Skip to content

Commit dab51a9

Browse files
Merge pull request #45 from boostcampwm-2024/CI/빌드_최적화
CI/배포 과정 최적화
2 parents 8c7fba6 + 7224c91 commit dab51a9

File tree

3 files changed

+83
-29
lines changed

3 files changed

+83
-29
lines changed

.github/workflows/deploy.yml

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,66 @@ on:
77
- main
88

99
jobs:
10+
build-frontend:
11+
name: Frontend Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup pnpm
17+
uses: pnpm/action-setup@v4
18+
with:
19+
version: 8
20+
21+
- name: Cache pnpm store
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.pnpm-store
25+
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
26+
27+
- run: pnpm install
28+
- run: pnpm --filter client run build
29+
30+
- name: Upload client/dist
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: client-dist
34+
path: client/dist
35+
36+
build-backend:
37+
name: Backend Build
38+
runs-on: [self-hosted, boost-was]
39+
steps:
40+
- name: Checkout Repository
41+
uses: actions/checkout@v4
42+
43+
- name: Build Backend Image
44+
env:
45+
NODE_ENV: production
46+
MONGO_URI: ${{ secrets.MONGO_URI }}
47+
JWT_SECRET: ${{ secrets.JWT_SECRET }}
48+
JWT_REFRESH_SECRET: ${{ secrets.JWT_REFRESH_SECRET }}
49+
VITE_API_URL: ${{ secrets.VITE_API_URL }}
50+
AI_PROMPT: ${{ secrets.AI_PROMPT }}
51+
AI_API_URL: ${{ secrets.AI_API_URL }}
52+
AI_API_KEY: ${{ secrets.AI_API_KEY }}
53+
run: docker-compose build backend
54+
1055
deploy:
1156
name: Deploy on Server
12-
runs-on: [self-hosted, boost-was] # 라벨에 해당하는 runner로 실행
13-
57+
needs: [build-frontend, build-backend]
58+
runs-on: [self-hosted, boost-was]
1459
steps:
15-
# 1. 레포지토리 클론
1660
- name: Checkout Repository
1761
uses: actions/checkout@v4
1862

19-
# 2. Docker Compose로 서비스 빌드 및 재시작
20-
- name: Build and Deploy Docker Images
63+
- name: Download client-dist
64+
uses: actions/download-artifact@v4
65+
with:
66+
name: client-dist
67+
path: client/dist
68+
69+
- name: Start Services
2170
env:
2271
NODE_ENV: production
2372
MONGO_URI: ${{ secrets.MONGO_URI }}
@@ -27,9 +76,7 @@ jobs:
2776
AI_PROMPT: ${{ secrets.AI_PROMPT }}
2877
AI_API_URL: ${{ secrets.AI_API_URL }}
2978
AI_API_KEY: ${{ secrets.AI_API_KEY }}
30-
run: |
31-
docker-compose up -d --build
79+
run: docker-compose up -d --no-build
3280

33-
# 3. Clean up Old Images
34-
- name: Remove Dangling Images
81+
- name: Cleanup
3582
run: docker image prune -f

.github/workflows/lint_and_test.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- dev
88

99
jobs:
10-
lint_and_unit_test:
10+
lint-and-unit-test:
1111
name: Lint and Unit Test
1212
runs-on: ubuntu-latest
1313

@@ -43,8 +43,28 @@ jobs:
4343
JWT_REFRESH_SECRET: ${{ secrets.JWT_REFRESH_SECRET }}
4444
VITE_API_URL: ${{ secrets.VITE_API_URL }}
4545

46-
test_building_docker_image:
47-
name: Test Building Docker Image
46+
frontend-build-test:
47+
name: Frontend Build Test
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Setup pnpm
53+
uses: pnpm/action-setup@v4
54+
with:
55+
version: 8
56+
57+
- name: Cache pnpm store
58+
uses: actions/cache@v4
59+
with:
60+
path: ~/.pnpm-store
61+
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
62+
63+
- run: pnpm install
64+
- run: pnpm --filter client run build
65+
66+
backend-build-test:
67+
name: Backend Build Test
4868
runs-on: ubuntu-latest
4969

5070
steps:
@@ -77,4 +97,4 @@ jobs:
7797
JWT_REFRESH_SECRET: ${{ secrets.JWT_REFRESH_SECRET }}
7898
VITE_API_URL: ${{ secrets.VITE_API_URL }}
7999
run: |
80-
docker-compose build frontend backend
100+
docker-compose build backend

docker-compose.yml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
services:
2-
frontend:
3-
build:
4-
context: .
5-
dockerfile: ./client/Dockerfile
6-
volumes:
7-
- ./client/dist:/app/client/dist
8-
environment:
9-
- NODE_ENV=${NODE_ENV}
10-
- VITE_API_URL=${VITE_API_URL}
11-
command: pnpm --filter client run build
12-
132
backend:
143
build:
154
context: .
@@ -27,18 +16,16 @@ services:
2716
- AI_API_KEY=${AI_API_KEY}
2817

2918
nginx:
30-
build:
31-
context: .
32-
dockerfile: ./nginx/Dockerfile
19+
image: nginx:alpine
3320
ports:
3421
- "80:80"
3522
- "443:443"
3623
volumes:
37-
- ./client/dist:/usr/share/nginx/html
24+
- ./client/dist:/usr/share/nginx/html:ro
25+
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
3826
- ~/certbot/www:/var/www/certbot
3927
- /etc/letsencrypt:/etc/letsencrypt:ro
4028
depends_on:
41-
- frontend
4229
- backend
4330

4431
networks:

0 commit comments

Comments
 (0)