From af6d8c1ebfc5472b815980d929947095725e3020 Mon Sep 17 00:00:00 2001 From: kimjihye Date: Fri, 20 Dec 2024 10:13:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20build-and-deploy=EA=B0=80=20=EB=B3=B4?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/itcast-build-and-deploy.yml | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/.github/workflows/itcast-build-and-deploy.yml b/.github/workflows/itcast-build-and-deploy.yml index aa5879c..916b642 100644 --- a/.github/workflows/itcast-build-and-deploy.yml +++ b/.github/workflows/itcast-build-and-deploy.yml @@ -8,8 +8,80 @@ on: jobs: deploy: + if: > + github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: - - name: Deploy - run: echo "Triggered" + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Set Yaml + uses: microsoft/variable-substitution@v1 + with: + files: ./src/main/resources/application-prod.yml + env: + spring.datasource.url: ${{secrets.KJH_MYSQL_URL}} + spring.datasource.username: ${{ secrets.KJH_DB_USERNAME }} + spring.datasource.password: ${{ secrets.KJH_DB_PASSWORD }} + spring.data.redis.host: ${{ secrets.KJH_REDIS_HOST }} + spring.data.redis.port: ${{ secrets.KJH_REDIS_PORT }} + + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + + - name: Set up Docker Compose + run: | + docker-compose up -d + docker-compose ps + + - name: Wait for services to be ready + run: | + until docker-compose exec -T mysql mysqladmin ping -h"127.0.0.1" --silent; do + echo "Waiting for MySQL to be ready" + sleep 5 + done + sleep 10 + + - name: Build with Gradle (prod profile) + run: ./gradlew clean build -Dspring.profiles.active=prod -Duser.language=ko -Duser.country=KR + + - name: Tear down Docker Compose + if: always() + run: docker-compose down + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + shell: bash + + - name: Make Zip file + run: zip -r $GITHUB_SHA.zip build/libs/*.jar appspec.yml scripts/deploy.sh + shell: bash + + - name: AWS credential setting + uses: aws-actions/configure-aws-credentials@v3 + with: + aws-region: ${{secrets.AWS_KJH_REGION}} + aws-access-key-id: ${{secrets.AWS_KJH_ACCESS_KEY}} + aws-secret-access-key: ${{secrets.AWS_KJH_SECRET_ACCESS_KEY}} + + - name: Upload to S3 + run: aws s3 cp ./$GITHUB_SHA.zip s3://${{ secrets.AWS_S3_BUCKET }}/$GITHUB_SHA.zip + - name: EC2 Deploy + run: aws deploy create-deployment + --application-name ${{secrets.AWS_KJH_CODE_DEPLOY_APPLICATION}} + --deployment-config-name CodeDeployDefault.AllAtOnce + --deployment-group-name ${{secrets.AWS_KJH_CODE_DEPLOY_GROUP}} + --s3-location bucket=${{secrets.AWS_KJH_S3_BUCKET}},key=$GITHUB_SHA.zip,bundleType=zip