Repository navigation
96 lines (78 loc) · 2.85 KB
/
Copy pathdeploy.yml
File metadata and controls
96 lines (78 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main, develop ]
env:
AWS_REGION: ap-northeast-2
jobs:
test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run tests
run: ./gradlew test
- name: Build JAR
run: ./gradlew bootJar -x test
deploy:
name: Deploy to EC2
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build JAR
run: ./gradlew bootJar -x test
- 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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Firebase 서비스 계정 파일 생성
run: echo '${{ secrets.FIREBASE_SERVICE_ACCOUNT_JSON }}' > firebase-service-account.json
- name: Build, tag, and push Docker image to ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "IMAGE_URI=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" > scripts/image.env
- name: Create deployment bundle
run: zip -r deploy.zip appspec.yml scripts/
- name: Upload bundle to S3
run: |
aws s3 cp deploy.zip s3://${{ secrets.S3_BUCKET }}/deploy-${{ github.sha }}.zip
- name: Deploy to AWS CodeDeploy
run: |
aws deploy create-deployment \
--application-name ${{ secrets.CODEDEPLOY_APP_NAME }} \
--deployment-group-name ${{ secrets.CODEDEPLOY_DEPLOYMENT_GROUP }} \
--s3-location bucket=${{ secrets.S3_BUCKET }},bundleType=zip,key=deploy-${{ github.sha }}.zip \
--file-exists-behavior OVERWRITE \
--region ${{ env.AWS_REGION }}