From 8cd19f509a8e4dad46a0e8a995247703da2b6843 Mon Sep 17 00:00:00 2001 From: Polspoel Jens Date: Wed, 16 Oct 2024 13:02:10 +0200 Subject: [PATCH 1/2] :construction_worker: Only deploy uat when pushing to uat branch --- .github/workflows/deploy_uat.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_uat.yml b/.github/workflows/deploy_uat.yml index b0d738a..6e0054d 100644 --- a/.github/workflows/deploy_uat.yml +++ b/.github/workflows/deploy_uat.yml @@ -2,8 +2,8 @@ name: Deploy UAT on: push: - # branches: - # - development + branches: + - uat jobs: deploy: From fb0506e4c35c42967aa81fc8b2e48ab75adfc8cd Mon Sep 17 00:00:00 2001 From: Polspoel Jens Date: Wed, 16 Oct 2024 13:03:13 +0200 Subject: [PATCH 2/2] :construction_worker: Add github action for production --- .github/workflows/deploy_prod.yml | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/deploy_prod.yml diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml new file mode 100644 index 0000000..4a4e235 --- /dev/null +++ b/.github/workflows/deploy_prod.yml @@ -0,0 +1,56 @@ +name: Deploy PROD + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: self-hosted + environment: PROD + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + role-to-assume: ${{ secrets.AWS_ECR_DEPLOYMENT_ROLE }} + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: BACK-END - Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: ${{ secrets.AWS_ECR_REPO_BACKEND }} + IMAGE_TAG: uat + run: | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f Dockerfile.backend . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: FRONT-END - Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: ${{ secrets.AWS_ECR_REPO_FRONTEND }} + IMAGE_TAG: latest + run: | + docker build --build-arg ${{ secrets.FRONTEND_DOCKER_BUILD_ARGS }} -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f Dockerfile.frontend . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: Setup AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_DEFAULT_REGION }} + role-to-assume: ${{ secrets.AWS_DEPLOYMENT_ROLE }} + - name: Deploy new backend task + run: | + aws ecs update-service --cluster ${{ secrets.AWS_ECS_CLUSTER }} --service ${{ secrets.AWS_ECS_DJANGO_SERVICE }} --force-new-deployment + - name: Deploy new backend task + run: | + aws ecs update-service --cluster ${{ secrets.AWS_ECS_CLUSTER }} --service ${{ secrets.AWS_ECS_NODE_SERVICE }} --force-new-deployment