Skip to content

Commit

Permalink
github: add trigger job to staging/prod workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
digorgonzola committed Feb 1, 2024
1 parent c5438a6 commit 078fe8d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 81 deletions.
73 changes: 33 additions & 40 deletions .github/workflows/build-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ permissions:
id-token: write
contents: read

env:
environment_name: production

jobs:
build_push:
runs-on: ubuntu-latest
environment: production
environment: ${{ env.environment_name }}
outputs:
image_digest: ${{ steps.build_and_push.outputs.digest }}
steps:
Expand Down Expand Up @@ -50,49 +53,39 @@ jobs:
- name: Push Image Digest to SSM
run: |
aws ssm put-parameter \
--name "/apps/sample-django-app/production/image_digest" \
--name "/apps/sample-django-app/${{ env.environment_name }}/image_digest" \
--type "String" \
--value "$digest" \
--overwrite
env:
digest: ${{ steps.build_and_push.outputs.digest }}

# Optional deployment job if you want to update the task immediately
# However, the appdeploy repository is configured to run drift jobs on an hourly basis
# See: https://terrateam.io/docs/features/drift-detection
trigger_deploy:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DEPLOY_APP_ID }}
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "appdeploy"

# deploy:
# runs-on: ubuntu-latest
# environment: production
# needs: [build_push]
# steps:
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# audience: sts.amazonaws.com
# aws-region: ${{ vars.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
#
# - name: Get Currently Running Task Definition
# id: get-current-task-definition
# run: |
# aws ecs describe-task-definition \
# --task-definition ${{ vars.FAMILY }} \
# --query taskDefinition > task-definition.json
#
# - name: Update Task Definition with Image Digest
# id: update-api-image-tag
# uses: aws-actions/amazon-ecs-render-task-definition@v1
# with:
# task-definition: task-definition.json
# container-name: app
# image: ${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }}@${{ needs.build_push.outputs.image_digest }}
#
# - name: Deploy to Amazon ECS service
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1
# with:
# task-definition: ${{ steps.update-api-image-tag.outputs.task-definition }}
# service: ${{ vars.FAMILY }}
# cluster: ${{ vars.CLUSTER }}
# force-new-deployment: true
# wait-for-service-stability: true
- name: Trigger Deploy Workflow
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
retries: 3
retry-exempt-status-codes: 204
script: |
github.rest.actions.createWorkflowDispatch({
owner: 'aodn',
repo: 'appdeploy',
workflow_id: 'deploy.yml',
ref: 'main',
inputs: {
app_name: 'sample-django-app',
environment: '${{ env.environment_name }}'
}
})
74 changes: 33 additions & 41 deletions .github/workflows/build-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ permissions:
id-token: write
contents: read

env:
environment_name: staging

jobs:
build_push:
runs-on: ubuntu-latest
environment: staging
environment: ${{ env.environment_name }}
outputs:
image_digest: ${{ steps.build_and_push.outputs.digest }}
steps:
Expand Down Expand Up @@ -54,50 +57,39 @@ jobs:
- name: Push Image Digest to SSM
run: |
aws ssm put-parameter \
--name "/apps/sample-django-app/staging/image_digest" \
--name "/apps/sample-django-app/${{ env.environment_name }}/image_digest" \
--type "String" \
--value "$digest" \
--overwrite
env:
digest: ${{ steps.build_and_push.outputs.digest }}

trigger_deploy:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.DEPLOY_APP_ID }}
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "appdeploy"

# Optional deployment job if you want to update the task immediately
# However, the appdeploy repository is configured to run drift jobs on an hourly basis
# See: https://terrateam.io/docs/features/drift-detection

# deploy:
# runs-on: ubuntu-latest
# environment: staging
# needs: [build_push]
# steps:
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# audience: sts.amazonaws.com
# aws-region: ${{ vars.AWS_REGION }}
# role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
#
# - name: Get Currently Running Task Definition
# id: get-current-task-definition
# run: |
# aws ecs describe-task-definition \
# --task-definition ${{ vars.FAMILY }} \
# --query taskDefinition > task-definition.json
#
# - name: Update Task Definition with Image Digest
# id: update-api-image-tag
# uses: aws-actions/amazon-ecs-render-task-definition@v1
# with:
# task-definition: task-definition.json
# container-name: app
# image: ${{ vars.ECR_REGISTRY }}/${{ vars.ECR_REPOSITORY }}@${{ needs.build_push.outputs.image_digest }}
#
# - name: Deploy to Amazon ECS service
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1
# with:
# task-definition: ${{ steps.update-api-image-tag.outputs.task-definition }}
# service: ${{ vars.FAMILY }}
# cluster: ${{ vars.CLUSTER }}
# force-new-deployment: true
# wait-for-service-stability: true
- name: Trigger Deploy Workflow
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token }}
retries: 3
retry-exempt-status-codes: 204
script: |
github.rest.actions.createWorkflowDispatch({
owner: 'aodn',
repo: 'appdeploy',
workflow_id: 'deploy.yml',
ref: 'main',
inputs: {
app_name: 'sample-django-app',
environment: '${{ env.environment_name }}'
}
})

0 comments on commit 078fe8d

Please sign in to comment.