[Fix] dev 초기 데이터 수정 #89
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy DEV & COMMON Infra, Service | |
| on: | |
| push: | |
| branches: [ develop ] | |
| paths: | |
| - 'src/**' | |
| - 'terraform/common/**' | |
| - 'terraform/dev/**' | |
| - '.github/workflows/deploy-dev.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| concurrency: | |
| group: terraform | |
| cancel-in-progress: false | |
| env: | |
| AWS_REGION: ap-northeast-2 | |
| jobs: | |
| terraform-apply-common: | |
| name: Terraform Apply COMMON | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: hashicorp/setup-terraform@v3 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Terraform Init (common) | |
| run: terraform init | |
| working-directory: ./terraform/common | |
| - name: Terraform Apply COMMON | |
| run: terraform apply -auto-approve | |
| working-directory: ./terraform/common | |
| terraform-apply-dev: | |
| name: Terraform Apply dev | |
| runs-on: ubuntu-latest | |
| needs: terraform-apply-common | |
| outputs: | |
| tf_outputs_json: ${{ steps.get-outputs.outputs.data }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_wrapper: false | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Terraform Init (dev) | |
| run: terraform init | |
| working-directory: ./terraform/dev | |
| - name: Terraform Apply dev | |
| run: terraform apply -auto-approve | |
| working-directory: ./terraform/dev | |
| - name: Get Terraform Outputs | |
| id: get-outputs | |
| run: | | |
| echo "data<<EOF" >> $GITHUB_OUTPUT | |
| terraform output -json >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| working-directory: ./terraform/dev | |
| deploy-service: | |
| name: Deploy to Amazon ECS | |
| runs-on: ubuntu-latest | |
| environment: develop | |
| needs: terraform-apply-dev | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Parse Terraform Outputs and Set Environment Variables | |
| run: | | |
| TF_OUTPUTS='${{ needs.terraform-apply-dev.outputs.tf_outputs_json }}' | |
| echo "ECR_REPOSITORY=$(echo "$TF_OUTPUTS" | jq -r '.ecr_repository_name.value')" >> $GITHUB_ENV | |
| echo "ECS_CLUSTER=$(echo "$TF_OUTPUTS" | jq -r '.ecs_cluster_name.value')" >> $GITHUB_ENV | |
| echo "ECS_SERVICE=$(echo "$TF_OUTPUTS" | jq -r '.ecs_api_service_name.value')" >> $GITHUB_ENV | |
| echo "CONTAINER_NAME=$(echo "$TF_OUTPUTS" | jq -r '.ecs_api_container_name.value')" >> $GITHUB_ENV | |
| echo "PRIVATE_IP=$(echo "$TF_OUTPUTS" | jq -r '.ec2_private_ip.value')" >> $GITHUB_ENV | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Update MYSQL_URL in Parameter Store | |
| run: | | |
| MYSQL_URL="jdbc:mysql://${PRIVATE_IP}:3306/eatda?useUnicode=true&characterEncoding=UTF-8" | |
| aws ssm put-parameter \ | |
| --name "/dev/MYSQL_URL" \ | |
| --type "SecureString" \ | |
| --value "$MYSQL_URL" \ | |
| --overwrite | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Install Semantic Release dependencies | |
| run: | | |
| npm install \ | |
| semantic-release \ | |
| @semantic-release/commit-analyzer \ | |
| @semantic-release/release-notes-generator \ | |
| @semantic-release/github \ | |
| conventional-changelog-conventionalcommits | |
| - name: Semantic Release | |
| id: get_version | |
| run: | | |
| OUTPUT=$(./node_modules/.bin/semantic-release --no-ci) | |
| echo "$OUTPUT" | |
| VERSION=$(echo "$OUTPUT" | grep -oP 'Published (?:pre)?release \K[0-9.a-z-]+') | |
| if [ -z "$VERSION" ]; then | |
| echo "릴리즈할 새로운 버전이 없습니다. 배포를 건너뜁니다." | |
| exit 0 | |
| fi | |
| echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: 21 | |
| java-package: jdk | |
| architecture: 'x64' | |
| cache: 'gradle' | |
| - name: Get TEST_JWT_SECRET_KEY from SSM | |
| id: get-test-secret | |
| run: | | |
| SECRET_VALUE=$(aws ssm get-parameter \ | |
| --name "/common/TEST_JWT_SECRET_KEY" \ | |
| --with-decryption \ | |
| --region "${{ env.AWS_REGION }}" \ | |
| --query "Parameter.Value" \ | |
| --output text) | |
| echo "TEST_JWT_SECRET_KEY=$SECRET_VALUE" >> $GITHUB_ENV | |
| - name: Build with Gradle | |
| run: | | |
| cd ${{ github.workspace }} | |
| chmod +x gradlew | |
| ./gradlew clean build -Dspring.profiles.active=dev | |
| env: | |
| TEST_JWT_SECRET_KEY: ${{ env.TEST_JWT_SECRET_KEY }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| with: | |
| mask-password: 'true' | |
| - name: Build, tag, and push image to Amazon ECR | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION | |
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV | |
| - name: Get latest ECS task definition | |
| id: get-latest-task-def | |
| run: | | |
| TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --region "${{ env.AWS_REGION }}" --query "services[0].taskDefinition" --output text) | |
| aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --region "${{ env.AWS_REGION }}" --query "taskDefinition" --output json > task-definition.json | |
| - name: Fill in the new image ID in the Amazon ECS task definition | |
| id: task-def | |
| uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
| with: | |
| task-definition: task-definition.json | |
| container-name: ${{ env.CONTAINER_NAME }} | |
| image: ${{ env.image }} | |
| - name: Deploy Amazon ECS task definition | |
| uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
| with: | |
| task-definition: ${{ steps.task-def.outputs.task-definition }} | |
| service: ${{ env.ECS_SERVICE }} | |
| cluster: ${{ env.ECS_CLUSTER }} | |
| wait-for-service-stability: true | |
| - name: Prepare Notification Info | |
| id: vars | |
| run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Discord Notify (Success) | |
| if: success() | |
| uses: tsickert/[email protected] | |
| with: | |
| webhook-url: ${{ secrets.DISCORD_WEBHOOK }} | |
| embed-title: "✅ 개발 서버 배포 성공!" | |
| embed-color: 65280 | |
| embed-description: | | |
| 새로운 버전이 성공적으로 배포되었습니다. | |
| **버전**: [v${{ env.SEMANTIC_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ env.SEMANTIC_VERSION }}) | |
| **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) | |
| **배포자**: ${{ github.actor }} | |
| embed-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| - name: Discord Notify (Failure) | |
| if: failure() | |
| uses: tsickert/[email protected] | |
| with: | |
| webhook-url: ${{ secrets.DISCORD_WEBHOOK }} | |
| embed-title: "❌ 개발 서버 배포 실패!" | |
| embed-color: 16711680 | |
| embed-description: | | |
| 배포 과정 중 오류가 발생했습니다. 아래 링크에서 로그를 확인하세요. | |
| **시도 버전**: ${{ env.SEMANTIC_VERSION }} | |
| **커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) | |
| **요청자**: ${{ github.actor }} | |
| embed-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |