-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (180 loc) · 6.67 KB
/
main.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
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
name: Main
on:
workflow_dispatch:
push:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Set extra GitHub environment variables
id: github-env-vars
uses: rlespinasse/github-slug-action@v4
- name: Checkout source
id: checkout-source
uses: actions/checkout@v4
- name: Setup Python
id: install-python
uses: actions/setup-python@v3
with:
python-version: 3.12
cache: pipenv
- name: Install pipenv
id: install-pipenv
shell: bash
run: python -m pip install --upgrade pipenv
- name: Install dependencies
id: install-python-deps
shell: bash
run: pipenv install --dev
- name: Assume build account AWS credentials
id: build-account-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::346402060170:role/GitHubActionsBuildRole
role-session-name: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ github.run_number }}-${{ github.job }}
role-duration-seconds: 3600 # 60 minutes; needs to be less than our current max duration
aws-region: us-east-1
- name: Install AWS SAM
uses: aws-actions/setup-sam@v2
# FIXME: We're only validating the top-level template and not the rest.
- name: Validate artifact
run: sam validate --lint
- name: Synethsize StackSet templates
run: |
for _f in $(find . -type f -name 'stackset.yaml'); do
_dir="$(dirname $_f)/" \
yq \
-i \
'(.. | select(has("localTemplateFile")) | .localTemplateFile) |= load_str(strenv(_dir) + .)' \
$_f;
done
- name: Build artifact
run: sam build --parallel --template template.yaml
- name: Upload SAM artifact
id: upload-sam
shell: bash
run: |
sam package \
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \
--region us-east-1 \
--output-template-file packaged-template.yaml
- name: 'Upload pipeline artifact'
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.GITHUB_REPOSITORY_SLUG }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.run_number }}-${{ github.sha }}
path: |
**/*
!.aws-sam/build
!**/.terraform/providers
!node_modules
!.git
if-no-files-found: error
retention-days: 30
deploy:
needs:
- build
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Set extra GitHub environment variables
id: github-env-vars
uses: rlespinasse/github-slug-action@v4
- name: Download artifact
id: download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.GITHUB_REPOSITORY_SLUG }}-${{ env.GITHUB_REF_SLUG_URL }}-${{ github.run_number }}-${{ github.sha }}
- name: Setup Python
id: install-python
uses: actions/setup-python@v3
with:
python-version: 3.12
cache: pipenv
- name: Install pipenv
id: install-pipenv
shell: bash
run: python -m pip install --upgrade pipenv
- name: Install dependencies
id: install-python-deps
shell: bash
run: pipenv install --dev
- name: Assume build account AWS credentials
id: build-account-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::346402060170:role/GitHubActionsBuildRole
role-session-name: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ github.run_number }}-${{ github.job }}
role-duration-seconds: 3600 # 60 minutes; needs to be less than our current max duration
aws-region: us-east-1
- name: Assume deploy account AWS credentials
id: deploy-account-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::349603509961:role/GitHubActionsCfnDeployRole
role-session-name: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ github.run_number }}-${{ github.job }}
role-duration-seconds: 3600 # 60 minutes; needs to be less than our current max duration
aws-region: us-east-1
role-chaining: true
- name: Install AWS SAM
uses: aws-actions/setup-sam@v2
- name: Process AWS Tags
id: processaws-tags
shell: bash
run: >-
AWS_CFN_TAGS=$(
cat cfn-tags.json |
jq -r '
to_entries |
map("\(.key)=\(.value|tostring)") |
. += [
"org:branch=${{ env.GITHUB_EVENT_REF_SLUG_URL }}",
"org:stackName=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
] |
join(" ")
'
) &&
echo "AWS_CFN_TAGS=--tags ${AWS_CFN_TAGS}">> $GITHUB_ENV
- name: Process AWS Cloudformation Parameters
id: process-aws-parameters
shell: bash
env:
GHA_SECRETS: ${{ tojson(secrets) }}
GHA_VARS: ${{ toJson(vars) }}
run: >-
AWS_CFN_PARAMS=$(
jq \
-n \
--argjson secrets "$GHA_SECRETS" \
--argjson vars "$GHA_VARS" \
-f cfn-parameters.json |
jq \
-r '
to_entries |
map("\(.key)=\(.value|tostring)") |
join(" ")
'
) &&
echo "AWS_CFN_PARAMS=--parameter-overrides ${AWS_CFN_PARAMS}" >> $GITHUB_ENV
- name: Deploy via SAM
id: deploy-sam
shell: bash
run: |
sam deploy \
--template-file packaged-template.yaml \
--stack-name ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }} \
--s3-bucket aws-sam-cli-sourcebucket-346402060170-us-east-1 \
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \
--region us-east-1 \
--role-arn arn:aws:iam::349603509961:role/CfnExecIamRole \
--on-failure DELETE \
$AWS_CFN_PARAMS \
$AWS_CFN_TAGS