Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dev branch CI/CD process #534

Merged
merged 6 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions .github/workflows/deploy-development.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Deploy development server to ec2

on:
Expand All @@ -9,27 +6,36 @@ on:
- dev

jobs:
build:
runs-on: self-hosted
deploy:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
defaults:
run:
working-directory: ${{ env.SERVER_PROFILE }}

steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0
with:
path: ${{ env.SERVER_PROFILE }}
- name: Checkout Repository
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 #v.3.5.1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: cp ~/config-injection/ecosystem-${{ env.SERVER_PROFILE }}.json ${{ env.PROJECT_PATH }}/ecosystem.json
- run: cp ~/config-injection/envs/.env.${{ env.NODE_ENV }} ${{ env.PROJECT_PATH }}/.env
- run: bash ${{ env.PROJECT_PATH }}/script/prebuild.sh
- run: sh ${{ env.PROJECT_PATH }}/script/reload.sh

- name: Deploy to EC2 using SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
cp ~/config-injection/ecosystem-${{ env.SERVER_PROFILE }}.json ${{ env.PROJECT_PATH }}/ecosystem.json
cp ~/config-injection/envs/.env.${{ env.NODE_ENV }} ${{ env.PROJECT_PATH }}/.env
cd ${{ env.PROJECT_PATH }}
bash script/prebuild.sh
sh script/reload.sh

env:
NODE_ENV: development
SERVER_PROFILE: development
Expand Down
15 changes: 13 additions & 2 deletions script/prebuild.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/bin/bash

# 에러 핸들링 추가
set -e

# ecosystem.json 파일이 존재하면 pm2로 실행 중인 프로세스 중지
if [[ -f "ecosystem.json" ]]; then
pm2 stop ecosystem.json
pm2 stop ecosystem.json || true
fi

npm ci
# 종속성 설치
npm ci || exit 1

# 프로젝트 빌드
npm run build || exit 1

# Exit code를 출력하여 스크립트가 성공적으로 실행되었는지 확인
echo $?
21 changes: 16 additions & 5 deletions script/reload.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/bin/sh
#!/bin/bash

pm2 stop ecosystem.json
npm run build
pm2 restart ecosystem.json
echo $?
# 에러 핸들링 추가
set -e

# ecosystem.json 파일이 존재하면 pm2로 실행 중인 프로세스를 중지
if [[ -f "ecosystem.json" ]]; then
pm2 stop ecosystem.json || true
fi

# npm run build 명령어로 프로젝트 빌드
npm run build || exit 1

# ecosystem.json 사용하여 pm2로 프로세스 재시작
if [[ -f "ecosystem.json" ]]; then
pm2 restart ecosystem.json || exit 1
fi
Loading