From 387e6bb16bee329163b10a6ebfb37ec0009ec079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=B0=AC?= Date: Mon, 12 Aug 2024 14:12:29 +0900 Subject: [PATCH 1/5] Update fastcd.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ssh키 파일로 인식하게 임시 파일에 저장후 실행 --- .github/workflows/fastcd.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fastcd.yml b/.github/workflows/fastcd.yml index eaa4826..92d81dd 100644 --- a/.github/workflows/fastcd.yml +++ b/.github/workflows/fastcd.yml @@ -4,31 +4,48 @@ on: push: branches: - main + pull_request: + branches: + - main jobs: deploy: runs-on: ubuntu-latest steps: + # 리포지토리의 코드를 체크아웃합니다. - name: Check out the repository uses: actions/checkout@v3 + # Node.js 환경을 설정합니다. - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '16' + # 프로젝트의 의존성을 설치합니다. - name: Install dependencies run: npm install - - name: Deploy to AWS EC2 + # GitHub Secrets에서 SSH 키를 파일로 저장하고, 올바른 권한을 설정합니다. + - name: Add SSH key + run: | + echo "$DEPLOY_KEY" > /tmp/deploy_key.pem + chmod 600 /tmp/deploy_key.pem env: DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} + + # AWS EC2 인스턴스에 접속하여 애플리케이션을 배포합니다. + - name: Deploy to AWS EC2 run: | - ssh -i $DEPLOY_KEY -o StrictHostKeyChecking=no ubuntu@ec2-3-38-96-3.ap-northeast-2.compute.amazonaws.com << 'EOF' + ssh -i /tmp/deploy_key.pem -o StrictHostKeyChecking=no ubuntu@ec2-3-38-96-3.ap-northeast-2.compute.amazonaws.com << 'EOF' cd Pironeer_Attend_Web/ pm2 stop app.js || true git pull origin main npm install --production pm2 start app.js EOF + + # 배포 후, SSH 키 파일을 명시적으로 삭제합니다. + - name: Clean up + run: rm /tmp/deploy_key.pem From 45a69fa0df4a4ef97dd4f67462bd6a13b706d85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=B0=AC?= Date: Mon, 12 Aug 2024 14:20:26 +0900 Subject: [PATCH 2/5] Update fastcd.yml --- .github/workflows/fastcd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fastcd.yml b/.github/workflows/fastcd.yml index 92d81dd..64ee294 100644 --- a/.github/workflows/fastcd.yml +++ b/.github/workflows/fastcd.yml @@ -38,7 +38,7 @@ jobs: # AWS EC2 인스턴스에 접속하여 애플리케이션을 배포합니다. - name: Deploy to AWS EC2 run: | - ssh -i /tmp/deploy_key.pem -o StrictHostKeyChecking=no ubuntu@ec2-3-38-96-3.ap-northeast-2.compute.amazonaws.com << 'EOF' + ssh -i /tmp/deploy_key.pem -o StrictHostKeyChecking=no ubuntu@ec2-3-38-96-3.ap-northeast-2.compute.amazonaws.com cd Pironeer_Attend_Web/ pm2 stop app.js || true git pull origin main From dece5cc883fa7dc3043905cfe55c0cf0e1f609d9 Mon Sep 17 00:00:00 2001 From: chan000518 Date: Mon, 12 Aug 2024 14:28:40 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[cd]=20=EC=9E=90=EB=8F=99=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=B4=88=EC=95=88=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B5=9C=EC=A2=852?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/fastcd.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/fastcd.yml b/.github/workflows/fastcd.yml index d52f95c..9705e1e 100644 --- a/.github/workflows/fastcd.yml +++ b/.github/workflows/fastcd.yml @@ -25,13 +25,15 @@ jobs: run: npm install - name: Deploy to AWS EC2 - env: - DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} - run: | - ssh -i $DEPLOY_KEY -o StrictHostKeyChecking=no ubuntu@ec2-3-38-96-3.ap-northeast-2.compute.amazonaws.com << 'EOF' - cd Pironeer_Attend_Web/ - pm2 stop app.js || true - git pull origin main - npm install --production - pm2 start app.js - EOF + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_IP }} + username: ubuntu + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + cd Pironeer_Attend_Web/ + pm2 stop app.js || true + git pull origin main + npm install --production + pm2 start app.js + From 638156eec0edaa797b465d2619f8663971a8dbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=B0=AC?= Date: Mon, 12 Aug 2024 14:52:09 +0900 Subject: [PATCH 4/5] Update fastcd.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 자동 배포 완성 --- .github/workflows/fastcd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fastcd.yml b/.github/workflows/fastcd.yml index 4300b6a..479ec0a 100644 --- a/.github/workflows/fastcd.yml +++ b/.github/workflows/fastcd.yml @@ -35,8 +35,9 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} script: | cd Pironeer_Attend_Web/ - pm2 stop app.js || true git pull origin main npm install --production + pm2 stop app || true pm2 start app.js + sudo systemctl restart nginx From 0ea7581c928ee4676127312d17be3593d4ebfad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=B0=AC?= Date: Mon, 12 Aug 2024 14:52:56 +0900 Subject: [PATCH 5/5] Update fastcd.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 한번만 되게 변경 --- .github/workflows/fastcd.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/fastcd.yml b/.github/workflows/fastcd.yml index 479ec0a..c35de8c 100644 --- a/.github/workflows/fastcd.yml +++ b/.github/workflows/fastcd.yml @@ -4,9 +4,6 @@ on: push: branches: - main - pull_request: - branches: - - main jobs: deploy: