Skip to content

Merge pull request #22 from berkeley-gif/tier_endpt_cleanup #38

Merge pull request #22 from berkeley-gif/tier_endpt_cleanup

Merge pull request #22 from berkeley-gif/tier_endpt_cleanup #38

Workflow file for this run

name: Build and push coeqwal-api to ECR
on:
push:
paths:
- 'api/**'
# Documentation-only edits do not change the image, so they don't rebuild
# and don't trigger ECS redeploys. A commit that also touches real code (Dockerfile,
# requirements, source) still matches the include above and triggers.
- '!api/**/*.md'
- '.github/workflows/api.yml'
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Linting runs as a separate workflow (.github/workflows/lint.yml) on
# every push touching Python files. This workflow handles build+deploy
# only.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Create ECR repository if not exists
run: |
aws ecr create-repository \
--repository-name coeqwal-network-api \
--region us-west-2 \
--image-scanning-configuration scanOnPush=true \
|| echo "Repository already exists"
- name: Build, tag, and push API Docker image to ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: coeqwal-network-api
IMAGE_TAG: ${{ github.sha }}
run: |
# Build context is api/coeqwal-api/ (the API service directory).
# The Dockerfile is multi-stage.
docker build --target prod -f api/coeqwal-api/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:latest api/coeqwal-api
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "✅ Image pushed to ECR: $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Update ECS service
run: |
echo "🔄 Updating ECS service to use new image..."
aws ecs update-service \
--cluster coeqwal-api \
--service coeqwal-api-service \
--force-new-deployment \
--region us-west-2
echo "✅ ECS service update triggered"
echo "🎯 API will be updated automatically in 3-5 minutes"