Skip to content

ecs ci/cd

ecs ci/cd #9

Workflow file for this run

name: Deploy to Amazon ECS
on:
push:
branches: [ "main", "feat/indexer" ]
env:
AWS_REGION: us-east-1
ECR_REPOSITORY: ponder/indexer
ECS_SERVICE: ponder-indexer
ECS_CLUSTER: ponder-cluster
ECS_TASK_DEFINITION: ponder-task-definition
CONTAINER_NAME: indexer
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set up .env file
run: |
echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" > .env
echo "SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }}" >> .env
- 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: |
# Login to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 058264122535.dkr.ecr.us-east-1.amazonaws.com
# Build and push
docker buildx build \
--platform linux/amd64 \
--build-arg SUPABASE_URL=${{ secrets.SUPABASE_URL }} \
--build-arg SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY }} \
--push \
-t 058264122535.dkr.ecr.us-east-1.amazonaws.com/ponder/indexer:latest \
.
# Set the image output using the new GitHub Actions syntax
echo "image=058264122535.dkr.ecr.us-east-1.amazonaws.com/ponder/indexer:latest" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} \
--query taskDefinition > 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
force-new-deployment: true
desired-count: 1
network-configuration: |
{
"awsvpcConfiguration": {
"subnets": ["subnet-0cd439d262800846e", "subnet-0f8cf38a64d5dbcb5", "subnet-030a4f6086b8945e8", "subnet-0c8fb2a556e29ca39", "subnet-06ea05d9487a80b1d", "subnet-09bde9f5ac4ae4112"], # Replace with your private subnets
"securityGroups": ["sg-01abfa630f6281705"], # Replace with your security group
"assignPublicIp": "ENABLED"
}
}
load-balancers: |
[
{
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:058264122535:targetgroup/indexerapi/ecd5acc40de51460",
"containerName": "indexer",
"containerPort": 3000
}
]