diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 66c0a5e..af5ee57 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -3,13 +3,14 @@ on: push: branches: [ "cicd-test" ] env: + JAR_FILE: logbat.jar BASTION_HOST_IP: ${{ secrets.BASTION_HOST_IP }} BACKEND_HOST_IP: ${{ secrets.BACKEND_HOST_IP }} permissions: contents: read jobs: - build-and-deploy: + build-and-push: runs-on: ubuntu-latest steps: - name: Checkout @@ -34,6 +35,21 @@ jobs: run: | cd logbat ./gradlew clean bootJar -x test + - name: Upload JAR file as artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.JAR_FILE }} + path: logbat/build/libs/*.jar + + deploy: + name: Deploy to EC2 + needs: build-and-push + runs-on: ubuntu-latest + steps: + - name: Download JAR file + uses: actions/download-artifact@v2 + with: + name: ${{ env.JAR_FILE }} - name: Start SSH Agent and Add Bastion Key uses: webfactory/ssh-agent@v0.9.0 with: @@ -43,8 +59,8 @@ jobs: - name: SCP JAR file to EC2 via Bastion run: | scp -o StrictHostKeyChecking=no -o ProxyCommand="ssh -W %h:%p -o StrictHostKeyChecking=no ubuntu@${{ secrets.BASTION_HOST_IP }}" \ - logbat/build/libs/*.jar ubuntu@${{ secrets.BACKEND_HOST_IP }}:/home/ubuntu/logbat.jar - - name: Execute deploy script on EC2 + ${{ env.JAR_FILE }} ubuntu@${{ secrets.BACKEND_HOST_IP }}:/home/ubuntu/${{ env.JAR_FILE }} + - name: Connect to Bastion and Deploy to EC2 run: | ssh -o StrictHostKeyChecking=no -A ubuntu@${{ secrets.BASTION_HOST_IP }} \ "ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.BACKEND_HOST_IP }} 'bash /home/ubuntu/deploy.sh'"