CD #254
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
name: 'CD' | |
on: | |
workflow_dispatch: | |
inputs: | |
deploy_cli: | |
description: Deploy CLI | |
type: boolean | |
default: true | |
deploy_api: | |
description: Deploy API | |
type: boolean | |
default: true | |
deploy_web: | |
description: Deploy Website | |
type: boolean | |
default: true | |
push: | |
branches: | |
- master | |
- staging | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
prepare: | |
name: 'Prepare' | |
uses: rfcx/cicd/.github/workflows/notify-prepare.yaml@master | |
with: | |
repo: biodiversity-analytics | |
workflow-id: cd.yaml | |
secrets: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
configure: | |
name: 'Configure' | |
runs-on: ubuntu-latest | |
needs: [prepare] | |
outputs: | |
namespace: ${{ steps.configuration.outputs.namespace }} | |
release-date: ${{ steps.configuration.outputs.release-date }} | |
steps: | |
- name: 'Conditional environment' | |
id: configuration | |
run: | | |
if [[ "${{ needs.prepare.outputs.branch-name }}" == "master" ]]; then | |
echo "namespace=production" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ needs.prepare.outputs.branch-name }}" == "staging" ]]; then | |
echo "namespace=staging" >> "$GITHUB_OUTPUT" | |
else | |
echo "namespace=testing" >> "$GITHUB_OUTPUT" | |
fi | |
echo "release-date=$( date +"%s" ) >> $GITHUB_OUTPUT" | |
build: | |
name: 'Build' | |
needs: [prepare, configure] | |
uses: rfcx/cicd/.github/workflows/ecr-build-push.yaml@master | |
with: | |
dockerfile: tools/deployment/Dockerfile | |
targets: "[\"biodiversity-api\",\"biodiversity-cli\",\"biodiversity-website\"]" | |
tag-environment: ${{ needs.configure.outputs.namespace }} | |
tag-latest: ${{ needs.configure.outputs.namespace == 'production' }} | |
build-args: | | |
mode=${{ needs.configure.outputs.namespace }} | |
release_commit=${{ needs.configure.outputs.short-sha }} | |
release_date=${{ needs.configure.outputs.release-date }} | |
secrets: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
deploy: | |
name: 'Deploy' | |
runs-on: deployment-runner | |
needs: ['build', 'configure'] | |
steps: | |
- name: 'Deploy: Setup Git checkout' | |
# v4 (4.1.1) @ 17 Oct 2023 https://github.com/actions/checkout/tags | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 | |
- name: 'Deploy: Set image version' | |
run: | | |
find tools/deployment -name "*.yaml" -exec sed -i s/:latest/:${{ needs.build.outputs.unique-tag }}/g {} + | |
find tools/deployment -name "*.yaml" -exec sed -i s/JOB_NUMBER/${{ github.run_number }}/g {} + | |
- name: 'Deploy: Kubernetes apply CLI (starts migrate)' | |
if: ${{ github.event_name != 'workflow_dispatch' || inputs.deploy_cli }} | |
# v1 (1.28.2) @ 19 Oct 2023 https://github.com/actions-hub/kubectl/tags | |
uses: actions-hub/kubectl@2d1ce94ead5b3ba03de25df993a359c1b4657b05 | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_SUPER }} | |
with: | |
args: apply -f ./tools/deployment/cli/${{ needs.configure.outputs.namespace }} | |
- name: 'Deploy: Wait for migrate to complete successfully' | |
if: ${{ github.event_name != 'workflow_dispatch' || inputs.deploy_cli }} | |
# v1 (1.28.2) @ 19 Oct 2023 https://github.com/actions-hub/kubectl/tags | |
uses: actions-hub/kubectl@2d1ce94ead5b3ba03de25df993a359c1b4657b05 | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_SUPER }} | |
with: | |
args: wait --for=condition=complete --timeout=500s -n ${{ needs.configure.outputs.namespace }} job/biodiversity-cli-migrate-${{ github.run_number }} | |
- name: 'Deploy: Kubernetes apply API' | |
if: ${{ github.event_name != 'workflow_dispatch' || inputs.deploy_api }} | |
# v1 (1.28.2) @ 19 Oct 2023 https://github.com/actions-hub/kubectl/tags | |
uses: actions-hub/kubectl@2d1ce94ead5b3ba03de25df993a359c1b4657b05 | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_SUPER }} | |
with: | |
args: apply -f ./tools/deployment/api/${{ needs.configure.outputs.namespace }} | |
- name: 'Deploy: Kubernetes apply WEB' | |
if: ${{ github.event_name != 'workflow_dispatch' || inputs.deploy_web }} | |
# v1 (1.28.2) @ 19 Oct 2023 https://github.com/actions-hub/kubectl/tags | |
uses: actions-hub/kubectl@2d1ce94ead5b3ba03de25df993a359c1b4657b05 | |
env: | |
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_SUPER }} | |
with: | |
args: apply -f ./tools/deployment/website/${{ needs.configure.outputs.namespace }} | |
notify: | |
name: 'Notify' | |
if: ${{ always() }} | |
needs: [prepare, build, deploy] | |
uses: rfcx/cicd/.github/workflows/notify-send.yaml@master | |
with: | |
repo: biodiversity-analytics | |
branch-name: ${{ needs.prepare.outputs.branch-name }} | |
workflow-id: cd.yaml | |
previous-run-id: ${{ needs.prepare.outputs.previous-run-id }} | |
status: ${{ needs.deploy.result }} | |
always: true | |
notification-title: 'CD: APIs' | |
notification-footer: "Build: ${{ needs.build.result || 'n/a' }} | Deploy: ${{ needs.deploy.result || 'n/a' }}" | |
notification-success-statement: '{0} deployed the build!' | |
secrets: | |
slack-webhook: ${{ secrets.SLACK_ALERT_ARBIMON_WEBHOOK }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} |