Skip to content

Commit 3030bf8

Browse files
authored
[FEAT] #70: dev, prod 환경 분리
[FEAT] #70: dev, prod 환경 분리
2 parents 6c4b6fd + eb7e676 commit 3030bf8

File tree

10 files changed

+253
-11
lines changed

10 files changed

+253
-11
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CD - DEV
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v4
15+
16+
- name: Log in to Docker Hub
17+
uses: docker/login-action@v3
18+
with:
19+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
20+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
21+
22+
- name: Build and Push Docker Image
23+
run: |
24+
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/gdgoc-be-app-dev:latest .
25+
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/gdgoc-be-app-dev:latest
26+
27+
- name: move files to Root
28+
run: |
29+
cp gdgoc/docker-compose-dev.yml ./docker-compose-dev.yml
30+
cp gdgoc/deploy.dev.sh ./deploy.dev.sh
31+
cp gdgoc/appspec.dev.yml ./appspec.yml
32+
33+
- name: Create Deployment Package
34+
run: |
35+
echo "DOCKER_HUB_USERNAME=${{ secrets.DOCKER_HUB_USERNAME }}" > .env
36+
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
37+
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
38+
echo "DB_NAME_DEV=${{ secrets.DB_NAME_DEV }}" >> .env
39+
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> .env
40+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
41+
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> .env
42+
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> .env
43+
echo "GOOGLE_REDIRECT_URI=${{ secrets.GOOGLE_REDIRECT_URI }}" >> .env
44+
echo "GOOGLE_ISSUER=${{secrets.GOOGLE_ISSUER}}" >> .env
45+
echo "SELF_ISSUER=${{secrets.SELF_ISSUER}}" >> .env
46+
echo "SECRET_KEY=${{secrets.SECRET_KEY}}" >> .env
47+
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env
48+
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env
49+
echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> .env
50+
echo "AWS_RESOURCE_BUCKET=${{secrets.AWS_RESOURCE_BUCKET}}" >> .env
51+
echo "AWS_TEST_RESOURCE_BUCKET=${{secrets.AWS_TEST_RESOURCE_BUCKET}}" >> .env
52+
echo "GMAIL=${{secrets.GMAIL}}" >> .env
53+
echo "GMAIL_PASSWORD=${{secrets.GMAIL_PASSWORD}}" >> .env
54+
echo "DOZZLE_USERNAME=${{ secrets.DOZZLE_USERNAME }}" >> .env
55+
echo "DOZZLE_PASSWORD=${{ secrets.DOZZLE_PASSWORD }}" >> .env
56+
57+
zip -r deploy.zip .env docker-compose-dev.yml deploy.dev.sh appspec.yml
58+
59+
- name: Configure AWS credentials
60+
run: |
61+
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
62+
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
63+
aws configure set region ${{ secrets.AWS_REGION }}
64+
65+
- name: Upload Deployment Package to S3
66+
run: |
67+
aws s3 cp deploy.zip s3://${{ secrets.AWS_S3_BUCKET }}/deploy-dev.zip
68+
69+
- name: Deploy to AWS CodeDeploy
70+
run: |
71+
aws deploy create-deployment \
72+
--application-name ${{ secrets.AWS_CODEDEPLOY_APP }} \
73+
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_GROUP_DEV }} \
74+
--s3-location bucket=${{ secrets.AWS_S3_BUCKET }},bundleType=zip,key=deploy-dev.zip
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to EC2 via Docker Hub and CodeDeploy
1+
name: CD - PROD
22

33
on:
44
push:
@@ -11,10 +11,10 @@ jobs:
1111

