Skip to content

Commit 66f8dd7

Browse files
authored
Merge pull request #292 from depromeet/develop
refactor: layer-admin, layer-batch 코드 layer-api로 이관
2 parents 09af213 + fb5bc6f commit 66f8dd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+910
-368
lines changed

.github/workflows/aws-cicd-dev.yml

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- develop
7+
78
pull_request:
89
branches:
910
- develop
@@ -21,11 +22,16 @@ jobs:
2122
packages: write
2223
outputs:
2324
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
25+
2426
steps:
2527
- name: Setup Env
2628
id: set-env
2729
run: |
28-
echo "DEPLOY_TARGET=development" >> $GITHUB_OUTPUT
30+
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
31+
echo "DEPLOY_TARGET=production" >> $GITHUB_OUTPUT
32+
else
33+
echo "DEPLOY_TARGET=development" >> $GITHUB_OUTPUT
34+
fi
2935
3036
build:
3137
name: build
@@ -36,7 +42,7 @@ jobs:
3642
packages: write
3743

3844
env:
39-
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
45+
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }} # 이부분
4046
REGISTRY: "docker.io"
4147
NAMESPACE: "clean01"
4248
APPLICATION_SECRET_PROPERTIES: ${{ secrets.AWS_APPLICATION_SECRET_PROPERTIES }}
@@ -57,27 +63,14 @@ jobs:
5763

5864
- name: Create application-secret.properties
5965
run: |
60-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
61-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
62-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-admin/src/main/resources/application-secret.properties
66+
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
6367
6468
- name: Build layer-api module
6569
run: ./gradlew :layer-api:build
6670

6771
- name: Test layer-api module
6872
run: ./gradlew :layer-api:test
6973

70-
- name: Build layer-batch module
71-
run: ./gradlew :layer-batch:build
72-
73-
- name: Test layer-batch module
74-
run: ./gradlew :layer-batch:test
75-
76-
- name: Build layer-admin module
77-
run: ./gradlew :layer-admin:build
78-
79-
- name: Test layer-admin module
80-
run: ./gradlew :layer-admin:test
8174

8275
- name: Docker Hub Login
8376
uses: docker/login-action@v1
@@ -90,40 +83,20 @@ jobs:
9083
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
9184
with:
9285
images: |
93-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
94-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
95-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin
86+
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
9687
9788
- name: Push layer-api Docker Image
9889
uses: docker/build-push-action@v4
9990
with:
10091
context: ./layer-api
101-
file: ./layer-api/Dockerfile-dev # Dockerfile 이름 지정
92+
file: ./layer-api/Dockerfile # Dockerfile 이름 지정
10293
platforms: linux/amd64
10394
push: true
10495
tags: |
10596
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest
106-
107-
108-
- name: Push layer-batch Docker Image
109-
uses: docker/build-push-action@v4
110-
with:
111-
context: ./layer-batch
112-
file: ./layer-batch/Dockerfile-batch # Dockerfile 이름 지정
113-
platforms: linux/amd64
114-
push: true
115-
tags: |
116-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
117-
118-
- name: Push layer-admin Docker Image
119-
uses: docker/build-push-action@v4
120-
with:
121-
context: ./layer-admin
122-
file: ./layer-admin/Dockerfile-admin # Dockerfile 이름 지정
123-
platforms: linux/amd64
124-
push: true
125-
tags: |
126-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin:latest
97+
build-args: |
98+
SPRING_PROFILE=dev
99+
no-cache: true
127100

128101
deploy:
129102
name: Deploy
@@ -132,6 +105,7 @@ jobs:
132105
if: github.event_name != 'pull_request'
133106
env:
134107
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
108+
HOST_IP: ${{ needs.setup.outputs.host_ip }}
135109

136110
steps:
137111
- name: Checkout sources
@@ -140,8 +114,6 @@ jobs:
140114
- name: Create application-secret.properties file
141115
run: |
142116
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
143-
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
144-
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-admin/src/main/resources/application-secret.properties
145117
146118
- name: Archive Files
147119
run: |
@@ -171,6 +143,17 @@ jobs:
171143
sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
172144
173145
146+
- name: Set Permissions on Transferred Files
147+
uses: appleboy/ssh-action@master
148+
with:
149+
host: ${{ secrets.AWS_DEV_INSTANCE_HOST }}
150+
username: ubuntu
151+
key: ${{ secrets.AWS_INSTANCE_PEM }}
152+
port: 22
153+
script: |
154+
sudo chmod -R 755 /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
155+
sudo chown -R ubuntu:ubuntu /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
156+
174157
- name: Deploy with Docker Compose
175158
uses: appleboy/ssh-action@master
176159
with:
@@ -179,10 +162,8 @@ jobs:
179162
key: ${{ secrets.AWS_INSTANCE_PEM }}
180163
port: 22
181164
script: |
182-
sudo apt update
183-
sudo apt install docker-ce
184-
sudo apt install docker-compose
185165
sudo docker login --username ${{ secrets.DOCKER_EMAIL }} --password ${{ secrets.DOCKER_PASSWORD }}
186166
cd /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
187-
sudo docker-compose pull && sudo docker-compose up -d
167+
chmod 777 ./deploy.sh
168+
./deploy.sh
188169
sudo docker image prune -a -f

