From 02b82d4db036c2a0f212ed7efba125d6b4034a86 Mon Sep 17 00:00:00 2001 From: Arseni Kalma Date: Thu, 28 Nov 2024 18:12:49 +0100 Subject: [PATCH] Create push-deploy.yaml --- .github/workflows/push-deploy.yaml | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/push-deploy.yaml diff --git a/.github/workflows/push-deploy.yaml b/.github/workflows/push-deploy.yaml new file mode 100644 index 00000000000..0cbd605e62e --- /dev/null +++ b/.github/workflows/push-deploy.yaml @@ -0,0 +1,54 @@ +name: Deploy to Amazon ECS + +on: + push: + tags: + - '*' # Triggers the workflow on any new tag + +env: + AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: ${{ var.ECR_REPOSITORY }} # set this to your Amazon ECR repository name + ECS_SERVICE: ${{ var.ECS_SERVICE }} # set this to your Amazon ECS service name + ECS_CLUSTER: ${{ vars.ECS_CLUSTER }} # set this to your Amazon ECS cluster name + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: latest + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Update ECS Service to use the latest image + run: | + # Force a new deployment of the ECS service + aws ecs update-service \ + --cluster ${{ env.ECS_CLUSTER }} \ + --service ${{ env.ECS_SERVICE }} \ + --force-new-deployment