From d30a064d985f78a773487d9ad59ea5e109d8bd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Caiado=20da=20Silva?= Date: Thu, 4 Apr 2024 11:27:14 +0100 Subject: [PATCH] deploy to aws wc2 --- .github/workflows/CI-CD.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI-CD.yml b/.github/workflows/CI-CD.yml index 274a6bb..76516c5 100644 --- a/.github/workflows/CI-CD.yml +++ b/.github/workflows/CI-CD.yml @@ -132,8 +132,22 @@ jobs: needs: [prepare, build-image-push] if: always() && (needs.build-image-push.result == 'success' && needs.prepare.outputs.deploy == 'true') steps: - - name: Deploy + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Set permissions for private key + run: | + echo "${{ secrets.AWS_EC2_PRIVATE_KEY }}" > key.pem + chmod 600 key.pem + - name: Pull Docker image + run: | + ssh -o StrictHostKeyChecking=no -i key.pem spring-boot-test-cicd-ec2@52.56.61.209 'sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ needs.prepare.outputs.tag_version }}' + - name: Stop running container + run: | + ssh -o StrictHostKeyChecking=no -i key.pem spring-boot-test-cicd-ec2@52.56.61.209 'sudo docker stop spring-boot-tests-cicd || true' + ssh -o StrictHostKeyChecking=no -i key.pem spring-boot-test-cicd-ec2@y52.56.61.209 'sudo docker rm spring-boot-tests-cicd || true' + - name: Run new container run: | - echo ${{ needs.prepare.outputs.deploy }} - echo ${{ needs.prepare.outputs.deploy == 'true' }} - echo "Deploying the app to ${{ needs.prepare.outputs.environment }} using ${{ github.event.repository.name }}:${{ needs.prepare.outputs.tag_version }} image" + ssh -o StrictHostKeyChecking=no -i key.pem spring-boot-test-cicd-ec2@52.56.61.209 'sudo docker run -d --name spring-boot-tests-cicd -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ needs.prepare.outputs.tag_version }}'