setting: Nginx grafana upstream 추가 #98
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: CI/CD Workflow for Multi-Module Project | |
| on: | |
| push: | |
| branches: | |
| - test/data-stress | |
| jobs: | |
| ci: | |
| runs-on: ubuntu-latest | |
| env: | |
| AWS_REGION: "ap-northeast-2" | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v2 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v2 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Build and Test Each Module | |
| run: | | |
| ./gradlew :ttoklip-api:clean :ttoklip-api:build :ttoklip-api:test | |
| ./gradlew :ttoklip-batch:clean :ttoklip-batch:build :ttoklip-batch:test | |
| ./gradlew :ttoklip-notification:clean :ttoklip-notification:build :ttoklip-notification:test | |
| - name: Verify Build Artifacts | |
| run: | | |
| echo "Verifying build artifacts..." | |
| ls -la ttoklip-api/build/libs/ | |
| ls -la ttoklip-batch/build/libs/ | |
| ls -la ttoklip-notification/build/libs/ | |
| - name: Save Build Artifacts | |
| run: | | |
| mkdir -p deploy | |
| cp ttoklip-api/build/libs/ttoklip-api-SNAPSHOT.jar deploy/ | |
| cp ttoklip-batch/build/libs/ttoklip-batch-SNAPSHOT.jar deploy/ | |
| cp ttoklip-notification/build/libs/ttoklip-notification-SNAPSHOT.jar deploy/ | |
| cp ttoklip-api/Dockerfile-prod deploy/Dockerfile-api-prod | |
| cp ttoklip-batch/Dockerfile-prod deploy/Dockerfile-batch-prod | |
| cp ttoklip-notification/Dockerfile-prod deploy/Dockerfile-notification-prod | |
| cp -r nginx deploy/ | |
| cp docker-compose.prod.yml deploy/ | |
| zip -r deploy-package.zip deploy | |
| - name: Configure AWS Credentials | |
| run: | | |
| aws configure set aws_access_key_id ${{ secrets.SSM_PUBLIC }} | |
| aws configure set aws_secret_access_key ${{ secrets.SSM_PRIVATE }} | |
| aws configure set region $AWS_REGION | |
| - name: Upload to S3 | |
| run: | | |
| aws s3 cp deploy-package.zip s3://ttoklip-deploy/zips/deploy-package.zip --region ap-northeast-2 | |
| cd: | |
| needs: ci | |
| runs-on: ubuntu-latest | |
| env: | |
| AWS_REGION: "ap-northeast-2" | |
| steps: | |
| - name: Configure AWS Credentials | |
| run: | | |
| aws configure set aws_access_key_id ${{ secrets.SSM_PUBLIC }} | |
| aws configure set aws_secret_access_key ${{ secrets.SSM_PRIVATE }} | |
| aws configure set region $AWS_REGION | |
| - name: Upload Deploy Script to S3 | |
| run: | | |
| cat << 'EOF' > deploy_script.sh | |
| #!/bin/bash | |
| mkdir -p /home/ec2-user/ttoklip/application | |
| sudo chown -R ec2-user:ec2-user /home/ec2-user/ttoklip | |
| sudo chmod -R 755 /home/ec2-user/ttoklip | |
| if [ -d "/home/ec2-user/ttoklip/application/deploy" ]; then | |
| rm -rf /home/ec2-user/ttoklip/application/deploy | |
| fi | |
| aws s3 cp s3://ttoklip-deploy/zips/deploy-package.zip /home/ec2-user/ttoklip/application/deploy-package.zip --region ap-northeast-2 | |
| unzip -o /home/ec2-user/ttoklip/application/deploy-package.zip -d /home/ec2-user/ttoklip/application/ | |
| docker container prune -f | |
| docker image prune -a -f --filter "until=24h" | |
| docker volume prune -f | |
| docker system prune -a -f --volumes | |
| docker-compose -f /home/ec2-user/ttoklip/application/deploy/docker-compose.prod.yml --env-file /home/ec2-user/ttoklip/application/.env up -d --build | |
| EOF | |
| zip deploy_script.zip deploy_script.sh | |
| aws s3 cp deploy_script.zip s3://ttoklip-deploy/zips/deploy-script.zip --region ap-northeast-2 | |
| - name: Deploy to EC2 via SSM | |
| run: | | |
| aws ssm send-command \ | |
| --instance-ids "${{ secrets.EC2_INSTANCE_ID }}" \ | |
| --document-name "AWS-RunShellScript" \ | |
| --comment "Running deployment script" \ | |
| --parameters commands=$'\ | |
| aws s3 cp s3://ttoklip-deploy/zips/deploy-script.zip /home/ec2-user/ttoklip/application/ --region ap-northeast-2\n\ | |
| cd /home/ec2-user/ttoklip/application/\n\ | |
| unzip -o deploy-script.zip\n\ | |
| chmod +x deploy_script.sh\n\ | |
| ./deploy_script.sh' \ | |
| --output-s3-bucket-name "ttoklip-deploy" \ | |
| --output-s3-key-prefix "ssm-output" \ | |
| --region $AWS_REGION | |