Skip to content

Commit 46a571e

Browse files
CLAP-234 CI/CD 스크립트 분리 (#74)
* 👷 [cicd] : CI/CD 스크립트 분리
1 parent 2a9243b commit 46a571e

File tree

2 files changed

+90
-61
lines changed

2 files changed

+90
-61
lines changed
Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,57 @@
1-
# github repository actions 페이지에 나타날 이름
2-
name: CI/CD for front using github actions
3-
4-
# event trigger
5-
# develop 브랜치에 pull_request가 닫히거나 푸시했을때 실행
6-
on:
7-
pull_request:
8-
types: [closed]
9-
branches: [ "develop" ]
10-
push:
11-
branches: [ "develop" ]
12-
13-
14-
permissions:
15-
contents: read
16-
17-
jobs:
18-
front-cicd:
19-
runs-on: ubuntu-latest
20-
steps:
21-
# 저장소 코드를 체크아웃합니다. (PR 올린 코드를 가져오는 행위)
22-
- uses: actions/checkout@v4
23-
24-
# Node.js 환경 설정
25-
- name: Use Node.js
26-
uses: actions/setup-node@v4
27-
with:
28-
node-version: 22 # 지정된 Node.js 버전 사용
29-
cache: npm # setup-node 의 캐시 기능을 사용함
30-
cache-dependency-path: package-lock.json # 캐시 기능을 사용할 때 캐시의 기준이 될 파일을 지정
31-
32-
- name: Install Dependencies
33-
run: npm install
34-
35-
- name: Build with npm
36-
run: npm run build || exit 0 # exit 0를 추가하여 경고성 오류 무시
37-
38-
- name: Create nginx.conf
39-
run: touch ./nginx.conf
40-
- run: echo "${{ secrets.NGINX_CONF }}" > ./nginx.conf
41-
42-
## docker build & push to production
43-
- name: Docker build & push
44-
run: |
45-
docker login clap.kr-central-2.kcr.dev -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
46-
docker build -t ${{ secrets.DOCKER_FRONT_REPO }} .
47-
docker push ${{ secrets.DOCKER_FRONT_REPO }}
48-
49-
## deploy
50-
- name: Deploy
51-
uses: appleboy/ssh-action@master
52-
id: deploy
53-
with:
54-
host: ${{ secrets.FRONT_HOST }}
55-
username: ${{ secrets.FRONT_HOST_USERNAME }}
56-
key: ${{ secrets.FRONT_HOST_KEY }}
57-
port: ${{ secrets.FRONT_HOST_PORT }}
58-
script: |
59-
docker rm -f taskflow-front
60-
docker image rm ${{ secrets.DOCKER_FRONT_REPO }} -f
61-
docker run --name taskflow-front -d -p 80:80 --restart on-failure ${{ secrets.DOCKER_FRONT_REPO }}
1+
# github repository actions 페이지에 나타날 이름
2+
name: CD for front using github actions
3+
4+
# event trigger
5+
# develop 브랜치에 pull_request가 닫히거나 푸시했을때 실행
6+
on:
7+
push:
8+
branches: [ "develop" ]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
front-cicd:
15+
runs-on: ubuntu-latest
16+
steps:
17+
# 저장소 코드를 체크아웃합니다. (PR 올린 코드를 가져오는 행위)
18+
- uses: actions/checkout@v4
19+
20+
# Node.js 환경 설정
21+
- name: Use Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 22 # 지정된 Node.js 버전 사용
25+
cache: npm # setup-node 의 캐시 기능을 사용함
26+
cache-dependency-path: package-lock.json # 캐시 기능을 사용할 때 캐시의 기준이 될 파일을 지정
27+
28+
- name: Install Dependencies
29+
run: npm install
30+
31+
- name: Build with npm
32+
run: npm run build-only
33+
34+
- name: Create nginx.conf
35+
run: touch ./nginx.conf
36+
- run: echo "${{ secrets.NGINX_CONF }}" > ./nginx.conf
37+
38+
## docker build & push to production
39+
- name: Docker build & push
40+
run: |
41+
docker login clap.kr-central-2.kcr.dev -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
42+
docker build -t ${{ secrets.DOCKER_FRONT_REPO }} .
43+
docker push ${{ secrets.DOCKER_FRONT_REPO }}
44+
45+
## deploy
46+
- name: Deploy
47+
uses: appleboy/ssh-action@master
48+
id: deploy
49+
with:
50+
host: ${{ secrets.FRONT_HOST }}
51+
username: ${{ secrets.FRONT_HOST_USERNAME }}
52+
key: ${{ secrets.FRONT_HOST_KEY }}
53+
port: ${{ secrets.FRONT_HOST_PORT }}
54+
script: |
55+
docker rm -f taskflow-front
56+
docker image rm ${{ secrets.DOCKER_FRONT_REPO }} -f
57+
docker run --name taskflow-front -d -p 80:80 --restart on-failure ${{ secrets.DOCKER_FRONT_REPO }}

.github/workflows/CI.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# github repository actions 페이지에 나타날 이름
2+
name: CI for front using github actions
3+
4+
# event trigger
5+
# develop 브랜치에 pull_request가 닫히거나 푸시했을때 실행
6+
on:
7+
pull_request:
8+
types: [ opened, synchronize ]
9+
branches: [ "develop" ]
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
front-cicd:
16+
runs-on: ubuntu-latest
17+
steps:
18+
# 저장소 코드를 체크아웃합니다. (PR 올린 코드를 가져오는 행위)
19+
- uses: actions/checkout@v4
20+
21+
# Node.js 환경 설정
22+
- name: Use Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 22 # 지정된 Node.js 버전 사용
26+
cache: npm # setup-node 의 캐시 기능을 사용함
27+
cache-dependency-path: package-lock.json # 캐시 기능을 사용할 때 캐시의 기준이 될 파일을 지정
28+
29+
- name: Install Dependencies
30+
run: npm install
31+
32+
- name: Build with npm
33+
run: npm run build-only

0 commit comments

Comments
 (0)