From 5c558b93fdfad6e213bd5f99487e89e3257eae76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 12:30:17 +0900 Subject: [PATCH 1/6] Update prebuild.sh --- script/prebuild.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/script/prebuild.sh b/script/prebuild.sh index 3a8a83a9..f2bc5326 100755 --- a/script/prebuild.sh +++ b/script/prebuild.sh @@ -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 \ No newline at end of file +# 종속성 설치 +npm ci || exit 1 + +# 프로젝트 빌드 +npm run build || exit 1 + +# Exit code를 출력하여 스크립트가 성공적으로 실행되었는지 확인 +echo $? \ No newline at end of file From 2edb7eaa6108dd91957f52fbad3bd21c1d959388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 12:30:27 +0900 Subject: [PATCH 2/6] Update reload.sh --- script/reload.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/script/reload.sh b/script/reload.sh index c8af0c4a..1db728da 100755 --- a/script/reload.sh +++ b/script/reload.sh @@ -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 \ No newline at end of file From ea316a84cef8bcd00bf2500186a8b5d9295f7427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 12:33:55 +0900 Subject: [PATCH 3/6] Create deploy file to test with Github Hosted Runner --- .../deploy-test-with-github-hosted-runner.yml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/deploy-test-with-github-hosted-runner.yml diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml new file mode 100644 index 00000000..e213fdbe --- /dev/null +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -0,0 +1,42 @@ +name: Deploy test server to ec2 + +on: + push: + branches: + - refact/issue-533 + +jobs: + deploy: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.TEST_HOST }} # 인스턴스 IP + username: ${{ secrets.TEST_USERNAME }} # 우분투 아이디 + key: ${{ secrets.TEST_PEM_KEY }} # ec2 instance pem 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 + PROJECT_PATH: ~/development From 07d1d786011b293bb552ba82294eae12413d4a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 16:07:07 +0900 Subject: [PATCH 4/6] Update deploy-development.yml using github-hosted runner and SSH --- .github/workflows/deploy-development.yml | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml index c15bc545..967d8810 100644 --- a/.github/workflows/deploy-development.yml +++ b/.github/workflows/deploy-development.yml @@ -1,35 +1,42 @@ -# 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: push: branches: - - dev + # - dev + - refact/issue-533 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 From 52be57a24912a37233068fb9433559846e4ba3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 18:22:05 +0900 Subject: [PATCH 5/6] Rollback branch name to push --- .github/workflows/deploy-development.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml index 967d8810..ea2b3d28 100644 --- a/.github/workflows/deploy-development.yml +++ b/.github/workflows/deploy-development.yml @@ -3,8 +3,7 @@ name: Deploy development server to ec2 on: push: branches: - # - dev - - refact/issue-533 + - dev jobs: deploy: From 9e3e5e7495f5fa4a9b0ffe4eeea90bc425aef191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 26 Dec 2023 18:24:26 +0900 Subject: [PATCH 6/6] Remove workflow file for testing --- .../deploy-test-with-github-hosted-runner.yml | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 .github/workflows/deploy-test-with-github-hosted-runner.yml diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml deleted file mode 100644 index e213fdbe..00000000 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Deploy test server to ec2 - -on: - push: - branches: - - refact/issue-533 - -jobs: - deploy: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: executing remote ssh commands using ssh key - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.TEST_HOST }} # 인스턴스 IP - username: ${{ secrets.TEST_USERNAME }} # 우분투 아이디 - key: ${{ secrets.TEST_PEM_KEY }} # ec2 instance pem 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 - PROJECT_PATH: ~/development