-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (132 loc) · 4.97 KB
/
pkr-base-nomadpack.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
name: Build Base Images - Nomad Pack
on:
workflow_dispatch:
inputs:
singleBuild:
type: choice
description: image override
required: false
options:
- all
- rhel
- ubuntu
- windows
platform:
type: choice
description: platform override
required: false
options:
- all
- vsphere
- aws
- azure
env:
DEFAULT_IMAGES: windows, rhel, ubuntu
DEFAULT_PLATFORMS: aws, azure, vsphere
LAYER: base-images
BUILDPATH: packer/builds/image-factory
#Datadog Environment Variables
DD_API_KEY: ${{ secrets.DD_API_KEY }}
#HCP Environment Variables
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID}}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET}}
HCP_PROJECT_ID: ${{ secrets.HCP_PROJECT_ID}}
#vSphere Environment Variables
VSPHERE_SERVER : ${{ secrets.VSPHERE_SERVER }}
VSPHERE_USER: ${{ secrets.VSPHERE_USER }}
VSPHERE_PASSWORD: ${{ secrets.VSPHERE_PASSWORD }}
#AWS Environment Variables
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2
#Azure Environment Variables
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 }}
jobs:
selectimages:
runs-on: "ubuntu-latest"
steps:
- uses: FraBle/[email protected]
- name: get-images
id: get-images
run: |
if [[ "${{ inputs.singleBuild }}" != "all" ]] && [[ -n "${{ github.event.inputs.singleBuild }}" ]] ; then
export IMAGES=$(echo ${{ inputs.singleBuild }} | jq -R '["\(.)"]')
echo "images_out"=$IMAGES""
echo "images_out"=$IMAGES"" >> $GITHUB_OUTPUT
else
export IMAGES=$(echo $DEFAULT_IMAGES | jq -R 'split(", ")')
echo "images_out"=$IMAGES""
echo "images_out"=$IMAGES"" >> $GITHUB_OUTPUT
fi
if [[ "${{ inputs.platform }}" != "all" ]] && [[ -n "${{ github.event.inputs.platform }}" ]] ; then
export PLATFORMS=$(echo ${{ inputs.platform }} | jq -R '["\(.)"]')
echo "platforms_out"=$PLATFORMS""
echo "platforms_out"=$PLATFORMS"" >> $GITHUB_OUTPUT
else
export PLATFORMS=$(echo $DEFAULT_PLATFORMS | jq -R 'split(", ")')
echo "platforms_out"=$PLATFORMS""
echo "platforms_out"=$PLATFORMS"" >> $GITHUB_OUTPUT
fi
outputs:
images: ${{ steps.get-images.outputs.images_out }}
platforms: ${{ steps.get-images.outputs.platforms_out }}
scale:
runs-on: [listener, "${{ matrix.platform}}"]
needs: [selectimages]
strategy:
fail-fast: false
matrix:
image: ${{fromJson(needs.selectimages.outputs.images)}}
platform: ${{fromJson(needs.selectimages.outputs.platforms)}}
steps:
- uses: FraBle/[email protected]
- name: Create Nomad Job
run: |
nomad-pack run /nomad-packs/github_actions_runner/. \
--name "${{ matrix.platform }}-${{ matrix.image }}-${{ github.run_id }}" \
--var=job_name="${{ matrix.platform }}-${{ matrix.image }}-${{ github.run_id }}"
build:
runs-on: ["${{ matrix.platform }}-${{ matrix.image }}-${{ github.run_id }}"]
needs: [selectimages,scale]
env:
HCP_PACKER_BUCKET: ${{matrix.platform}}-${{matrix.image}}
PLATFORM: ${{matrix.platform}}
strategy:
fail-fast: false
matrix:
image: ${{fromJson(needs.selectimages.outputs.images)}}
platform: ${{fromJson(needs.selectimages.outputs.platforms)}}
steps:
- uses: FraBle/[email protected]
- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
with:
version: latest
- name: Checkout code
uses: actions/[email protected]
- name: Image Builder
run: |
packer init -force -var-file=${BUILDPATH}/${LAYER}/${{matrix.image}}/variables/example.pkrvars.hcl ${BUILDPATH}/${LAYER}/${{matrix.image}}/.
packer build -force -var-file=${BUILDPATH}/${LAYER}/${{matrix.image}}/variables/example.pkrvars.hcl ${BUILDPATH}/${LAYER}/${{matrix.image}}/.
cleanup:
runs-on: [listener, "${{ matrix.platform}}"]
if: always()
needs: [selectimages,scale,build]
strategy:
fail-fast: false
matrix:
image: ${{fromJson(needs.selectimages.outputs.images)}}
platform: ${{fromJson(needs.selectimages.outputs.platforms)}}
steps:
- uses: FraBle/[email protected]
- name: Destroy Nomad Job
run: |
nomad-pack stop \
/nomad-packs/github_actions_runner/. \
--name "${{ matrix.platform }}-${{ matrix.image }}-${{ github.run_id }}" \
--var=job_name="${{ matrix.platform }}-${{ matrix.image }}-${{ github.run_id }}" \
--purge