-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDPT-1012 New deploy process with slack notifications (#204)
- Loading branch information
Showing
4 changed files
with
308 additions
and
156 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
name: Deploy Workflow | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_call: | ||
|
||
env: | ||
PREFIX: "fm-api" | ||
|
||
concurrency: | ||
group: deploy-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Assume role in Cloud Platform | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.ECR_ROLE_TO_ASSUME }} | ||
aws-region: ${{ vars.ECR_REGION }} | ||
|
||
- name: Login to container repository | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
id: login-ecr | ||
|
||
- name: Store current date | ||
run: echo "BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S%z)" >> $GITHUB_ENV | ||
|
||
- name: Store build tag | ||
id: vars | ||
run: | | ||
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
short_sha=$(git rev-parse --short ${{ github.sha }}) | ||
build_tag=$PREFIX-$branch-$short_sha | ||
echo "build_tag=$build_tag" >> $GITHUB_OUTPUT | ||
- name: Build | ||
run: | | ||
docker build \ | ||
--build-arg APP_BUILD_DATE=${{ env.BUILD_DATE }} \ | ||
--build-arg APP_BUILD_TAG=${{ steps.vars.outputs.build_tag }} \ | ||
--build-arg APP_GIT_COMMIT=${{ github.sha }} \ | ||
-t ${{ vars.ECR_URL }}:${{ github.sha }} . | ||
- name: Push to ECR | ||
run: | | ||
docker tag ${{ vars.ECR_URL }}:${{ github.sha }} ${{ vars.ECR_URL }}:staging.latest | ||
docker tag ${{ vars.ECR_URL }}:${{ github.sha }} ${{ vars.ECR_URL }}:production.latest | ||
docker push ${{ vars.ECR_URL }}:${{ github.sha }} | ||
docker push ${{ vars.ECR_URL }}:staging.latest | ||
docker push ${{ vars.ECR_URL }}:production.latest | ||
deploy-staging: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: staging | ||
|
||
env: | ||
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Store build tag | ||
id: vars | ||
run: | | ||
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
short_sha=$(git rev-parse --short ${{ github.sha }}) | ||
build_tag=$PREFIX-$branch-$short_sha | ||
echo "build_tag=$build_tag" >> $GITHUB_OUTPUT | ||
- name: Update image tag | ||
env: | ||
ECR_URL: ${{ vars.ECR_URL }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
cat config/kubernetes/staging/deployment.tpl | envsubst > config/kubernetes/staging/deployment.yaml | ||
cat config/kubernetes/staging/migrations.tpl | envsubst > config/kubernetes/staging/migrations.yaml | ||
- name: Authenticate to the cluster | ||
env: | ||
KUBE_CERT: ${{ secrets.KUBE_CERT }} | ||
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }} | ||
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | ||
run: | | ||
echo "${KUBE_CERT}" > ca.crt | ||
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | ||
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | ||
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | ||
kubectl config use-context ${KUBE_CLUSTER} | ||
- name: Rollout restart deployment | ||
run: | | ||
kubectl set image -n ${KUBE_NAMESPACE} \ | ||
deployment/family-mediators-api-deployment-staging \ | ||
webapp="${{ vars.ECR_URL }}:${{ github.sha }}" | ||
- name: Send deploy notification to product Slack channel | ||
uses: slackapi/slack-github-action@v1.24.0 | ||
with: | ||
payload: | | ||
{ | ||
"attachments": [ | ||
{ | ||
"color": "#1d990c", | ||
"text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *Staging*", | ||
"fields": [ | ||
{ | ||
"title": "Project", | ||
"value": "Family Mediators API", | ||
"short": true | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"text": "Visit Job", | ||
"type": "button", | ||
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | ||
|
||
deploy-production: | ||
runs-on: ubuntu-latest | ||
needs: deploy-staging | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
environment: production | ||
|
||
env: | ||
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Store build tag | ||
id: vars | ||
run: | | ||
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | ||
short_sha=$(git rev-parse --short ${{ github.sha }}) | ||
build_tag=$PREFIX-$branch-$short_sha | ||
echo "build_tag=$build_tag" >> $GITHUB_OUTPUT | ||
- name: Update image tag | ||
env: | ||
ECR_URL: ${{ vars.ECR_URL }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
cat config/kubernetes/production/deployment.tpl | envsubst > config/kubernetes/production/deployment.yaml | ||
cat config/kubernetes/production/migrations.tpl | envsubst > config/kubernetes/production/migrations.yaml | ||
- name: Authenticate to the cluster | ||
env: | ||
KUBE_CERT: ${{ secrets.KUBE_CERT }} | ||
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }} | ||
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }} | ||
run: | | ||
echo "${KUBE_CERT}" > ca.crt | ||
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER} | ||
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN} | ||
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE} | ||
kubectl config use-context ${KUBE_CLUSTER} | ||
- name: Rollout restart deployment | ||
run: | | ||
kubectl set image -n ${KUBE_NAMESPACE} \ | ||
deployment/family-mediators-api-deployment-production \ | ||
webapp="${{ vars.ECR_URL }}:${{ github.sha }}" | ||
- name: Send deploy notification to product Slack channel | ||
uses: slackapi/slack-github-action@v1.24.0 | ||
with: | ||
payload: | | ||
{ | ||
"attachments": [ | ||
{ | ||
"color": "#1d990c", | ||
"text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *Production*", | ||
"fields": [ | ||
{ | ||
"title": "Project", | ||
"value": "Family Mediators API", | ||
"short": true | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"text": "Visit Job", | ||
"type": "button", | ||
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | ||
|
||
- name: Send deploy notification to product Slack channel | ||
uses: slackapi/slack-github-action@v1.24.0 | ||
with: | ||
payload: | | ||
{ | ||
"attachments": [ | ||
{ | ||
"color": "#1d990c", | ||
"text": "${{ github.actor }} deployed *${{ steps.vars.outputs.build_tag }}* to *Production*", | ||
"fields": [ | ||
{ | ||
"title": "Project", | ||
"value": "Family Mediators API", | ||
"short": true | ||
} | ||
], | ||
"actions": [ | ||
{ | ||
"text": "Visit Job", | ||
"type": "button", | ||
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.PROD_SLACK_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |
Oops, something went wrong.