ElevenLabs Text-to-Speech MCP
by georgi-io
name: Docker Build and Push
on:
push:
branches:
- main
- develop
paths:
- 'src/**'
- 'Dockerfile'
- '.github/workflows/docker-build-and-push.yml'
workflow_dispatch:
# Cancel in-progress runs on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-push:
name: 🐳 Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
# Use a default role ARN initially to access S3
- name: Configure AWS credentials for S3 access
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::927485958639:role/jessica-github-actions-deployment-role
aws-region: eu-central-1
- name: Fetch Terraform State
id: terraform-state
run: |
# Install jq
sudo apt-get update && sudo apt-get install -y jq
# Download the state file
aws s3 cp s3://georgi-io-terraform-state/services/jessica/terraform.tfstate ./terraform.tfstate
# Extract values from state
ROLE_ARN=$(jq -r '.outputs.github_actions_deployment_role_arn.value' terraform.tfstate)
ECR_REPOSITORY=$(jq -r '.outputs.ecr_repository_name.value' terraform.tfstate)
ECS_CLUSTER=$(jq -r '.outputs.ecs_cluster_name.value' terraform.tfstate)
ECS_SERVICE=$(jq -r '.outputs.ecs_service_name.value' terraform.tfstate)
# Set outputs
echo "role_arn=${ROLE_ARN}" >> $GITHUB_OUTPUT
echo "ecr_repository=${ECR_REPOSITORY}" >> $GITHUB_OUTPUT
echo "ecs_cluster=${ECS_CLUSTER}" >> $GITHUB_OUTPUT
echo "ecs_service=${ECS_SERVICE}" >> $GITHUB_OUTPUT
# Clean up
rm terraform.tfstate
# Re-configure AWS credentials with the proper role from Terraform state
- name: Configure AWS credentials for ECR
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ steps.terraform-state.outputs.role_arn }}
aws-region: eu-central-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ steps.terraform-state.outputs.ecr_repository }}:latest
${{ steps.login-ecr.outputs.registry }}/${{ steps.terraform-state.outputs.ecr_repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Force new deployment of ECS service
run: |
aws ecs update-service --cluster ${{ steps.terraform-state.outputs.ecs_cluster }} --service ${{ steps.terraform-state.outputs.ecs_service }} --force-new-deployment
echo "New deployment of ECS service initiated"
- name: Set outputs for potential downstream jobs
id: vars
run: |
echo "image=${{ steps.login-ecr.outputs.registry }}/${{ steps.terraform-state.outputs.ecr_repository }}:${{ github.sha }}" >> $GITHUB_OUTPUT