Skip to content

Commit

Permalink
Add initial auto-deploy workflow
Browse files Browse the repository at this point in the history
Add initial auto-deploy Github action workflow. This should
automatically build the containers and push to GHCR and use the GHCR
path to update task definitions and deploy to AWS ECS.

Currently being tested with the fastAPI branch.
  • Loading branch information
eternaltyro committed May 16, 2024
1 parent 00120fd commit 3034875
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/ecs-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Deploy to Amazon ECS

on:
push:
branches:
- tasking-manager-fastapi

env:
REGISTRY: ghcr.io
AWS_REGION: us-east-1
ECS_CLUSTER: tasking-manager
ECS_SERVICE: tasking-manager-fastAPI
CONTAINER_NAME: backend
IMAGE_NAME: hotosm/tasking-manager-backend # was ${{ github.repository }}

jobs:
build-push-image:
name: Build Images
runs-on: ubuntu-latest
environment: production

permissions:
contents: read
packages: write

outputs:
imageid: steps.build-push-image.imageid

steps:
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set container image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

tags: |
type=ref,event=branch
- name: Build and push container image
id: build-push-image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}"
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}

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@v4


- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition tasking-manager --query taskDefinition > task-definition.json
- name: Task definition rendition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ needs.build-push-image.outputs.imageid }}

- name: Deploy 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



0 comments on commit 3034875

Please sign in to comment.