.github/workflows/aws-cicd-prod.yml

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
78
pull_request:
89
branches:
910
- main
@@ -21,6 +22,7 @@ jobs:
2122
packages: write
2223
outputs:
2324
deploy_target: ${{ steps.set-env.outputs.DEPLOY_TARGET }}
25+
2426
steps:
2527
- name: Setup Env
2628
id: set-env
@@ -36,7 +38,7 @@ jobs:
3638
packages: write
3739

3840
env:
39-
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
41+
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }} # 이부분
4042
REGISTRY: "docker.io"
4143
NAMESPACE: "clean01"
4244
APPLICATION_SECRET_PROPERTIES: ${{ secrets.AWS_APPLICATION_SECRET_PROPERTIES }}
@@ -57,28 +59,14 @@ jobs:
5759

5860
- name: Create application-secret.properties
5961
run: |
60-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
61-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-batch/src/main/resources/application-secret.properties
62-
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-admin/src/main/resources/application-secret.properties
62+
echo "${APPLICATION_SECRET_PROPERTIES}" > ./layer-api/src/main/resources/application-secret.properties
6363
6464
- name: Build layer-api module
6565
run: ./gradlew :layer-api:build
6666

6767
- name: Test layer-api module
6868
run: ./gradlew :layer-api:test
6969

70-
- name: Build layer-batch module
71-
run: ./gradlew :layer-batch:build
72-
73-
- name: Test layer-batch module
74-
run: ./gradlew :layer-batch:test
75-
76-
- name: Build layer-admin module
77-
run: ./gradlew :layer-admin:build
78-
79-
- name: Test layer-admin module
80-
run: ./gradlew :layer-admin:test
81-
8270
- name: Docker Hub Login
8371
uses: docker/login-action@v1
8472
with:
@@ -90,49 +78,29 @@ jobs:
9078
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
9179
with:
9280
images: |
93-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
94-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch
95-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin
81+
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api
9682
9783
- name: Push layer-api Docker Image
9884
uses: docker/build-push-action@v4
9985
with:
10086
context: ./layer-api
101-
file: ./layer-api/Dockerfile-prod # Dockerfile 이름 지정
87+
file: ./layer-api/Dockerfile # Dockerfile 이름 지정
10288
platforms: linux/amd64
10389
push: true
10490
tags: |
10591
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-api:latest
92+
build-args: |
93+
SPRING_PROFILE=prod
10694
no-cache: true
10795

108-
- name: Push layer-batch Docker Image
109-
uses: docker/build-push-action@v4
110-
with:
111-
context: ./layer-batch
112-
file: ./layer-batch/Dockerfile-batch # Dockerfile 이름 지정
113-
platforms: linux/amd64
114-
push: true
115-
tags: |
116-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-batch:latest
117-
no-cache: true
118-
119-
- name: Push layer-admin Docker Image
120-
uses: docker/build-push-action@v4
121-
with:
122-
context: ./layer-admin
123-
file: ./layer-admin/Dockerfile-admin # Dockerfile 이름 지정
124-
platforms: linux/amd64
125-
push: true
126-
tags: |
127-
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}_layer-admin:latest
128-
12996
deploy:
13097
name: Deploy
13198
needs: [ build, setup ]
13299
runs-on: ubuntu-latest
133100
if: github.event_name != 'pull_request'
134101
env:
135102
DEPLOY_TARGET: ${{ needs.setup.outputs.deploy_target }}
103+
HOST_IP: ${{ needs.setup.outputs.host_ip }}
136104

