From b6f23b536aecf317dd8168c17d7a924054384866 Mon Sep 17 00:00:00 2001 From: plduthoit <139240078+plduthoit@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:37:45 +0200 Subject: [PATCH 1/5] ci: Add gh action to deploy on dev and uat --- .github/workflows/deploy.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..d102fd26 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,32 @@ +name: Deploy to Server + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up SSH + uses: webfactory/ssh-agent@v0.8.1 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Deploy to UAT + if: github.ref == 'refs/heads/main' + run: | + ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ + "cd /home/ubuntu/puc_uat && git fetch origin && git reset --hard origin/main && make deploy" + + - name: Deploy to Dev + if: github.event_name == 'workflow_dispatch' + run: | + ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ + "cd /home/ubuntu/puc_dev && git fetch origin && git reset --hard origin/${{ github.ref_name }} && make deploy" From 9949e8da550c0055c1dcdd948c5ec92332dccfe7 Mon Sep 17 00:00:00 2001 From: plduthoit <139240078+plduthoit@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:40:30 +0200 Subject: [PATCH 2/5] ci: Fix gh action ssh-agent version --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d102fd26..65552adf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v3 - name: Set up SSH - uses: webfactory/ssh-agent@v0.8.1 + uses: webfactory/ssh-agent@v0.9.0 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} From 83b1f4b42267935dcc3dd2de52ea83944d1250ed Mon Sep 17 00:00:00 2001 From: plduthoit <139240078+plduthoit@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:08:51 +0200 Subject: [PATCH 3/5] ci: Refactor deploy to env using secrets env --- .github/workflows/deploy.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 65552adf..d5658464 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,14 +19,16 @@ jobs: with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Deploy to UAT - if: github.ref == 'refs/heads/main' + - name: Set Environment Variables + id: set-env run: | - ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ - "cd /home/ubuntu/puc_uat && git fetch origin && git reset --hard origin/main && make deploy" - - - name: Deploy to Dev - if: github.event_name == 'workflow_dispatch' + if [ "${{ github.ref }}" == "refs/heads/main" ]; then + echo "ENVIRONMENT=uat" >> $GITHUB_ENV + else + echo "ENVIRONMENT=dev" >> $GITHUB_ENV + fi + + - name: Deploy to Server run: | ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ - "cd /home/ubuntu/puc_dev && git fetch origin && git reset --hard origin/${{ github.ref_name }} && make deploy" + "cd ${{ secrets.REMOTE_PATH }} && git fetch origin && git reset --hard origin/${{ github.ref_name }} && make deploy" From 17724e5f2ba60fe0ef694dcd6c3bdf6f52332a53 Mon Sep 17 00:00:00 2001 From: plduthoit <139240078+plduthoit@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:10:16 +0200 Subject: [PATCH 4/5] fix(ci): Set env vars before testing ssh --- .github/workflows/deploy.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d5658464..f09b4271 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,11 +14,6 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up SSH - uses: webfactory/ssh-agent@v0.9.0 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Set Environment Variables id: set-env run: | @@ -27,6 +22,11 @@ jobs: else echo "ENVIRONMENT=dev" >> $GITHUB_ENV fi + + - name: Set up SSH + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Deploy to Server run: | From 994d871b7e02977ee360e4f87c8d8131dc909ae7 Mon Sep 17 00:00:00 2001 From: plduthoit <139240078+plduthoit@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:19:46 +0200 Subject: [PATCH 5/5] fix(ci): Fix env to deploy --- .github/workflows/deploy.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f09b4271..3ab96367 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,20 +9,13 @@ on: jobs: deploy: runs-on: ubuntu-latest + environment: + name: ${{ github.ref == 'refs/heads/main' && 'uat' || 'dev' }} steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set Environment Variables - id: set-env - run: | - if [ "${{ github.ref }}" == "refs/heads/main" ]; then - echo "ENVIRONMENT=uat" >> $GITHUB_ENV - else - echo "ENVIRONMENT=dev" >> $GITHUB_ENV - fi - - name: Set up SSH uses: webfactory/ssh-agent@v0.9.0 with: