-
Notifications
You must be signed in to change notification settings - Fork 3
334 lines (283 loc) · 12.2 KB
/
pipeline.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
---
# https://docs.github.com/en/actions/quickstart
# hhttps://github.com/marketplace/actions/build-and-publish-docker-image-to-github-container-registry
name: "GIB - Golden Image Builder"
on: # yamllint disable-line rule:truthy
push: # yamllint disable-line rule:empty-values
env:
TF_CLOUD_ORGANIZATION: "nolan"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "golden-image-builder"
CONFIG_DIRECTORY: "./"
jobs:
build-and-publish-latest:
if: |
always() &&
contains(github.event.pull_request.labels.*.name, 'rebuild container image') &&
(github.ref != 'refs/heads/main' || github.ref != 'refs/heads/master')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# https://github.com/docker/setup-qemu-action
# https://blog.thesparktree.com/docker-multi-arch-github-actions
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,amd64'
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# https://github.com/marketplace/actions/docker-build-push-action
- uses: mr-smithers-excellent/docker-build-push@v6
name: Build and Push Docker image
with:
image: golden-image-builder-container
tags: latest
registry: ghcr.io
multiPlatform: true
platform: linux/amd64,linux/arm64
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
run-run-dot-sh:
needs: build-and-publish-latest
if: |
always() &&
(github.ref != 'refs/heads/main' || github.ref != 'refs/heads/master') &&
(needs.build-and-publish-latest.result == 'success' || needs.build-and-publish-latest.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
- uses: actions/checkout@v3
- name: Packer version
run: packer -v
- name: Ansible version
run: ansible --version
- name: Terraform version
run: terraform -v
- name: Copy /home/ubuntu/.tflint.d to /github/home/
run: cp -r /home/ubuntu/.tflint.d /github/home/
- name: Install Pre Commit
run: python3 -m pip install --no-cache-dir --quiet --upgrade --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org git+https://github.com/pre-commit/[email protected]
- name: cd GITHUB_WORKSPACE
run: cd $GITHUB_WORKSPACE
- name: Run
run: ./run.sh
azure-image-gallery:
needs: run-run-dot-sh
if: |
always() &&
(needs.run-run-dot-sh.result == 'success' || needs.run-run-dot-sh.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
- uses: actions/checkout@v3
- name: Terraform version
run: terraform -v
- name: Terraform init
run: terraform init -upgrade
working-directory: ./terraform/azure-shared-image-gallery
- name: Terraform plan
run: terraform plan
working-directory: ./terraform/azure-shared-image-gallery
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}
azure-image-gallery-on-tfc:
needs: run-run-dot-sh
if: |
always() &&
(needs.run-run-dot-sh.result == 'success' || needs.run-run-dot-sh.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
- uses: actions/checkout@v3
- name: Terraform version
run: terraform -v
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-upload
if: |
env.GITHUB_TOKEN == true
with:
workspace: 'azure-image-gallery'
directory: './terraform/azure-shared-image-gallery'
speculative: true
- name: Create Plan Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-run
if: |
env.GITHUB_TOKEN == true
with:
workspace: 'azure-image-gallery'
directory: './terraform/azure-shared-image-gallery'
configuration_version: ${{ steps.plan-upload.outputs.configuration_version_id }}
plan_only: true
- name: Get Plan Output
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-output
if: |
env.GITHUB_TOKEN == true
with:
workspace: 'azure-image-gallery'
directory: './terraform/azure-shared-image-gallery'
plan: ${{ fromJSON(steps.plan-run.outputs.payload).data.relationships.plan.data.id }}
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: upload
with:
workspace: 'azure-image-gallery'
directory: "./terraform/azure-shared-image-gallery"
- name: Create Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: create-run
with:
workspace: 'azure-image-gallery'
configuration_version: ${{ steps.upload.outputs.configuration_version_id }}
- name: Apply Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
# assign id attribute to reference in subsequent steps
id: apply
with:
run: ${{ steps.create-run.outputs.run_id }}
comment: "Confirmed from GitHub Actions CI"
awx-ansible-tower:
needs: azure-image-gallery
if: |
always() &&
(needs.run-run-dot-sh.result == 'success' || needs.run-run-dot-sh.result == 'skipped') &&
(needs.azure-image-gallery.result == 'success' || needs.azure-image-gallery.result == 'skipped' || needs.azure-image-gallery-on-tfc.result == 'success' || needs.azure-image-gallery-on-tfc.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
- uses: actions/checkout@v3
- name: Terraform version
run: terraform -v
- name: Terraform init
run: terraform init -upgrade
working-directory: ./terraform/awx-ansible-tower-instance
- name: Terraform plan
run: terraform plan
working-directory: ./terraform/awx-ansible-tower-instance
env:
TF_VAR_ssh_public_key: ${{ vars.TF_VAR_SSH_PUBLIC_KEY }}
TF_VAR_ssh_private_key: ${{ vars.TF_VAR_SSH_PRIVATE_KEY }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}
awx-ansible-tower-on-tfc:
needs: azure-image-gallery-on-tfc
if: |
always() &&
(needs.run-run-dot-sh.result == 'success' || needs.run-run-dot-sh.result == 'skipped') &&
(needs.azure-image-gallery.result == 'success' || needs.azure-image-gallery.result == 'skipped' || needs.azure-image-gallery-on-tfc.result == 'success' || needs.azure-image-gallery-on-tfc.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
- uses: actions/checkout@v3
- name: Terraform version
run: terraform -v
- name: Terraform auto tfvars
run: |
echo "ssh_private_key = \"${{ secrets.TF_VAR_SSH_PRIVATE_KEY }}\"" >> terraform.auto.tfvars
echo "ssh_public_key = <<EOF\n${{ vars.TF_VAR_SSH_PUBLIC_KEY }}\nEOF" >> terraform.auto.tfvars
ls -la
cat terraform.auto.tfvars
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-upload
with:
workspace: "awx-ansible-tower"
directory: "./terraform/awx-ansible-tower-instance"
speculative: true
- name: Create Plan Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-run
with:
workspace: "awx-ansible-tower"
configuration_version: ${{ steps.plan-upload.outputs.configuration_version_id }}
plan_only: true
# env:
# TF_VAR_ssh_public_key: "${{ vars.TF_VAR_SSH_PUBLIC_KEY }}"
# TF_VAR_ssh_private_key: "${{ secrets.TF_VAR_SSH_RIVATE_KEY }}"
- name: Get Plan Output
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: plan-output
with:
plan: ${{ fromJSON(steps.plan-run.outputs.payload).data.relationships.plan.data.id }}
- name: Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: upload
with:
workspace: "awx-ansible-tower"
directory: "./terraform/awx-ansible-tower-instance"
- name: Create Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: create-run
with:
workspace: "awx-ansible-tower"
configuration_version: ${{ steps.upload.outputs.configuration_version_id }}
- name: Apply Run
uses: hashicorp/tfc-workflows-github/actions/[email protected]
id: apply
with:
run: ${{ steps.create-run.outputs.run_id }}
comment: "Confirmed from GitHub Actions CI"
packer-build:
needs: azure-image-gallery
if: |
always() &&
(needs.run-run-dot-sh.result == 'success' || needs.run-run-dot-sh.result == 'skipped') &&
(needs.azure-image-gallery.result == 'success' || needs.azure-image-gallery.result == 'skipped' || needs.azure-image-gallery-on-tfc.result == 'success' || needs.azure-image-gallery-on-tfc.result == 'skipped')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/golden-image-builder-container:latest
options: --user 1001
steps:
# Checking out the repo
- uses: actions/checkout@v3
- name: Ansible version
run: ansible --version
- name: Ansible Galaxy install roles
run: ansible-galaxy install -f -r ansible/roles/requirements.yml -p ansible/roles/
- name: Packer version
run: packer -v
- name: Packer init
run: packer init -upgrade packer/all
- name: Packer build
# https://developer.hashicorp.com/packer/docs/templates/hcl_templates/onlyexcept
run: packer build -force -only='amazon-ebs.ubuntu-2204' packer/all
# run: packer build -force -except='vagrant.*' packer/all
# run: PACKER_LOG=1 packer build -debug -force -only='googlecompute.ubuntu-2204' packer/all
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}