-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (127 loc) · 5.32 KB
/
cd.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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 }}