-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from endless-horses/chore#3-cicd
CI/CD 파이프라인 구현 close #3
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Continuous Deployment | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
workflow_dispatch: | ||
inputs: | ||
logLevel: | ||
description: 'Log level' | ||
required: true | ||
default: 'warning' | ||
type: choice | ||
options: | ||
- info | ||
- warning | ||
- debug | ||
tags: | ||
description: 'Test scenario tags' | ||
required: false | ||
type: boolean | ||
environment: | ||
description: 'Environment to run tests against' | ||
type: environment | ||
required: false | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
develop-deploy: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
# 1. Compare branch 코드 내려 받기 | ||
- name: Checkout PR | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.push.base_ref }} | ||
|
||
# 2. Docker 이미지 build 및 push | ||
- name: Docker build and push | ||
run: | | ||
echo "${{ secrets.ENVIRONMENT }}" > .env | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t jinlee1703/oot-web:latest . | ||
docker push jinlee1703/oot-web:latest | ||
# 3. SSH ACTION을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행) | ||
- name: Deploy | ||
uses: appleboy/ssh-action@v0.1.5 | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
port: ${{ secrets.SERVER_SSH_PORT }} | ||
username: ${{ secrets.SERVER_USERNAME }} | ||
password: ${{ secrets.SERVER_PASSWORD }} | ||
script: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker system prune -a -f | ||
docker pull jinlee1703/oot-web:latest | ||
docker-compose up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Check Build Possibility | ||
|
||
on: | ||
pull_request: | ||
branches: [ "develop" ] | ||
|
||
jobs: | ||
build-test: | ||
runs-on: ubuntu-20.04 | ||
env: | ||
DISABLE_ESLINT_PLUGIN: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3.5.1 | ||
with: | ||
node-version: "21.2.0" | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Try build | ||
run: npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 가져올 이미지를 정의 | ||
FROM node:20 | ||
# 경로 설정하기 | ||
WORKDIR /app | ||
# package.json 워킹 디렉토리에 복사 (.은 설정한 워킹 디렉토리를 뜻함) | ||
COPY package.json . | ||
# 명령어 실행 (의존성 설치) | ||
RUN npm install | ||
# 현재 디렉토리의 모든 파일을 도커 컨테이너의 워킹 디렉토리에 복사한다. | ||
COPY . . | ||
|
||
# 각각의 명령어들은 한줄 한줄씩 캐싱되어 실행된다. | ||
# package.json의 내용은 자주 바뀌진 않을 거지만 | ||
# 소스 코드는 자주 바뀌는데 | ||
# npm install과 COPY . . 를 동시에 수행하면 | ||
# 소스 코드가 조금 달라질때도 항상 npm install을 수행해서 리소스가 낭비된다. | ||
|
||
# 3000번 포트 노출 | ||
EXPOSE 3000 |