1212
steps:
1313
- name: Checkout Repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Log in to Docker Hub
17-
uses: docker/login-action@v2
17+
uses: docker/login-action@v3
1818
with:
1919
username: ${{ secrets.DOCKER_HUB_USERNAME }}
2020
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
@@ -26,9 +26,9 @@ jobs:
2626
2727
- name: move files to Root
2828
run: |
29-
cp gdgoc/docker-compose.yml ./docker-compose.yml
30-
cp gdgoc/deploy.sh ./deploy.sh
31-
cp gdgoc/appspec.yml ./appspec.yml
29+
cp gdgoc/docker-compose-prod.yml ./docker-compose-prod.yml
30+
cp gdgoc/deploy.prod.sh ./deploy.prod.sh
31+
cp gdgoc/appspec.prod.yml ./appspec.yml
3232
3333
- name: Create Deployment Package
3434
run: |
@@ -51,8 +51,10 @@ jobs:
5151
echo "AWS_TEST_RESOURCE_BUCKET=${{secrets.AWS_TEST_RESOURCE_BUCKET}}" >> .env
5252
echo "GMAIL=${{secrets.GMAIL}}" >> .env
5353
echo "GMAIL_PASSWORD=${{secrets.GMAIL_PASSWORD}}" >> .env
54+
echo "DOZZLE_USERNAME=${{ secrets.DOZZLE_USERNAME }}" >> .env
55+
echo "DOZZLE_PASSWORD=${{ secrets.DOZZLE_PASSWORD }}" >> .env
5456
55-
zip -r deploy.zip .env docker-compose.yml deploy.sh appspec.yml
57+
zip -r deploy.zip .env docker-compose-prod.yml deploy.prod.sh appspec.yml
5658
5759
- name: Configure AWS credentials
5860
run: |

gdgoc/appspec.dev.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /home/ubuntu/gdgoc-be-app-dev
6+
7+
hooks:
8+
AfterInstall:
9+
- location: deploy.dev.sh
10+
timeout: 300
11+
runas: root
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ files:
66

77
hooks:
88
AfterInstall:
9-
- location: deploy.sh
9+
- location: deploy.prod.sh
1010
timeout: 300
1111
runas: root

gdgoc/deploy.dev.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC2164
3+
cd /home/ubuntu/gdgoc-be-app-dev
4+
5+
# Docker & Docker Compose가 설치되어 있는지 확인
6+
if ! [ -x "$(command -v docker)" ]; then
7+
echo "Docker가 설치되어 있지 않습니다. 설치 중..."
8+
sudo apt update
9+
sudo apt install -y docker.io
10+
sudo systemctl start docker
11+
sudo systemctl enable docker
12+
echo "Docker 설치 완료"
13+
fi
14+
15+
if ! [ -x "$(command -v docker-compose)" ]; then
16+
echo "Docker Compose가 설치되어 있지 않습니다. 설치 중..."
17+
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
18+
sudo chmod +x /usr/local/bin/docker-compose
19+
echo "Docker Compose 설치 완료"
20+
fi
21+
22+
# 기존 컨테이너 중지 및 삭제
23+
docker-compose -f docker-compose-dev.yml down
24+
25+
# 사용되지 않는 컨테이너, 이미지, 네트워크, 볼륨 정리
26+
docker system prune -af
27+
28+
# 불필요한 Docker 볼륨도 정리 (옵션)
29+
docker volume prune -f
30+
31+
# 최신 이미지 가져오기
32+
# shellcheck disable=SC2046
33+
export $(grep -v '^#' .env | xargs)
34+
# shellcheck disable=SC2086
35+
docker pull ${DOCKER_HUB_USERNAME}/gdgoc-be-app-dev:latest
36+
37+
# 컨테이너 실행
38+
docker-compose -f docker-compose-dev.yml --env-file .env up -d

gdgoc/deploy.sh renamed to gdgoc/deploy.prod.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2164
23
cd /home/ubuntu/gdgoc-be-app
34

45
# Docker & Docker Compose가 설치되어 있는지 확인
@@ -19,7 +20,7 @@ if ! [ -x "$(command -v docker-compose)" ]; then
1920
fi
2021

2122
# 기존 컨테이너 중지 및 삭제
22-
docker-compose down
23+
docker-compose -f docker-compose-prod.yml down
2324

2425
# 사용되지 않는 컨테이너, 이미지, 네트워크, 볼륨 정리
2526
docker system prune -af
@@ -28,8 +29,10 @@ docker system prune -af
2829
docker volume prune -f
2930

3031
# 최신 이미지 가져오기
32+
# shellcheck disable=SC2046
3133
export $(grep -v '^#' .env | xargs)
34+
# shellcheck disable=SC2086
3235
docker pull ${DOCKER_HUB_USERNAME}/gdgoc-be-app:latest
3336

3437
# 컨테이너 실행
35-
docker-compose --env-file .env up -d
38+
docker-compose -f docker-compose-prod.yml --env-file .env up -d