137105
steps:
138106
- name: Checkout sources
@@ -141,8 +109,6 @@ jobs:
141109
- name: Create application-secret.properties file
142110
run: |
143111
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-api/infra/${{ env.DEPLOY_TARGET }}/application-secret.properties
144-
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-batch/src/main/resources/application-secret.properties
145-
echo "${{ secrets.APPLICATION_SECRET_PROPERTIES }}" > ./layer-admin/src/main/resources/application-secret.properties
146112
147113
- name: Archive Files
148114
run: |
@@ -151,7 +117,7 @@ jobs:
151117
- name: Send Docker Compose
152118
uses: appleboy/scp-action@master
153119
with:
154-
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }}
120+
host: ${{ secrets.AWS_PROD_INSTANCE_HOST }} # aws-cicd-dev.yml과 분리한 이유
155121
username: ubuntu
156122
key: ${{ secrets.AWS_INSTANCE_PEM }}
157123
port: 22
@@ -191,9 +157,6 @@ jobs:
191157
key: ${{ secrets.AWS_INSTANCE_PEM }}
192158
port: 22
193159
script: |
194-
sudo apt update
195-
sudo apt install docker-ce
196-
sudo apt install docker-compose
197160
sudo docker login --username ${{ secrets.DOCKER_EMAIL }} --password ${{ secrets.DOCKER_PASSWORD }}
198161
cd /home/ubuntu/layer-api/infra/${{ env.DEPLOY_TARGET }}
199162
chmod 777 ./deploy.sh

layer-admin/Dockerfile-admin renamed to layer-admin/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ COPY ${JAR_FILE} layer-admin.jar
77

88
ENV SPRING_PROFILE=${SPRING_PROFILE}
99

10-
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul" ,"-jar" ,"layer-admin.jar"]
10+
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-Dspring.profiles.active=${SPRING_PROFILE}","-jar" ,"layer-admin.jar"]
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
FROM openjdk:17
2+
23
ARG JAR_FILE=./build/libs/*.jar
4+
ARG SPRING_PROFILE
5+
36
COPY ${JAR_FILE} layer-server.jar
4-
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=dev" ,"-jar" ,"layer-server.jar"]
7+
8+
ENV SPRING_PROFILE=${SPRING_PROFILE}
9+
10+
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul","-Dspring.profiles.active=${SPRING_PROFILE}" ,"-jar" ,"layer-server.jar"]

layer-api/Dockerfile-prod

Lines changed: 0 additions & 4 deletions
This file was deleted.

layer-api/infra/development/deploy.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
IS_GREEN=$(sudo docker ps | grep layer-api-green) # 현재 실행중인 App이 blue인지 확인합니다.
4+
DEFAULT_CONF="/etc/nginx/nginx.conf"
5+
6+
7+
if [ -z $IS_GREEN ];then # blue라면
8+
9+
echo "### BLUE => GREEN ###"
10+
11+
echo "1. get green image"
12+
cd ./layer-api/infra/production
13+
14+
echo "1.1. pull latest green image"
15+
sudo docker-compose -f docker-compose-green.yaml pull
16+
17+
echo "2. green container up"
18+
sudo docker-compose -f docker-compose-green.yaml up -d
19+
20+
while [ 1 = 1 ]; do
21+
echo "3. green health check..."
22+
sudo sleep 3
23+
24+
REQUEST=$(sudo curl http://127.0.0.1:8080/actuator/health) # green으로 request
25+
if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
26+
echo "health check success"
27+
break ;
28+
fi
29+
done;
30+
31+
echo "4. reload nginx"
32+
sudo cp ./nginx.green.conf /etc/nginx/nginx.conf
33+
sudo nginx -s reload
34+
35+
echo "5. blue container down"
36+
sudo docker-compose -f docker-compose-blue.yaml rm -s -f layer-api-blue
37+
else
38+
echo "### GREEN => BLUE ###"
39+
echo "1. get blue image"
40+
cd ./layer-api/infra/production
41+
42+
echo "1.1. pull latest blue image"
43+
sudo docker-compose -f docker-compose-blue.yaml pull
44+
45+
echo "2. blue container up"
46+
sudo docker-compose -f docker-compose-blue.yaml up -d
47+
48+
49+
while [ 1 = 1 ]; do
50+
echo "3. blue health check..."
51+
sleep 3
52+
REQUEST=$(curl http://127.0.0.1:8081/actuator/health) # blue로 request
53+
54+
if [ -n "$REQUEST" ]; then # 서비스 가능하면 health check 중지
55+
echo "health check success"
56+
break ;
57+
fi
58+
done;
59+
60+
echo "4. reload nginx"
61+
sudo cp ./nginx.blue.conf /etc/nginx/nginx.conf
62+
sudo nginx -s reload
63+
64+
echo "5. green container down"
65+
sudo docker-compose -f docker-compose-green.yaml rm -s -f layer-api-green
66+
fi

0 commit comments

Comments
 (0)