Skip to content

Commit

Permalink
Update workflows for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gsf committed Oct 5, 2024
1 parent 79dd451 commit 444d399
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 72 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ jobs:
ACCOUNT: ${{ inputs.environment == 'prod-test' && 'prod' || inputs.environment }}

steps:
- name: Assume role in AB2D ${{ env.ACCOUNT }} account
uses: aws-actions/configure-aws-credentials@v3
- uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets[format('{0}_ACCOUNT_ID', env.ACCOUNT)] }}:role/delegatedadmin/developer/ab2d-${{ env.ACCOUNT }}-github-actions

- name: Deploy latest image in ECR to ECS
- name: Deploy ECS service to run on latest image in ECR
run: aws ecs update-service --cluster ab2d-${DEPLOYMENT_ENV}-${{ inputs.module }} --service ab2d-${DEPLOYMENT_ENV}-${{ inputs.module }} --force-new-deployment
20 changes: 12 additions & 8 deletions .github/workflows/promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,29 @@ jobs:
DEPLOYMENT_ENV: ${{ vars[format('{0}_DEPLOYMENT_ENV', inputs.environment)] }}
run: |
REPO="ab2d_${{ inputs.module }}"
SHA_SHORT=$(git rev-parse --short HEAD)
#SHA_SHORT=$(git rev-parse --short HEAD)
SHA_SHORT=82d2398 # TODO remove after testing
# Get the manifest of the image pushed for latest commit to main
echo "Getting the manifest of the image pushed with the latest commit to main at sha $SHA_SHORT"
MANIFEST=$(aws ecr batch-get-image --repository-name "$REPO" --image-ids imageTag=main-$SHORT_SHA --output text --query 'images[].imageManifest')
# Add the tag for sha
if ! OUT=$(2>&1 aws ecr put-image --repository-name "$REPO" --image-tag "ab2d-$DEPLOYMENT_ENV-$SHA_SHORT" --image-manifest "$MANIFEST"); then
SHA_TAG="ab2d-$DEPLOYMENT_ENV-$SHA_SHORT"
echo "Adding the tag for $SHA_TAG to main-$SHORT_SHA image"
# Avoid failure on existing image and tag
if ! OUT=$(2>&1 aws ecr put-image --repository-name "$REPO" --image-tag "$SHA_TAG" --image-manifest "$MANIFEST"); then
if echo "$OUT" | grep ImageAlreadyExistsException > /dev/null; then
echo "Image for main-$SHORT_SHA has already been tagged with ab2d-$DEPLOYMENT_ENV-$SHA_SHORT"
echo "Image for main-$SHORT_SHA has already been tagged with $SHA_TAG"
else
>&2 echo "$OUT"
exit 1
fi
fi
# Add the tag for latest
if ! OUT=$(2>&1 aws ecr put-image --repository-name "$REPO" --image-tag "ab2d-$DEPLOYMENT_ENV-latest" --image-manifest "$MANIFEST"); then
LATEST_TAG="ab2d-$DEPLOYMENT_ENV-latest"
echo "Adding the tag for $LATEST_TAG to main-$SHORT_SHA image"
if ! OUT=$(2>&1 aws ecr put-image --repository-name "$REPO" --image-tag "$LATEST_TAG" --image-manifest "$MANIFEST"); then
if echo "$OUT" | grep ImageAlreadyExistsException > /dev/null; then
echo "Image for main-$SHORT_SHA has already been tagged with ab2d-$DEPLOYMENT_ENV-latest"
echo "Image for main-$SHORT_SHA has already been tagged with $LATEST_TAG"
else
>&2 echo "$OUT"
exit 1
Expand Down
124 changes: 63 additions & 61 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
release:
types: [released]
workflow_dispatch:
push: # TODO Remove after testing

permissions:
contents: read
Expand All @@ -26,64 +27,65 @@ jobs:
module: worker
secrets: inherit

# Promote and Deploy to prod
promote-prod-api:
uses: ./.github/workflows/promote.yml
with:
environment: prod
module: api
secrets: inherit

promote-prod-worker:
uses: ./.github/workflows/promote.yml
with:
environment: prod
module: worker
secrets: inherit

deploy-prod-api:
needs: promote-prod-api
uses: ./.github/workflows/deploy.yml
with:
environment: prod
module: api
secrets: inherit

deploy-prod-worker:
needs: promote-prod-worker
uses: ./.github/workflows/deploy.yml
with:
environment: prod
module: worker
secrets: inherit

# Promote and Deploy to sandbox
promote-sbx-api:
uses: ./.github/workflows/promote.yml
with:
environment: sbx
module: api
secrets: inherit

promote-sbx-worker:
uses: ./.github/workflows/promote.yml
with:
environment: sbx
module: worker
secrets: inherit

deploy-sbx-api:
needs: promote-sbx-api
uses: ./.github/workflows/deploy.yml
with:
environment: sbx
module: api
secrets: inherit

deploy-sbx-worker:
needs: promote-sbx-worker
uses: ./.github/workflows/deploy.yml
with:
environment: sbx
module: worker
secrets: inherit
# TODO Uncomment after testing
# # Promote and Deploy to prod
# promote-prod-api:
# uses: ./.github/workflows/promote.yml
# with:
# environment: prod
# module: api
# secrets: inherit
#
# promote-prod-worker:
# uses: ./.github/workflows/promote.yml
# with:
# environment: prod
# module: worker
# secrets: inherit
#
# deploy-prod-api:
# needs: promote-prod-api
# uses: ./.github/workflows/deploy.yml
# with:
# environment: prod
# module: api
# secrets: inherit
#
# deploy-prod-worker:
# needs: promote-prod-worker
# uses: ./.github/workflows/deploy.yml
# with:
# environment: prod
# module: worker
# secrets: inherit
#
# # Promote and Deploy to sandbox
# promote-sbx-api:
# uses: ./.github/workflows/promote.yml
# with:
# environment: sbx
# module: api
# secrets: inherit
#
# promote-sbx-worker:
# uses: ./.github/workflows/promote.yml
# with:
# environment: sbx
# module: worker
# secrets: inherit
#
# deploy-sbx-api:
# needs: promote-sbx-api
# uses: ./.github/workflows/deploy.yml
# with:
# environment: sbx
# module: api
# secrets: inherit
#
# deploy-sbx-worker:
# needs: promote-sbx-worker
# uses: ./.github/workflows/deploy.yml
# with:
# environment: sbx
# module: worker
# secrets: inherit

0 comments on commit 444d399

Please sign in to comment.