Skip to content

Commit

Permalink
feat(wip): wip actions
Browse files Browse the repository at this point in the history
  • Loading branch information
briancaffey committed Apr 25, 2024
1 parent e4ccb4f commit 816708f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/backend_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ jobs:
VERSION: ${{ inputs.VERSION }}
ECR_REPO: backend
CONTAINER_NAME: update

update:
name: Update
permissions:
id-token: write
contents: read
strategy:
matrix:
service-name: [gunicorn, default-worker]
runs-on: ubuntu-latest
steps:
- name: Update the services
uses: ./packages/ecr
with:

5 changes: 5 additions & 0 deletions packages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Packages

This folder contains GitHub Actions workflows that are used to update the application.

See `.github/workflows/backend_update.yml` for an example of how these workflows are used.
67 changes: 67 additions & 0 deletions packages/ecr-update-service/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: 'Action for running an ECS task in a GHA workflow'
description: 'Action for running ECS task'
author: 'Brian Caffey'
inputs:
BASE_ENV:
required: true
description: 'Base env name (e.g. dev)'
APP_ENV:
required: true
description: 'App env name (e.g. alpha)'
VERSION:
required: true
description: 'Application version git tag (e.g. v1.2.3)'
ECR_REPO:
required: true
description: 'ECR repo to use'
CONTAINER_NAME:
required: true
description: 'Name of the container to update'
AWS_REGION:
required: false
description: 'AWS Region'
default: 'us-east-1'

runs:
using: "composite"
steps:
# Note: this assumes that your ECR repo lives in the same AWS account as your ECS cluster
- name: Get current AWS Account
id: get-aws-account
shell: bash
run: |
AWS_ACCOUNT_ID=$(aws sts get-caller-identity | jq -r .Account)
echo $AWS_ACCOUNT_ID
echo "AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID" >> $GITHUB_ENV
- name: Download existing task definition
id: download-task-definition
shell: bash
# CONTAINER_NAME
run: |
aws ecs describe-task-definition \
--task-definition ${{ inputs.CONTAINER_NAME }} \
| jq '.taskDefinition' > task-definition.json
- name: Remove fields from task definition
id: cleaned-task-def
shell: bash
run: |
jq 'del(.compatibilities, .taskDefinitionArn, .requiresAttributes, .revision, .status, .registeredAt, .registeredBy)' task-definition.json > cleaned-task-definition.json
- name: Render new task definition
id: render-new-task-definition
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: cleaned-task-definition.json
container-name: ${{ inputs.CONTAINER_NAME }} # CONTAINER_NAME
image: ${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ inputs.AWS_REGION}}.amazonaws.com/${{ inputs.ECR_REPO }}:${{ inputs.VERSION }}

- name: Deploy new task definition
id: deploy-new-task-definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
cluster: ${{ inputs.APP_ENV }}-cluster #CLUSTER_NAME
task-definition: ${{ steps.render-new-task-definition.outputs.task-definition }}
service: ${{ inputs.APP_ENV }}-${{ inputs.CONTAINER_NAME }} # SERVICE_NAME
wait-for-service-stability: true

0 comments on commit 816708f

Please sign in to comment.