Skip to content

Changed build to docker-compose #5

Changed build to docker-compose

Changed build to docker-compose #5

name: Docker Build, Push and Deploy Pitchlake UI
on:
push:
branches:
- ui-cicd #update branch name when everything looks good
env:
AWS_REGION: eu-central-1
ECR_REPOSITORY: pitchlake-ui-new_images_repository
ECS_SERVICE: pitchlake-ui-new-app
ECS_CLUSTER: pitchlake-ui-new-ecs-cluster
CONTAINER_NAME: pitchlake-ui-new
TASK_NAME: pitchlake-ui-new-app
permissions:
id-token: write
contents: write
jobs:
build_push_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if Docker is installed
run: |
if ! command -v docker &> /dev/null
then
sudo apt-get update
sudo apt-get install -y docker.io
sudo apt-get install -y docker-compose
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::654654236251:role/terraform-20241003185909187100000001
role-session-name: Github
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: "true"
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }}
run: |
IMAGE_TAG=pitchlake-ui-${{ github.sha }}
IMAGE_URI=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV
docker-compose buildx build --platform=linux/amd64 -f ./docker-compose.yml -t $IMAGE_URI ./
docker-compose push $IMAGE_URI
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.TASK_NAME }} --query taskDefinition > task-definition.json
- name: Log task definition
run: cat task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.IMAGE_URI }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true