-
Notifications
You must be signed in to change notification settings - Fork 8
226 lines (210 loc) · 8 KB
/
deploy-api-modules.yml
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
name: "Build and deploy API modules"
env:
AWS_REGION: eu-west-2
DEPLOYER_ROLE: arn:aws:iam::114407264696:role/deployers/github-actions-publish-to-s3-for-code-signing
SOURCE_BUCKET: di-auth-lambda-source-20220215170204376700000003
SIGNING_PROFILE: di_auth_lambda_signing_20220215170204371800000001
DESTINATION_BUCKET: di-auth-lambda-signed-20220215170204376200000002
GHA_ROLE: arn:aws:iam::761723964695:role/build-auth-deploy-pipeline-GitHubActionsRole-160U5ADTRKQ2O
ARTIFACT_BUCKET: build-auth-deploy-pipeli-githubartifactsourcebuck-1o4hcrnik6ayv
ARTIFACT_LOOKUP_TABLE: arn:aws:dynamodb:eu-west-2:114407264696:table/di-auth-production-artifact-lookup
JAVA_VERSION: 17
JAVA_DISTRIBUTION: corretto
on:
push:
branches:
- main
concurrency:
group: "build-and-deploy-api-modules"
cancel-in-progress: false
jobs:
set-up:
name: Set up environment
runs-on: ubuntu-latest
outputs:
aws_region: ${{ env.AWS_REGION }}
deployer_role: ${{ steps.secrets.outputs.DEPLOYER_ROLE }}
promotion_role: ${{ steps.secrets.outputs.PROMOTION_ROLE }}
source_bucket: ${{ steps.secrets.outputs.SOURCE_BUCKET }}
signing_profile: ${{ steps.secrets.outputs.SIGNING_PROFILE }}
destination_bucket: ${{ steps.secrets.outputs.DESTINATION_BUCKET }}
artifact_bucket: ${{ steps.secrets.outputs.ARTIFACT_BUCKET }}
artifact_lookup_table: ${{ steps.secrets.outputs.ARTIFACT_LOOKUP_TABLE }}
steps:
- id: secrets
run: |
{
echo "DEPLOYER_ROLE=${{ env.DEPLOYER_ROLE }}"
echo "SOURCE_BUCKET=${{ env.SOURCE_BUCKET }}"
echo "SIGNING_PROFILE=${{ env.SIGNING_PROFILE }}"
echo "DESTINATION_BUCKET=${{ env.DESTINATION_BUCKET }}"
echo "PROMOTION_ROLE=${{ env.GHA_ROLE }}"
echo "ARTIFACT_BUCKET=${{ env.ARTIFACT_BUCKET }}"
echo "ARTIFACT_LOOKUP_TABLE=${{ env.ARTIFACT_LOOKUP_TABLE }}"
} >> "$GITHUB_OUTPUT"
pr-data:
name: Get data for merged PR
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
data: ${{ steps.fetch-pr-metadata.outputs.escaped-json }}
steps:
- name: Fetch PR Metadata
uses: govuk-one-login/authentication-artifact-metadata-action@d0ea2b26de2edf3ba08e649f9f06e6300460f2f6
id: fetch-pr-metadata
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
shell: bash
build-cache:
name: Set up build cache
runs-on: ubuntu-latest
outputs:
java_version: ${{ env.JAVA_VERSION }}
java_distribution: ${{ env.JAVA_DISTRIBUTION }}
steps:
- name: Check out repository code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up JDK 17
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b #v4.5.0
with:
java-version: ${{ env.JAVA_VERSION}}
distribution: ${{ env.JAVA_DISTRIBUTION}}
- name: Set up Gradle
uses: gradle/actions/setup-gradle@cc4fc85e6b35bafd578d5ffbc76a5518407e1af0 # v4
with:
gradle-version: wrapper
cache-read-only: false
- name: Download dependencies for caching
run: ./gradlew --no-daemon --console=plain assemble
build:
name: Build modules
needs:
- set-up
- build-cache
strategy:
matrix:
module:
- account-management-api
- auth-external-api
- client-registry-api
- delivery-receipts-api
- doc-checking-app-api
- frontend-api
- interventions-api-stub
- ipv-api
- oidc-api
- test-services-api
- ticf-cri-stub
- utils
permissions:
id-token: write
contents: read
uses: ./.github/workflows/call_build-single-api-module.yml
with:
module_name: ${{ matrix.module }}
aws_region: ${{ needs.set-up.outputs.aws_region }}
aws_role: ${{ needs.set-up.outputs.deployer_role }}
source_bucket: ${{ needs.set-up.outputs.source_bucket }}
destination_bucket: ${{ needs.set-up.outputs.destination_bucket }}
signing_profile: ${{ needs.set-up.outputs.signing_profile }}
lookup_table: ${{ needs.set-up.outputs.artifact_lookup_table }}
java_version: ${{ needs.build-cache.outputs.java_version }}
java_distribution: ${{ needs.build-cache.outputs.java_distribution }}
create-promotion-artifact-shared:
name: Create Shared Promotion Artifact
needs: set-up
permissions:
id-token: write
contents: read
uses: ./.github/workflows/call_create-shared-promotion-artifact.yml
create-promotion-artifacts-simple-modules:
name: Create Promotion Artifact
needs:
- set-up
- build
strategy:
matrix:
include:
- module_name: account-management-api
terraform_directory_name: account-management
- module_name: auth-external-api
terraform_directory_name: auth-external-api
- module_name: delivery-receipts-api
terraform_directory_name: delivery-receipts
- module_name: interventions-api-stub
terraform_directory_name: interventions-api-stub
- module_name: test-services-api
terraform_directory_name: test-services
- module_name: ticf-cri-stub
terraform_directory_name: ticf-cri-stub
- module_name: utils
terraform_directory_name: utils
permissions:
id-token: write
contents: read
uses: ./.github/workflows/call_create-simple-module-promotion-artifact.yml
with:
module_name: ${{ matrix.module_name }}
terraform_directory_name: ${{ matrix.terraform_directory_name }}
create-promotion-artifact-oidc:
name: Create OIDC Promotion artifact
needs:
- set-up
- build
permissions:
id-token: write
contents: read
uses: ./.github/workflows/call_create-oidc-promotion-artifact.yml
with:
oidc_api_module_name: oidc-api
client_registry_api_module_name: client-registry-api
doc_checking_app_api_module_name: doc-checking-app-api
frontend_api_module_name: frontend-api
ipv_api_module_name: ipv-api
terraform_directory_name: oidc
gather-and-trigger-codepipeline:
name: Gather and trigger CodePipeline
needs:
- pr-data
- set-up
- create-promotion-artifact-shared
- create-promotion-artifacts-simple-modules
- create-promotion-artifact-oidc
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ needs.set-up.outputs.promotion_role }}
aws-region: ${{ needs.set-up.outputs.aws_region }}
- name: Download all promotion artifacts
id: download_promotion_artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
path: promotion-artifacts
pattern: promotion_artifact_*
merge-multiple: true
- name: Upload single promotion artifact to S3
working-directory: promotion-artifacts
env:
ARTIFACT_BUCKET: ${{ needs.set-up.outputs.artifact_bucket }}
run: |
echo "::group::Zip all promotion artifacts"
zip -r authentication-api.zip .
echo "::endgroup::"
echo "::group::Upload final artifact to S3"
OBJECT_VERSION="$(aws s3api put-object \
--bucket "${ARTIFACT_BUCKET}" \
--key authentication-api.zip \
--body authentication-api.zip \
--metadata ${{ needs.pr-data.outputs.data}} \
--query VersionId --output text)"
echo "::endgroup::"
echo "::notice title=Final artifact uploaded to S3::object: authentication-api.zip, version: $OBJECT_VERSION"