From 10d6fcc7f7baea1668ed70fa5aa2b9be41e06ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Thu, 28 Dec 2023 16:20:37 +0900 Subject: [PATCH 01/19] Rollback 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 ca1ae185c269b7552820148d15b43d59027a425c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Thu, 28 Dec 2023 16:22:42 +0900 Subject: [PATCH 02/19] Update branch name to push --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index e213fdbe..67460a33 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -3,7 +3,7 @@ name: Deploy test server to ec2 on: push: branches: - - refact/issue-533 + - refact/issue-533-continued jobs: deploy: From d73710825a479975ebf7c88306b1dc5298a1065e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Thu, 28 Dec 2023 16:24:15 +0900 Subject: [PATCH 03/19] Add step to check default github workspace path --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 67460a33..b8bdc581 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -14,6 +14,9 @@ jobs: node-version: [16.x] steps: + - name: Print workspace directory + run: echo $GITHUB_WORKSPACE + - name: Checkout Repository uses: actions/checkout@v3 From 11840ba5400f29a68285af880761bf6a7a9fa8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Thu, 28 Dec 2023 16:38:31 +0900 Subject: [PATCH 04/19] Add path option for actions/checkout --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index b8bdc581..0bdc00bc 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -19,6 +19,8 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 + with: + path: development - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 From 2b559adacbc1c593c28c4cfe4ca90e62005b1749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 13:47:16 +0900 Subject: [PATCH 05/19] Delete unnecessary code --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 0bdc00bc..b8bdc581 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -19,8 +19,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 - with: - path: development - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 From 7392f17372eaeff0a6c865652f461858f2103edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 13:50:06 +0900 Subject: [PATCH 06/19] Use bash instead of sh --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index b8bdc581..f3c7f976 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -37,7 +37,7 @@ jobs: cp ~/config-injection/envs/.env.${{ env.NODE_ENV }} ${{ env.PROJECT_PATH }}/.env cd ${{ env.PROJECT_PATH }} bash script/prebuild.sh - sh script/reload.sh + bash script/reload.sh env: NODE_ENV: development From 994e84d96ce8e4b6b9e4c6d05a26782997426cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 13:51:56 +0900 Subject: [PATCH 07/19] Get the latest changes from the branch --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index f3c7f976..2286b5a3 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -36,6 +36,9 @@ jobs: 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 }} + git checkout refact/issue-533-continued + git reset --hard origin/refact/issue-533-continued + git pull origin refact/issue-533-continued bash script/prebuild.sh bash script/reload.sh From 07f20b40308ed54b2b114a8be217b0615a35d6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 13:52:39 +0900 Subject: [PATCH 08/19] Manage branch name with environment variable --- .../workflows/deploy-test-with-github-hosted-runner.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 2286b5a3..32c935b5 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -3,7 +3,7 @@ name: Deploy test server to ec2 on: push: branches: - - refact/issue-533-continued + - ${{ env.BRANCH_NAME }} jobs: deploy: @@ -36,13 +36,14 @@ jobs: 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 }} - git checkout refact/issue-533-continued - git reset --hard origin/refact/issue-533-continued - git pull origin refact/issue-533-continued + git checkout ${{ env.BRANCH_NAME }} + git reset --hard origin/${{ env.BRANCH_NAME }} + git pull origin ${{ env.BRANCH_NAME }} bash script/prebuild.sh bash script/reload.sh env: + BRANCH_NAME: refact/issue-533-continued NODE_ENV: development SERVER_PROFILE: development PROJECT_PATH: ~/development From c0e517b8e175ef1c3b9b2696632c5b7acabfb54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 13:57:33 +0900 Subject: [PATCH 09/19] Use '&&' to ensure each step runs successfully --- .../deploy-test-with-github-hosted-runner.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 32c935b5..cff471b7 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -33,13 +33,13 @@ jobs: 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 }} - git checkout ${{ env.BRANCH_NAME }} - git reset --hard origin/${{ env.BRANCH_NAME }} - git pull origin ${{ env.BRANCH_NAME }} - bash script/prebuild.sh + 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 }} && + git checkout ${{ env.BRANCH_NAME }} && + git reset --hard origin/${{ env.BRANCH_NAME }} && + git pull origin ${{ env.BRANCH_NAME }} && + bash script/prebuild.sh && bash script/reload.sh env: From 6fad7b8c90623d6f4cb7cdc4a5f1d7c09fa2f1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 14:02:49 +0900 Subject: [PATCH 10/19] Write branch name directly --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index cff471b7..286b2864 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -3,7 +3,7 @@ name: Deploy test server to ec2 on: push: branches: - - ${{ env.BRANCH_NAME }} + - refact/issue-533-continued jobs: deploy: From 46ad2bf92aee716dc444b7fc0017424d713e0e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 14:07:18 +0900 Subject: [PATCH 11/19] Fetch all branches from remote repository --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 286b2864..53497f13 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -36,6 +36,7 @@ jobs: 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 }} && + git fetch --all && git checkout ${{ env.BRANCH_NAME }} && git reset --hard origin/${{ env.BRANCH_NAME }} && git pull origin ${{ env.BRANCH_NAME }} && From ac8e887c380bd11df3fe8161aeef72e25cae1af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 15:22:31 +0900 Subject: [PATCH 12/19] Update reload.sh to delete duplicate code and clarify roles --- script/reload.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/script/reload.sh b/script/reload.sh index 1db728da..beb6b5b3 100755 --- a/script/reload.sh +++ b/script/reload.sh @@ -3,14 +3,6 @@ # 에러 핸들링 추가 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 From 4c4844c7ffa48c588e147a6578da7d8e919a9d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 15:46:40 +0900 Subject: [PATCH 13/19] Remove git reset and leave only git pull --- .github/workflows/deploy-test-with-github-hosted-runner.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-test-with-github-hosted-runner.yml b/.github/workflows/deploy-test-with-github-hosted-runner.yml index 53497f13..f90ab53b 100644 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ b/.github/workflows/deploy-test-with-github-hosted-runner.yml @@ -38,7 +38,6 @@ jobs: cd ${{ env.PROJECT_PATH }} && git fetch --all && git checkout ${{ env.BRANCH_NAME }} && - git reset --hard origin/${{ env.BRANCH_NAME }} && git pull origin ${{ env.BRANCH_NAME }} && bash script/prebuild.sh && bash script/reload.sh From 13b675b4d5758f4be2d854bfa002c4a12b857988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Fri, 29 Dec 2023 16:36:25 +0900 Subject: [PATCH 14/19] Reflect the changes so far in deployment-development.yml --- .github/workflows/deploy-development.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml index ea2b3d28..104caced 100644 --- a/.github/workflows/deploy-development.yml +++ b/.github/workflows/deploy-development.yml @@ -14,6 +14,9 @@ jobs: node-version: [16.x] steps: + - name: Print workspace directory + run: echo $GITHUB_WORKSPACE + - name: Checkout Repository uses: actions/checkout@v3 @@ -30,13 +33,17 @@ jobs: 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 + 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 }} && + git fetch --all && + git checkout ${{ env.BRANCH_NAME }} && + git pull origin ${{ env.BRANCH_NAME }} && + bash script/prebuild.sh && + bash script/reload.sh env: + BRANCH_NAME: dev NODE_ENV: development SERVER_PROFILE: development PROJECT_PATH: ~/actions-runner/_work/A.fume.Server/A.fume.Server/development From d534f0ae9e308fefa8d7d9e4fb9aaad64ce07b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Mon, 1 Jan 2024 11:44:21 +0900 Subject: [PATCH 15/19] Delete the file for testing using Github Hosted Runner --- .../deploy-test-with-github-hosted-runner.yml | 49 ------------------- 1 file changed, 49 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 f90ab53b..00000000 --- a/.github/workflows/deploy-test-with-github-hosted-runner.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Deploy test server to ec2 - -on: - push: - branches: - - refact/issue-533-continued - -jobs: - deploy: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - name: Print workspace directory - run: echo $GITHUB_WORKSPACE - - - 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 }} && - git fetch --all && - git checkout ${{ env.BRANCH_NAME }} && - git pull origin ${{ env.BRANCH_NAME }} && - bash script/prebuild.sh && - bash script/reload.sh - - env: - BRANCH_NAME: refact/issue-533-continued - NODE_ENV: development - SERVER_PROFILE: development - PROJECT_PATH: ~/development From eca4b1443aef9c011141ca1c375ff42e4f8ba2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Mon, 1 Jan 2024 12:45:03 +0900 Subject: [PATCH 16/19] Delete code for checking github workspace path --- .github/workflows/deploy-development.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/deploy-development.yml b/.github/workflows/deploy-development.yml index 104caced..f58cd28b 100644 --- a/.github/workflows/deploy-development.yml +++ b/.github/workflows/deploy-development.yml @@ -14,9 +14,6 @@ jobs: node-version: [16.x] steps: - - name: Print workspace directory - run: echo $GITHUB_WORKSPACE - - name: Checkout Repository uses: actions/checkout@v3 From 71a02cbbae147747da9f0937b6c82888571e8f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 2 Jan 2024 10:14:00 +0900 Subject: [PATCH 17/19] Reflect the changes so far in deployment-production-1.yml --- .github/workflows/deploy-production-1.yml | 44 ++++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy-production-1.yml b/.github/workflows/deploy-production-1.yml index f4401222..12d42c29 100644 --- a/.github/workflows/deploy-production-1.yml +++ b/.github/workflows/deploy-production-1.yml @@ -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 production-1 server to ec2 on: @@ -10,28 +7,41 @@ on: - production-1 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@v2 - with: - path: ${{ env.SERVER_PROFILE }} + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + 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 }} && + git fetch --all && + git checkout ${{ env.BRANCH_NAME }} && + git pull origin ${{ env.BRANCH_NAME }} && + bash script/prebuild.sh && + bash script/reload.sh + env: + BRANCH_NAME: production-1 NODE_ENV: production SERVER_PROFILE: production-1 PROJECT_PATH: ~/actions-runner/_work/A.fume.Server/A.fume.Server/production-1 From 890312fb068978969010b282af9eea5512e50216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 2 Jan 2024 10:14:42 +0900 Subject: [PATCH 18/19] Reflect the changes so far in deployment-production-2.yml --- .github/workflows/deploy-production-2.yml | 44 ++++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy-production-2.yml b/.github/workflows/deploy-production-2.yml index e442ca15..a59a5854 100644 --- a/.github/workflows/deploy-production-2.yml +++ b/.github/workflows/deploy-production-2.yml @@ -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 production-2 server to ec2 on: @@ -10,28 +7,41 @@ on: - production-2 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@v2 - with: - path: ${{ env.SERVER_PROFILE }} + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + 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 }} && + git fetch --all && + git checkout ${{ env.BRANCH_NAME }} && + git pull origin ${{ env.BRANCH_NAME }} && + bash script/prebuild.sh && + bash script/reload.sh + env: + BRANCH_NAME: production-2 NODE_ENV: production SERVER_PROFILE: production-2 PROJECT_PATH: ~/actions-runner/_work/A.fume.Server/A.fume.Server/production-2 From 58298ab745b5d3d1ab7ae32ca9c37f4f60031a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=95=98=EB=8B=B4?= Date: Tue, 2 Jan 2024 10:15:23 +0900 Subject: [PATCH 19/19] Reflect the changes so far in deployment-production.yml --- .github/workflows/deploy-production.yml | 45 +++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index f330e40e..82397e0b 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -1,36 +1,47 @@ -# 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 production server to ec2 on: + workflow_dispatch: push: branches: - main 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@v2 - with: - path: ${{ env.SERVER_PROFILE }} + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + 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 }} && + git fetch --all && + git checkout ${{ env.BRANCH_NAME }} && + git pull origin ${{ env.BRANCH_NAME }} && + bash script/prebuild.sh && + bash script/reload.sh + env: + BRANCH_NAME: main NODE_ENV: production SERVER_PROFILE: production PROJECT_PATH: ~/actions-runner/_work/A.fume.Server/A.fume.Server/production