diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 50ed398..a0358f8 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,4 +1,4 @@ -name: Build with Gradle +name: Java CI with Gradle run-name: New Push @@ -6,15 +6,11 @@ on: push: branches: [ "main" ] -env: - AWS_REGION: ap-northeast-2 - AWS_S3_BUCKET: yw-cicd-bucket - AWS_CODE_DEPLOY_APPLICATION: yw-cicd - AWS_CODE_DEPLOY_GROUP: yw-cicd-group +permissions: + contents: read jobs: build-with-gradle: - runs-on: ubuntu-20.04 steps: @@ -26,21 +22,48 @@ jobs: java-version: '17' distribution: 'temurin' + - name: Make application-prod.yml + run: | + cd ./src/main/resources + touch ./application-prod.yml + echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml + - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew clean build --exclude-task test + run: ./gradlew build -x test - - name: AWS credential 설정 - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-region: ${{ env.AWS_REGION }} - aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.CICD_SECRET_ACCESS_KEY }} + - name: Docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t app . + docker tag app ${{ secrets.DOCKER_USERNAME }}/yourwriting:latest + docker push ${{ secrets.DOCKER_USERNAME }}/youwriting:latest - - name: S3로 upload - run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://$AWS_S3_BUCKET/yw-cicd/$GITHUB_SHA.zip --source . + - name: Deploy + uses: g16rim/ssh-action@master + with: + host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS + username: ubuntu + key: ${{ secrets.PRIVATE_KEY }} # pem 키 + # 도커 작업 + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/yourwriting:latest + docker stop $(docker ps -a -q) + docker run -d --log-driver=syslog -p 8080:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.DOCKER_USERNAME }}/gomaoom:latest + docker rm $(docker ps --filter 'status=exited' -a -q) + docker image prune -a -f - - name: EC2에 배포 - run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=yw-cicd/$GITHUB_SHA.zip,bundleType=zip \ No newline at end of file +# - name: AWS credential 설정 +# uses: aws-actions/configure-aws-credentials@v1 +# with: +# aws-region: ${{ env.AWS_REGION }} +# aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY_ID }} +# aws-secret-access-key: ${{ secrets.CICD_SECRET_ACCESS_KEY }} +# +# - name: S3로 upload +# run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://$AWS_S3_BUCKET/yw-cicd/$GITHUB_SHA.zip --source . +# +# - name: EC2에 배포 +# run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=yw-cicd/$GITHUB_SHA.zip,bundleType=zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3b30c9f..b2ea5ed 100644 --- a/.gitignore +++ b/.gitignore @@ -36,5 +36,4 @@ out/ ### VS Code ### .vscode/ -/src/main/resources/application.yml -/src/main/resources/application-auth.yml \ No newline at end of file +/src/main/resources/application.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..462209d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:17-jdk +ARG JAR_FILE=build/libs/realWriting-0.0.1-SNAPSHOT.jar +COPY ${JAR_FILE} /yourwriting.jar + +ENTRYPOINT ["java", "-jar", "/yourwriting.jar"] \ No newline at end of file diff --git a/appspec.yml b/appspec.yml deleted file mode 100644 index 4ffd8d2..0000000 --- a/appspec.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: 0.0 -os: linux - -files: - - source: / - destination: /home/ubuntu/spring-github-action - overwrite: yes - -permissions: - - object: / - owner: ubuntu - group: ubuntu - -hooks: - AfterInstall: - - location: scripts/stop.sh - timeout: 60 - ApplicationStart: - - location: scripts/start.sh - timeout: 60 \ No newline at end of file