-
Notifications
You must be signed in to change notification settings - Fork 0
198 lines (186 loc) · 6.77 KB
/
deploy.yml
File metadata and controls
198 lines (186 loc) · 6.77 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Build and Deploy Chat Function to Lambda Feedback
on:
workflow_call:
inputs:
template-repository-name:
type: string
description: "The name of the repository where the template is located"
required: true
environment:
type: string
description: "Deploy to staging or production"
required: true
default: staging
region:
type: string
description: "The AWS region to deploy to"
required: false
build-file:
type: string
description: "The path to the Dockerfile to build"
required: false
default: "Dockerfile"
build-context:
type: string
description: "The context to use for the Docker build"
required: false
default: "."
build-target:
type: string
description: "The target stage of the image to build"
required: false
build-args:
type: string
description: "The build arguments to pass to the Docker build"
required: false
build-platforms:
type: string
description: "The platforms to build the image for"
default: "aws"
required: false
version-bump:
type: string
description: "Used for prod: The version number to bump (major, minor or patch)"
required: false
default: "patch"
branch:
type: string
description: "Used for prod: The branch to deploy"
required: false
default: "main"
deployed-environment-variables:
type: string
description: "The environment variables to set for the lambda function on aws, set as mock values."
required: false
secrets:
aws-key-id:
description: "The AWS access key ID"
required: true
aws-secret-key:
description: "The AWS secret access key"
required: true
function-admin-api-key:
description: "The API key for the Lambda Feedback backend function admin API"
required: true
build-secrets:
description: "The Docker secrets to use for the build"
required: false
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
chat_function_name: ${{ steps.chat_function_name.outputs.name }}
region: ${{ steps.set-region.outputs.region }}
sha: ${{ steps.sha.outputs.sha }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up boilerplate config.json
if: github.repository == inputs.template-repository-name
run: |
functionName=$(echo "${{ github.event.repository.name }}" | sed -E 's/([A-Z])([A-Z]*)/\L\1\2/g' | sed -E 's/-([a-z])/\U\1/g' | tr -d '-')
echo "{\"ChatFunctionName\": \"$functionName\"}" > config.json
- name: Check for config.json
run: |
if [[ ! -f "config.json" ]]; then echo "Error: config.json not found."; exit 1; fi
- name: Read config.json
id: config
run: |
echo 'config<<EOF' >> $GITHUB_OUTPUT
cat ./config.json >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Get Chat Function Name
id: chat_function_name
run: |
functionName="${{fromJson(steps.config.outputs.config).ChatFunctionName}}"
if [[ -z "$functionName" ]]; then echo "Set ChatFunctionName in config.json"; exit 1; fi
echo "name=$functionName" >> "$GITHUB_OUTPUT"
- name: Set default region
id: set-region
run: |
if [[ -n "${{ inputs.region }}" ]]; then
region="${{ inputs.region }}"
else
region="eu-west-2"
fi
echo "region=$region" >> "$GITHUB_OUTPUT"
- name: Output SHA
id: sha
run: echo "sha=${{ github.sha }}" >> $GITHUB_OUTPUT
- name: Validate AWS secrets
run: |
if [[ -z "${{ secrets.aws-key-id }}" ]]; then
echo "Error: aws-key-id secret is required"
exit 1
fi
if [[ -z "${{ secrets.aws-secret-key }}" ]]; then
echo "Error: aws-secret-key secret is required"
exit 1
fi
if [[ -z "${{ secrets.function-admin-api-key }}" ]]; then
echo "Error: function-admin-api-key secret is required"
exit 1
fi
deploy-staging:
if: inputs.environment == 'staging' || inputs.environment == 'production'
uses: ./.github/workflows/staging_deploy.yml
needs: setup
with:
chat_function_name: ${{ needs.setup.outputs.chat_function_name }}
template-repository-name: ${{ inputs.template-repository-name }}
region: ${{ needs.setup.outputs.region }}
build-file: ${{ inputs.build-file }}
build-context: ${{ inputs.build-context }}
build-target: ${{ inputs.build-target }}
build-args: ${{ inputs.build-args }}
build-platforms: ${{ inputs.build-platforms }}
deployed-environment-variables: ${{ inputs.deployed-environment-variables }}
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
function-admin-api-key: ${{ secrets.function-admin-api-key }}
build-secrets: ${{ secrets.build-secrets }}
await-approval:
name: "Await Manual Approval (Production)"
if: inputs.environment == 'production' && needs.deploy-staging.result == 'success'
environment: production-override
runs-on: ubuntu-latest
needs: [setup, deploy-staging]
steps:
- name: "Manual approval received for production deployment"
run: echo "Production deployment approved."
deploy-production:
if: >
always() &&
inputs.environment == 'production' &&
needs.deploy-staging.result == 'success' &&
needs.await-approval.result == 'success'
uses: ./.github/workflows/production_deploy.yml
needs:
- setup
- deploy-staging
- await-approval
with:
chat_function_name: ${{ needs.setup.outputs.chat_function_name }}
template-repository-name: ${{ inputs.template-repository-name }}
region: ${{ needs.setup.outputs.region }}
build-file: ${{ inputs.build-file }}
build-context: ${{ inputs.build-context }}
build-target: ${{ inputs.build-target }}
build-args: ${{ inputs.build-args }}
build-platforms: ${{ inputs.build-platforms }}
version-bump: ${{ inputs.version-bump }}
sha: ${{ needs.setup.outputs.sha }}
deployed-environment-variables: ${{ inputs.deployed-environment-variables }}
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
function-admin-api-key: ${{ secrets.function-admin-api-key }}
build-secrets: ${{ secrets.build-secrets }}