Deploy to Amazon ECS #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build and push a new container image to Amazon ECR, | ||
# and then will deploy a new task definition for each of the services to Amazon ECS. | ||
# Note: The names of repository, cluster, services match what is configured in https://github.com/dimagi/ocs-deploy | ||
name: Deploy to Amazon ECS | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
description: "Deploy environment" | ||
required: true | ||
type: choice | ||
options: | ||
- dev | ||
- prod | ||
# push: | ||
# branches: [ "main" ] | ||
permissions: | ||
id-token: write | ||
contents: read | ||
jobs: | ||
init: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set variables | ||
run: | | ||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | ||
echo "DEPLOY_ENV=${{ inputs.environment }}" >> "$GITHUB_ENV" | ||
elif [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == "refs/heads/main" ]]; then | ||
echo "DEPLOY_ENV=prod" >> "$GITHUB_ENV" | ||
else | ||
echo "DEPLOY_ENV=dev" >> "$GITHUB_ENV" | ||
fi | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
needs: init | ||
env: | ||
AWS_REGION: ${{ vars.DEPLOY_AWS_REGION }} | ||
ECR_REPOSITORY: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-ecr-repo | ||
Check failure on line 46 in .github/workflows/deploy.yml GitHub Actions / Deploy to Amazon ECSInvalid workflow file
Check failure on line 46 in .github/workflows/deploy.yml GitHub Actions / Deploy to Amazon ECSInvalid workflow file
|
||
ECS_CLUSTER: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-Cluster | ||
ECS_SERVICE_DJANGO: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-Django | ||
ECS_SERVICE_CELERY: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-Celery | ||
ECS_SERVICE_CELERY_BEAT: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-CeleryBeat | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: configure aws credentials | ||
uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT }}:role/github_deploy | ||
role-session-name: GithubDeploy | ||
aws-region: ${{ env.AWS_REGION }} | ||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/[email protected] | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Get image names | ||
id: image-name | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
echo "image_latest=$ECR_REGISTRY/$ECR_REPOSITORY:latest" >> $GITHUB_OUTPUT | ||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
push: true | ||
tags: | | ||
${{ steps.image-name.outputs.image }} | ||
${{ steps.image-name.outputs.image_latest }} | ||
file: Dockerfile.web | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
# - name: Update ECS task def for Django web container | ||
# id: django-web-def | ||
# uses: aws-actions/[email protected] | ||
# with: | ||
# task-definition-family: ${{ env.ECS_SERVICE_DJANGO }}-${{ env.DEPLOY_ENV }}-Django | ||
# container-name: web | ||
# image: ${{ steps.image-name.outputs.image }} | ||
# | ||
# - name: Update ECS task def for Django migrations container | ||
# id: django-migrations-def | ||
# uses: aws-actions/[email protected] | ||
# with: | ||
# task-definition: ${{ steps.django-web-def.outputs.task-definition }} | ||
# container-name: migrate | ||
# image: ${{ steps.image-name.outputs.image }} | ||
# | ||
# - name: Update ECS task def for Celery worker container | ||
# id: celery-worker-def | ||
# uses: aws-actions/[email protected] | ||
# with: | ||
# task-definition-family: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-CeleryWorkerTask | ||
# container-name: celery-worker | ||
# image: ${{ steps.image-name.outputs.image }} | ||
# | ||
# - name: Update ECS task def for Celery beat container | ||
# id: celery-beat-def | ||
# uses: aws-actions/[email protected] | ||
# with: | ||
# task-definition-family: ${{ vars.DEPLOY_APP_NAME }}-${{ env.DEPLOY_ENV }}-CeleryBeatTask | ||
# container-name: celery-beat | ||
# image: ${{ steps.image-name.outputs.image }} | ||
# | ||
# - name: Deploy Django Web | ||
# uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | ||
# with: | ||
# task-definition: ${{ steps.django-migrations-def.outputs.task-definition }} | ||
# service: ${{ env.ECS_SERVICE_DJANGO }} | ||
# cluster: ${{ env.ECS_CLUSTER }} | ||
# wait-for-service-stability: false | ||
# | ||
# - name: Deploy Celery Worker | ||
# uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | ||
# with: | ||
# task-definition: ${{ steps.celery-worker-def.outputs.task-definition }} | ||
# service: ${{ env.ECS_SERVICE_CELERY }} | ||
# cluster: ${{ env.ECS_CLUSTER }} | ||
# wait-for-service-stability: false | ||
# | ||
# - name: Deploy Celery Beat | ||
# uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | ||
# with: | ||
# task-definition: ${{ steps.celery-beat-def.outputs.task-definition }} | ||
# service: ${{ env.ECS_SERVICE_CELERY_BEAT }} | ||
# cluster: ${{ env.ECS_CLUSTER }} | ||
# wait-for-service-stability: false | ||
# | ||
# - name: Wait for service stability | ||
# run: | | ||
# aws ecs wait services-stable --cluster $ECS_CLUSTER --services $ECS_SERVICE_DJANGO $ECS_SERVICE_CELERY $ECS_SERVICE_CELERY_BEAT |