From 7d3ee40c83a37a76e4d784e6bf8e5c998d21d68f Mon Sep 17 00:00:00 2001 From: ForsbergPhilip <60732259+ForsbergPhilip@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:20:39 +0100 Subject: [PATCH] fix: deploy to prod (#347) --- .github/workflows/main.yml | 124 +++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 60 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f31bf29..e61a16f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,12 +48,13 @@ jobs: steps: - run: echo "Ref ${{ github.ref }}" - - uses: actions/checkout@v1 + - name: Checkout code + uses: actions/checkout@v4 - name: Build docker image run: | docker build -t diamonds2_base:latest -f .docker/dockerfiles/base . - docker-compose -f docker-compose.yml build + docker compose -f docker-compose.yml build # Build and push production images build-prod: @@ -63,11 +64,14 @@ jobs: needs: - test-backend steps: - - uses: actions/checkout@v1 + - name: Checkout code + uses: actions/checkout@v4 + - name: Build docker image run: | docker build -t diamonds2_base:latest -f .docker/dockerfiles/base . - docker-compose -f docker-compose.prod-build.yml build + docker compose -f docker-compose.prod-build.yml build + - name: Extract branch name shell: bash run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV @@ -88,59 +92,59 @@ jobs: docker push etimodanielwinther/diamonds2_backend:latest-${BRANCH_NAME} docker push etimodanielwinther/diamonds2_backend:${BRANCH_NAME}-${{ github.sha }} # When pushing code to master we want to deploy latest master images to test environment - # deploy-prod: - # name: Deploy to new account - # needs: build-prod - # runs-on: ubuntu-latest - # if: github.ref == 'refs/heads/master' - # steps: - # - uses: chrnorm/deployment-action@releases/v1 - # name: Create GitHub deployment - # id: deployment - # with: - # token: "${{ github.token }}" - # target_url: https://diamonds.etimo.se - # environment: prod - # initial_status: "in_progress" - # - name: Update apps - # uses: appleboy/ssh-action@master - # with: - # host: ${{ secrets.DEPLOY_ETIMO_AWS_HOST }} - # USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} - # PORT: 22 - # KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }} - # script: | - # cd diamonds2 - # git fetch - # git checkout --progress --force ${{ github.sha }} - # docker-compose down - # docker system prune -af - # source ~/.bash_profile - # DIAMONDS_DOCKER_TAG=master-${{ github.sha }} docker-compose -f docker-compose.prod-run.yml up -d - # - name: Update autoscaler - # uses: appleboy/ssh-action@master - # with: - # host: ${{ secrets.DEPLOY_ETIMO_AWS_AUTOSCALER_HOST }} - # USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} - # PORT: 22 - # KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }} - # script: | - # cd diamonds2 - # git fetch - # git checkout --progress --force ${{ github.sha }} - # - name: Update deployment status (success) - # if: success() - # uses: chrnorm/deployment-status@releases/v1 - # with: - # token: "${{ github.token }}" - # target_url: https://diamonds.etimo.se - # state: "success" - # deployment_id: ${{ steps.deployment.outputs.deployment_id }} - # - name: Update deployment status (failure) - # if: failure() - # uses: chrnorm/deployment-status@releases/v1 - # with: - # token: "${{ github.token }}" - # target_url: https://diamonds.etimo.se - # state: "failure" - # deployment_id: ${{ steps.deployment.outputs.deployment_id }} + deploy-prod: + name: Deploy to new account + needs: build-prod + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - uses: chrnorm/deployment-action@releases/v1 + name: Create GitHub deployment + id: deployment + with: + token: "${{ github.token }}" + target_url: https://diamonds.etimo.se + environment: prod + initial_status: "in_progress" + - name: Update apps + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEPLOY_ETIMO_AWS_HOST }} + USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} + PORT: 22 + KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }} + script: | + cd diamonds2 + git fetch + git checkout --progress --force ${{ github.sha }} + docker-compose down + docker system prune -af + source ~/.bash_profile + DIAMONDS_DOCKER_TAG=master-${{ github.sha }} docker-compose -f docker-compose.prod-run.yml up -d + - name: Update autoscaler + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEPLOY_ETIMO_AWS_AUTOSCALER_HOST }} + USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} + PORT: 22 + KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }} + script: | + cd diamonds2 + git fetch + git checkout --progress --force ${{ github.sha }} + - name: Update deployment status (success) + if: success() + uses: chrnorm/deployment-status@releases/v1 + with: + token: "${{ github.token }}" + target_url: https://diamonds.etimo.se + state: "success" + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + - name: Update deployment status (failure) + if: failure() + uses: chrnorm/deployment-status@releases/v1 + with: + token: "${{ github.token }}" + target_url: https://diamonds.etimo.se + state: "failure" + deployment_id: ${{ steps.deployment.outputs.deployment_id }}