-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (223 loc) · 9.73 KB
/
deploy.yml
File metadata and controls
235 lines (223 loc) · 9.73 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Build and Deploy Evaluation 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
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
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 function admin API"
required: true
build-secrets:
description: "The Docker secrets to use for the build"
required: false
gcp_credentials:
description: "The JSON key for deploying to GCP"
required: false
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
evaluation_function_name: ${{ steps.normalize-function-name.outputs.name }}
region: ${{ steps.set-region.outputs.region }}
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 "{\"EvaluationFunctionName\": \"$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 Evaluation Function Name
id: evaluation_function_name
run: |
functionName="${{fromJson(steps.config.outputs.config).EvaluationFunctionName}}"
if [[ -z "$functionName" ]]; then echo "Set EvaluationFunctionName in config.json"; exit 1; fi
echo "name=$functionName" >> "$GITHUB_OUTPUT"
- name: Setup normalize function name
id: setup-normalize-function-name
uses: Entepotenz/change-string-case-action-min-dependencies@v1
with:
string: ${{ steps.evaluation_function_name.outputs.name }}
- name: Normalize function name
id: normalize-function-name
run: echo name=${{steps.setup-normalize-function-name.outputs.lowercase}} >> $GITHUB_OUTPUT
- name: Set default region based on platform
id: set-region
run: |
if [[ -n "${{ inputs.region }}" ]]; then
# Use provided region
region="${{ inputs.region }}"
elif [[ "${{ inputs.build-platforms }}" == "aws" ]]; then
# Default AWS region
region="eu-west-2"
else
# Default GCP region (or other platforms)
region="europe-west2"
fi
echo "region=$region" >> "$GITHUB_OUTPUT"
- name: Validate AWS secrets for AWS platform
if: inputs.build-platforms == 'aws'
run: |
if [[ -z "${{ secrets.aws-key-id }}" ]]; then
echo "Error: aws-key-id secret is required when build-platforms is 'aws'"
exit 1
fi
if [[ -z "${{ secrets.aws-secret-key }}" ]]; then
echo "Error: aws-secret-key secret is required when build-platforms is 'aws'"
exit 1
fi
if [[ -z "${{ secrets.function-admin-api-key }}" ]]; then
echo "Error: function-admin-api-key secret is required when build-platforms is 'aws'"
exit 1
fi
build-aws:
uses: ./.github/workflows/lambda_build.yml
if: inputs.build-platforms == 'aws'
needs: setup
strategy:
fail-fast: false
matrix:
environment: [staging, production]
with:
environment: ${{ matrix.environment }}
function-name: ${{ needs.setup.outputs.evaluation_function_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 }}
build-push: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) }}
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
build-secrets: ${{ secrets.build-secrets }}
deploy-staging-aws:
uses: ./.github/workflows/lambda_deploy.yml
if: inputs.build-platforms == 'aws' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch))
needs: [setup, build-aws]
with:
environment: staging
api-url: https://staging-api.lambdafeedback.com
image-name: ${{ needs.build-aws.outputs.registry }}/lambda-feedback-staging-functions-repository:${{ needs.setup.outputs.evaluation_function_name }}
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
region: ${{ needs.setup.outputs.region }}
secrets:
aws-key-id: ${{ secrets.aws-key-id }}
aws-secret-key: ${{ secrets.aws-secret-key }}
function-admin-api-key: ${{ secrets.function-admin-api-key }}
deploy-production-aws:
uses: ./.github/workflows/lambda_deploy.yml
if: inputs.build-platforms == 'aws' && (github.repository != inputs.template-repository-name && github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch))
needs: [setup, build-aws]
with:
environment: production
api-url: https://prod-api.lambdafeedback.com
image-name: ${{ needs.build-aws.outputs.registry }}/lambda-feedback-production-functions-repository:${{ needs.setup.outputs.evaluation_function_name }}
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
region: ${{ needs.setup.outputs.region }}
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-gcp:
uses: ./.github/workflows/gcp_build.yml
if: inputs.build-platforms == 'gcp'
needs: setup
strategy:
fail-fast: false
matrix:
environment: [staging, production]
with:
environment: ${{ matrix.environment }}
function-name: ${{ needs.setup.outputs.evaluation_function_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 }}
build-push: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) }}
secrets:
function-admin-api-key: ${{ secrets.function-admin-api-key }}
gcp_credentials: ${{ secrets.gcp_credentials }}
deploy-gcp-staging:
uses: ./.github/workflows/gcp_deploy.yml
if: inputs.build-platforms == 'gcp' && github.repository != inputs.template-repository-name && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch))
needs: [setup, build-gcp]
with:
environment: staging
api-url: https://prod-api.lambdafeedback.com
repo: ${{ needs.setup.outputs.region }}-docker.pkg.dev/wolfram-evaluation-functions/evaluation-function-staging
image-name: ${{ needs.setup.outputs.evaluation_function_name }}
function-name: ${{ needs.setup.outputs.evaluation_function_name }}-staging
region: ${{ needs.setup.outputs.region }}
secrets:
function-admin-api-key: ${{ secrets.function-admin-api-key }}
gcp_credentials: ${{ secrets.gcp_credentials }}
deploy-gcp-production:
uses: ./.github/workflows/gcp_deploy.yml
if: inputs.build-platforms == 'gcp' && github.repository != inputs.template-repository-name && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch))
needs: [setup, build-gcp]
with:
environment: production
api-url: https://prod-api.lambdafeedback.com
repo: ${{ needs.setup.outputs.region }}-docker.pkg.dev/wolfram-evaluation-functions/evaluation-function
image-name: ${{ needs.setup.outputs.evaluation_function_name }}
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
region: ${{ needs.setup.outputs.region }}
secrets:
function-admin-api-key: ${{ secrets.function-admin-api-key }}
gcp_credentials: ${{ secrets.gcp_credentials }}