gdgoc/docker-compose-dev.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "3.8"
2+
3+
services:
4+
app:
5+
image: "${DOCKER_HUB_USERNAME}/gdgoc-be-app-dev:latest"
6+
container_name: gdgoc-be-app-dev
7+
restart: always
8+
ports:
9+
- "8080:8080"
10+
environment:
11+
SPRING_PROFILES_ACTIVE: dev
12+
SPRING_DATASOURCE_URL: "jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME_DEV}"
13+
SPRING_DATASOURCE_USERNAME: "${DB_USERNAME}"
14+
SPRING_DATASOURCE_PASSWORD: "${DB_PASSWORD}"
15+
volumes:
16+
- /home/ubuntu/gdgoc-be-app-dev/.env:/app/.env
17+
env_file:
18+
- .env
19+
20+
dozzle:
21+
container_name: dozzle
22+
image: amir20/dozzle:v5.4.0
23+
volumes:
24+
- /var/run/docker.sock:/var/run/docker.sock
25+
ports:
26+
- 9999:8080
27+
environment:
28+
DOZZLE_USERNAME: "${DOZZLE_USERNAME}"
29+
DOZZLE_PASSWORD: "${DOZZLE_PASSWORD}"
30+
restart: always
31+
env_file:
32+
- .env
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ services:
1616
- /home/ubuntu/gdgoc-be-app/.env:/app/.env
1717
env_file:
1818
- .env
19+
20+
dozzle:
21+
container_name: dozzle
22+
image: amir20/dozzle:v5.4.0
23+
volumes:
24+
- /var/run/docker.sock:/var/run/docker.sock
25+
ports:
26+
- 9999:8080
27+
environment:
28+
DOZZLE_USERNAME: "${DOZZLE_USERNAME}"
29+
DOZZLE_PASSWORD: "${DOZZLE_PASSWORD}"
30+
restart: always
31+
env_file:
32+
- .env
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
server:
2+
forward-headers-strategy: framework
3+
4+
spring:
5+
jackson:
6+
time-zone: Asia/Seoul
7+
datasource:
8+
url: ${SPRING_DATASOURCE_URL}
9+
username: ${SPRING_DATASOURCE_USERNAME}
10+
password: ${SPRING_DATASOURCE_PASSWORD}
11+
driver-class-name: org.postgresql.Driver
12+
servlet:
13+
multipart:
14+
max-file-size: 10MB
15+
max-request-size: 12MB
16+
jpa:
17+
database: postgresql
18+
hibernate:
19+
ddl-auto: none
20+
properties:
21+
hibernate:
22+
default_batch_fetch_size: 100
23+
time_zone: Asia/Seoul
24+
show-sql: false
25+
database-platform: org.hibernate.dialect.PostgreSQLDialect
26+
flyway:
27+
enabled: true
28+
baseline-on-migrate: false
29+
clean-disabled: true
30+
validate-migration-naming: true
31+
locations: classpath:db/migration
32+
mail:
33+
host: smtp.gmail.com
34+
port: 587
35+
username: ${GMAIL}
36+
password: ${GMAIL_PASSWORD}
37+
properties:
38+
mail:
39+
smtp:
40+
auth: true
41+
starttls:
42+
enable: true
43+
44+
logging:
45+
level:
46+
org.hibernate.SQL: debug
47+
org.hibernate.type: off
48+
49+
50+
google:
51+
client-id: ${GOOGLE_CLIENT_ID}
52+
client-secret: ${GOOGLE_CLIENT_SECRET}
53+
redirect-uri: ${GOOGLE_REDIRECT_URI}
54+
55+
jwt:
56+
googleIssuer: ${GOOGLE_ISSUER}
57+
selfIssuer: ${SELF_ISSUER}
58+
secretKey: ${SECRET_KEY}
59+
60+
cloud:
61+
aws:
62+
credentials:
63+
access-key: ${AWS_ACCESS_KEY_ID}
64+
secret-key: ${AWS_SECRET_ACCESS_KEY}
65+
region:
66+
static: ${AWS_REGION}
67+
s3:
68+
bucket: ${WS_TEST_RESOURCE_BUCKET}

gdgoc/src/main/resources/application-prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spring:
2525
database-platform: org.hibernate.dialect.PostgreSQLDialect
2626
flyway:
2727
enabled: true
28-
baseline-on-migrate: true # 변경 확인 후 제거 예정
28+
baseline-on-migrate: false
2929
clean-disabled: true
3030
validate-migration-naming: true
3131
locations: classpath:db/migration

0 commit comments

Comments
 (0)