Skip to content

Commit 8785471

Browse files
authored
Release 0.0.4 (#135)
* 프로덕션 CI / CD 파이프라인을 분리한다. (#132) chore: separate production workflow from development workflow * CI / CD 파이프라인 환경 변수를 수정한다. (#134) fix: modify job environment * 존재하지 않는 환경 변수를 삭제한다. (#137) fix: modify environment variables
1 parent 55edcd2 commit 8785471

File tree

3 files changed

+134
-18
lines changed

3 files changed

+134
-18
lines changed
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
name: Deploy to AWS EC2
1+
name: Deploy to develop environment
22
on:
33
push:
44
branches:
5-
- prod
65
- dev
76
env:
87
AWS_REGION: ap-northeast-2
98
CONTAINER_NAME: gotchai-server
109
API_SPECIFICATION_PATH: ./api/src/main/resources/static/docs
1110
jobs:
12-
build:
11+
deploy-api-spec:
1312
name: Deploy API specification
1413
runs-on: ubuntu-latest
15-
if: github.ref_name == 'dev'
16-
environment: ${{ github.ref_name }}
14+
environment: dev
1715
steps:
1816
- name: Checkout repository
1917
uses: actions/checkout@v4
@@ -46,8 +44,8 @@ jobs:
4644
deploy-image:
4745
name: Deploy image
4846
runs-on: ubuntu-latest
49-
environment: ${{ github.ref_name }}
50-
needs: build
47+
environment: dev
48+
needs: deploy-api-spec
5149
outputs:
5250
image: ${{ steps.set-image.outputs.image }}
5351
steps:
@@ -86,7 +84,7 @@ jobs:
8684
name: Deploy container
8785
runs-on: ubuntu-latest
8886
needs: deploy-image
89-
environment: ${{ github.ref_name }}
87+
environment: dev
9088
steps:
9189
- name: Checkout
9290
uses: actions/checkout@v4
@@ -96,7 +94,7 @@ jobs:
9694
host: ${{ secrets.EC2_HOST }}
9795
username: ${{ secrets.EC2_USER }}
9896
key: ${{ secrets.EC2_PRIVATE_KEY }}
99-
source: docker/docker-compose-${{ github.ref_name }}.yml
97+
source: docker/docker-compose-dev.yml
10098
target: "~"
10199
strip_components: 1
102100
- name: Build and deploy container to AWS EC2
@@ -106,13 +104,12 @@ jobs:
106104
username: ${{ secrets.EC2_USER }}
107105
key: ${{ secrets.EC2_PRIVATE_KEY }}
108106
script: |
109-
aws secretsmanager get-secret-value --secret-id ${{ github.ref_name }}-env --region ap-northeast-2 --query SecretString --output text | jq -r '. | to_entries | map("\(.key)=\(.value)") | .[]' > .env
107+
aws secretsmanager get-secret-value --secret-id dev-env --region ap-northeast-2 --query SecretString --output text | jq -r '. | to_entries | map("\(.key)=\(.value)") | .[]' > .env
108+
aws s3 cp s3://${{ secrets.API_SPECIFICATION_BUCKET }}/api.yml .
109+
110110
export IMAGE_URI=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }}
111-
docker-compose -f docker-compose-${{ github.ref_name }}.yml --env-file .env up -d --build
112-
if [ "${{ github.ref_name }}" = "dev" ]; then
113-
aws s3 cp s3://${{ secrets.API_SPECIFICATION_BUCKET }}/api.yml .
114-
docker restart swagger
115-
fi
111+
docker-compose -f docker-compose-dev.yml --env-file .env up -d --build
112+
docker restart swagger
116113
notify-discord:
117114
name: Notify Discord
118115
runs-on: ubuntu-latest
@@ -130,8 +127,8 @@ jobs:
130127
"avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
131128
"embeds": [
132129
{
133-
"title": "**${{ github.ref_name == 'prod' && '프로덕션' || '개발' }} 환경 배포 성공**",
134-
"description": "서버가 성공적으로 배포되었습니다.",
130+
"title": "**개발 환경 배포 성공**",
131+
"description": "개발 서버가 성공적으로 배포되었습니다.",
135132
"color": 3066993,
136133
"fields": [
137134
{

.github/workflows/deploy-prod.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Deploy to production environment
2+
on:
3+
push:
4+
branches:
5+
- prod
6+
env:
7+
AWS_REGION: ap-northeast-2
8+
CONTAINER_NAME: gotchai-server
9+
jobs:
10+
deploy-image:
11+
name: Deploy image
12+
runs-on: ubuntu-latest
13+
environment: prod
14+
outputs:
15+
image: ${{ steps.set-image.outputs.image }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: corretto
23+
java-version: 21
24+
- name: Cache Gradle packages
25+
uses: actions/cache@v3
26+
with:
27+
path: |
28+
~/.gradle/caches
29+
~/.gradle/wrapper
30+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
31+
restore-keys: |
32+
${{ runner.os }}-gradle-
33+
- name: Configure AWS credentials
34+
uses: aws-actions/configure-aws-credentials@v1
35+
with:
36+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
37+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38+
aws-region: ${{ env.AWS_REGION }}
39+
- name: Set image
40+
id: set-image
41+
run: echo "image=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }}" >> $GITHUB_OUTPUT
42+
- name: Build and deploy image to AWS ECR
43+
run: |
44+
./gradlew :api:jib \
45+
-Djib.to.image=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }} \
46+
-Djib.to.auth.username=AWS \
47+
-Djib.to.auth.password=$(aws ecr get-login-password)
48+
deploy-container:
49+
name: Deploy container
50+
runs-on: ubuntu-latest
51+
needs: deploy-image
52+
environment: prod
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v4
56+
- name: Send necessary files to EC2
57+
uses: appleboy/[email protected]
58+
with:
59+
host: ${{ secrets.EC2_HOST }}
60+
username: ${{ secrets.EC2_USER }}
61+
key: ${{ secrets.EC2_PRIVATE_KEY }}
62+
source: docker/docker-compose-prod.yml
63+
target: "~"
64+
strip_components: 1
65+
- name: Build and deploy container to AWS EC2
66+
uses: appleboy/[email protected]
67+
with:
68+
host: ${{ secrets.EC2_HOST }}
69+
username: ${{ secrets.EC2_USER }}
70+
key: ${{ secrets.EC2_PRIVATE_KEY }}
71+
script: |
72+
aws secretsmanager get-secret-value --secret-id prod-env --region ap-northeast-2 --query SecretString --output text | jq -r '. | to_entries | map("\(.key)=\(.value)") | .[]' > .env
73+
74+
export IMAGE_URI=${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY }}:${{ github.sha }}
75+
docker-compose -f docker-compose-prod.yml --env-file .env up -d --build
76+
notify-discord:
77+
name: Notify Discord
78+
runs-on: ubuntu-latest
79+
needs: deploy-container
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@v4
83+
- name: Get commit
84+
id: get_commit
85+
run: echo "commit_message=$(git log -1 --pretty=%s)" >> "$GITHUB_OUTPUT"
86+
- name: Send Discord notification
87+
run: |
88+
curl -X POST -H "Content-Type: application/json" -d '{
89+
"username": "GitHub Actions",
90+
"avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
91+
"embeds": [
92+
{
93+
"title": "**프로덕션 환경 배포 성공**",
94+
"description": "프로덕션 서버가 성공적으로 배포되었습니다.",
95+
"color": 3066993,
96+
"fields": [
97+
{
98+
"name": "Repository",
99+
"value": "[${{ github.repository }}](https://github.com/${{ github.repository }})",
100+
"inline": true
101+
},
102+
{
103+
"name": "Branch",
104+
"value": "${{ github.ref_name }}",
105+
"inline": true
106+
},
107+
{
108+
"name": "Commit",
109+
"value": "[${{ steps.get_commit.outputs.commit_message }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})",
110+
"inline": true
111+
},
112+
{
113+
"name": "Author",
114+
"value": "[${{ github.actor }}](${{ github.event.sender.html_url }})",
115+
"inline": true
116+
}
117+
]
118+
}
119+
]
120+
}' ${{ secrets.DISCORD_WEBHOOK_URL }}

api/src/test/resources/tags.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)