-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (93 loc) · 4.01 KB
/
cd-prod.yml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Continuous Deployment for SOPT makers Authentication Production Server
on:
workflow_dispatch:
push:
branches: [ main ]
jobs:
build-and-push-image:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: ✅ Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'corretto'
cache: gradle
- name: 🤝 Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: 🔒 Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: ⚙️ Create Property File
run: |
touch ./gradle.properties
touch ./src/main/resources/application.properties
echo "${{ secrets.PROPERTY_GRADLE }}" >> ./gradle.properties
echo "${{ secrets.PROPERTY_APPLICATION }}" >> ./src/main/resources/application.properties
- name: 🔑 Copy Key File
env:
REGION: ${{ secrets.AWS_REGION }}
APPLE_KEY: ${{ secrets.APPLE_KEY }}
JWT_PUBLIC_KEY: ${{ secrets.JWT_PUBLIC_KEY }}
JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
PROPERTY_PATH: src/main/resources
run: |
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/static/$JWT_PUBLIC_KEY $PROPERTY_PATH/$JWT_PUBLIC_KEY
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/static/$JWT_PRIVATE_KEY $PROPERTY_PATH/$JWT_PRIVATE_KEY
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/static/$APPLE_KEY $PROPERTY_PATH/$APPLE_KEY
- name: 🧱 Build Image and Push to ECR
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_ECR_REPO: ${{ secrets.AWS_ECR_REPO_PROD }}
run: |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
docker build -t $AWS_ECR_REPO .
docker tag $AWS_ECR_REPO:latest public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest
docker push public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest
create-deploy:
needs: build-and-push-image
runs-on: ubuntu-22.04
steps:
- name: 🔒 Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: 📝 Copy Script File
env:
REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
run: |
mkdir script
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/script/deploy.sh script/deploy.sh
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/script/switch.sh script/switch.sh
aws s3 cp --region $REGION \
s3://$S3_BUCKET/prod/script/valid.sh script/valid.sh
- name: 📁 Make files to zip
run: zip -r ./$GITHUB_SHA.zip ./script
shell: bash
- name: 🚀 Upload Property Zip to S3 and Create Code Deploy
env:
REGION: ${{ secrets.AWS_REGION }}
DEPLOY_APPLICATION: ${{ secrets.AWS_DEPLOY_APPLICATION }}
DEPLOY_GROUP: ${{ secrets.AWS_DEPLOY_GROUP_PROD }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
run: |
aws s3 cp --region $REGION ./$GITHUB_SHA.zip s3://$S3_PATH/prod/deploy/$GITHUB_SHA.zip
aws deploy create-deployment --application-name $AWS_DEPLOY_APPLICATION_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $DEPLOY_GROUP
--s3-location bucket=$AWS_BUCKET_NAME,bundleType=zip,key=prod/deploy/$GITHUB_SHA.zip