-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (134 loc) · 4.85 KB
/
cd-dev.yml
File metadata and controls
159 lines (134 loc) · 4.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: CD - Development
on:
push:
branches: [ "develop" ]
paths-ignore:
- '**.md'
- 'docs/**'
- '.gitignore'
- 'LICENSE'
- '.env.example'
concurrency:
group: deploy-dev
cancel-in-progress: false
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
- name: Run tests
run: ./gradlew test
- name: Upload test reports on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
build/reports/tests/
build/test-results/
retention-days: 7
deploy:
needs: test
runs-on: ubuntu-latest
timeout-minutes: 30
environment: development
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
mask-aws-account-id: true
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Create credentials
run: |
mkdir -p secrets
echo "${{ secrets.FIREBASE_JSON }}" | base64 -d > secrets/deepple-firebase.json
echo "${{ secrets.GOOGLE_PLAY_JSON }}" | base64 -d > secrets/deepple-google-play.json
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:dev-${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ vars.ECR_REPOSITORY }}:dev-latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy to EC2 via SSM
run: |
# 배포 스크립트 base64 인코딩
DEPLOY_SCRIPT_B64=$(base64 -w 0 .github/scripts/deploy-dev.sh)
# 환경변수 파일 base64 인코딩
ENV_CONTENT_B64=$(echo -n '${{ secrets.ENV }}' | base64 -w 0)
# SSM 명령 실행
COMMAND_ID=$(aws ssm send-command \
--instance-ids "${{ secrets.EC2_INSTANCE_ID }}" \
--document-name "AWS-RunShellScript" \
--timeout-seconds 600 \
--parameters commands="[
\"echo ${DEPLOY_SCRIPT_B64} | base64 -d > /tmp/deploy.sh\",
\"chmod +x /tmp/deploy.sh\",
\"/tmp/deploy.sh '${ENV_CONTENT_B64}' '${{ vars.AWS_REGION }}' '${{ steps.login-ecr.outputs.registry }}' '${{ vars.ECR_REPOSITORY }}' 'dev-${{ github.sha }}' '${{ vars.CONTAINER_NAME }}' '${{ vars.BLUE_PORT }}' '${{ vars.GREEN_PORT }}' '${{ vars.HEALTH_CHECK_MAX_RETRIES }}' '${{ vars.HEALTH_CHECK_INTERVAL }}'\"
]" \
--query "Command.CommandId" \
--output text)
echo "Command ID: $COMMAND_ID"
echo "Waiting for deployment..."
# 결과 폴링
for i in {1..120}; do
sleep 5
RESULT=$(aws ssm get-command-invocation \
--command-id "$COMMAND_ID" \
--instance-id "${{ secrets.EC2_INSTANCE_ID }}" 2>/dev/null) || continue
STATUS=$(echo "$RESULT" | jq -r '.Status')
case "$STATUS" in
Success)
echo ""
echo "===== Deployment Output ====="
echo "$RESULT" | jq -r '.StandardOutputContent // empty'
echo ""
echo "Deployment completed successfully!"
exit 0
;;
Failed|TimedOut|Cancelled)
echo ""
echo "===== Deployment Output ====="
echo "$RESULT" | jq -r '.StandardOutputContent // empty'
echo ""
echo "===== Error Output ====="
echo "$RESULT" | jq -r '.StandardErrorContent // empty'
echo ""
echo "Deployment failed with status: $STATUS"
exit 1
;;
*)
if [ $((i % 6)) -eq 0 ]; then
echo "Status: $STATUS... ($((i * 5))s elapsed)"
fi
;;
esac
done
echo "Timeout waiting for deployment result"
exit 1