Skip to content

Merge branch 'main' of https://github.com/hackbio-ca/PRISM #3

Merge branch 'main' of https://github.com/hackbio-ca/PRISM

Merge branch 'main' of https://github.com/hackbio-ca/PRISM #3

Workflow file for this run

name: Deploy to AWS ECS
on:
push:
branches: [ main, interface ]
paths:
- 'interface/backend/**'
- 'Dockerfile'
- '.github/workflows/**'
# Allow manual triggering
workflow_dispatch:
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: bioinfo/repo
ECS_SERVICE: prism-api-service-0u9t6ggt
ECS_CLUSTER: bioinfo-cluster
ECS_TASK_DEFINITION: prism-api
CONTAINER_NAME: prism-container
jobs:
deploy:
name: Deploy to ECS
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure 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-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ env.AWS_REGION }}
- 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, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build Docker image for x86_64 (ECS Fargate compatibility)
docker buildx build \
--platform linux/amd64 \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:latest \
--push .
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition \
--task-definition $ECS_TASK_DEFINITION \
--query taskDefinition > task-definition-raw.json
# Clean task definition by removing unsupported fields for GitHub Actions
jq 'del(.enableFaultInjection, .taskDefinitionArn, .revision, .status, .requiresCompatibilities, .placementConstraints, .compatibilities, .registeredAt, .registeredBy)' \
task-definition-raw.json > 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: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
- name: Service deployment summary
run: |
echo "🚀 Deployment successful!"
echo "📦 Image: ${{ steps.build-image.outputs.image }}"
echo "🎯 Service: ${{ env.ECS_SERVICE }}"
echo "🔗 Check your ALB URL for the updated API"