Skip to content

Backend Build&Push to Test ECR #259

Backend Build&Push to Test ECR

Backend Build&Push to Test ECR #259

name: Backend Build&Push to Test ECR
on:
push:
branches: [ 'develop', 'feat/*' ]
permissions:
id-token: write
contents: read
jobs:
build:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_AWS_ROLE }}
aws-region: eu-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: cloud-web
IMAGE_TAG: latest
run: |
export COMMIT_SHA=$(git rev-parse --short HEAD)
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg COMMIT_SHA=${COMMIT_SHA} . -f Dockerfile_backend
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
restart:
needs: build
name: Restart ECS service
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_AWS_ROLE}}
aws-region: us-east-1
- name: Restart ECS
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
AWS_REGION: eu-west-2
run: |
aws ecs update-service --cluster ${{ vars.ECS_CLUSTER_NAME }} --service ${{ vars.ECS_SERVICE_NAME }} --force-new-deployment --region $AWS_REGION