-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (197 loc) · 8.05 KB
/
build-image.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: 'Image: Agent - duplocloud-docker'
on:
workflow_dispatch:
inputs:
image_version:
description: 'Set the image version'
required: false
default: 'dev' # default to dev version
only_partition:
description: 'Only build this partition'
required: false
default: 'all'
only_builders:
description: 'Only run these builders'
required: false
default: 'amazon-ebs.ubuntu-22,amazon-ebs.amazonlinux-2'
env:
git_user: duplo-bot
git_email: joe+github-bot@duplocloud.net
duplo_host: https://prod.duplocloud.net
duplo_token: "${{ secrets.PROD_DUPLO_TOKEN }}"
jobs:
build-commercial:
if: "${{ github.event.inputs.only_partition == 'all' || github.event.inputs.only_partition == 'commercial' }}"
# Needed for GCP (OIDC): Add "id-token" with the intended permissions.
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# GCP credentials
- name: Packer GCP Service Account
uses: google-github-actions/auth@v0
with:
workload_identity_provider: 'projects/17033121890/locations/global/workloadIdentityPools/duplo-githubactions/providers/duplo-githubactions'
service_account: 'packer@msp-duplocloud-01.iam.gserviceaccount.com'
# AWS credentials
- name: Packer AWS Role
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
aws-region: us-west-2
role-to-assume: arn:aws:iam::227120241369:role/packer-builder
role-session-name: github-duplocloud-linuxagent
role-duration-seconds: 3600
role-skip-session-tagging: true
# Build images
- name: Build VM Images
run: |
set -eu
# Install session manager.
curl -o session-manager-plugin.deb "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb"
sudo dpkg -i session-manager-plugin.deb
# Install packer.
curl -o packer.zip https://releases.hashicorp.com/packer/1.8.6/packer_1.8.6_linux_amd64.zip
mkdir -p /tmp/bin
sudo unzip -d /tmp/bin packer.zip
export PATH="/tmp/bin:$PATH"
# Validate the template.
packer validate -syntax-only ./packer
# Parse build options.
if [ "$ONLY_BUILDERS" = "all" ]; then
ONLY_BUILDERS=""
elif [ -n "$ONLY_BUILDERS" ]; then
ONLY_BUILDERS="-only=$ONLY_BUILDERS"
fi
# Build the images.
rm -f packer-manifest.json # always be clean
packer build $ONLY_BUILDERS \
-color=false -on-error=cleanup -parallel-builds=10 -timestamp-ui \
./packer
env:
ONLY_BUILDERS: "${{ github.event.inputs.only_builders }}"
PKR_VAR_image_version: "${{ github.event.inputs.image_version }}"
PKR_VAR_agent_git_ref: "${{ github.sha }}"
# Upload the image manifest
- name: Attach Manifest
uses: actions/upload-artifact@v3
with:
name: packer-manifest.json
path: packer-manifest.json
build-govcloud:
if: "${{ github.event.inputs.only_partition == 'all' || github.event.inputs.only_partition == 'govcloud' }}"
runs-on: ubuntu-latest
env:
duplo_host: https://qa-govcloud.duplocloud.net
duplo_token: "${{ secrets.GOVCLOUD_DUPLO_TOKEN }}"
steps:
- name: Checkout
uses: actions/checkout@v3
# AWS credentials
- name: Tenant AWS JIT
uses: duplocloud/ghactions-aws-jit@master
with:
tenant: github
# AWS credentials
- name: Packer AWS Role
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
aws-region: us-gov-west-1
role-to-assume: arn:aws-us-gov:iam::051848153245:role/packer-builder
role-session-name: github-duplocloud-linuxagent
role-chaining: true
role-duration-seconds: 3600
role-skip-session-tagging: true
# Build images
- name: Build VM Images
run: |
set -eu
# Install session manager.
curl -o session-manager-plugin.deb "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb"
sudo dpkg -i session-manager-plugin.deb
# Install packer.
curl -o packer.zip https://releases.hashicorp.com/packer/1.8.6/packer_1.8.6_linux_amd64.zip
mkdir -p /tmp/bin
sudo unzip -d /tmp/bin packer.zip
export PATH="/tmp/bin:$PATH"
# Validate the template.
packer validate -syntax-only ./packer
# Parse build options.
if [ "$ONLY_BUILDERS" = "all" ]; then
ONLY_BUILDERS="-only=amazon-ebs.ubuntu-20,amazon-ebs.ubuntu-22,amazon-ebs.amazonlinux-2"
elif [ -n "$ONLY_BUILDERS" ]; then
ONLY_BUILDERS="-only=$ONLY_BUILDERS"
fi
# Build the images.
rm -f *packer-manifest.json # always be clean
packer build $ONLY_BUILDERS \
-color=false -on-error=cleanup -parallel-builds=10 -timestamp-ui \
-var-file=packer/duplo-gov.json \
./packer
mv packer-manifest.json govcloud-packer-manifest.json
env:
ONLY_BUILDERS: "${{ github.event.inputs.only_builders }}"
PKR_VAR_image_version: "${{ github.event.inputs.image_version }}"
PKR_VAR_agent_git_ref: "${{ github.sha }}"
# Upload the image manifest
- name: Attach Manifest
uses: actions/upload-artifact@v3
with:
name: govcloud-packer-manifest.json
path: govcloud-packer-manifest.json
# If this is a release build, create a PR to update Duplo
autoupdate-duplo-images:
runs-on: ubuntu-latest
if: "${{ startsWith(github.event.inputs.image_version, 'release-') && github.event.inputs.only_partition == 'all' }}"
needs:
- build-commercial
steps:
# Get the code for the image JSON generation, and the code for Duplo master.
- name: Checkout duplo-infra
uses: actions/checkout@v3
- name: Checkout duplo (backend)
uses: actions/checkout@v3
with:
repository: duplocloud-internal/duplo
ref: master # always start from master
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
path: duplo-backend
# Download the image manifest
- name: Download Manifest (Commercial)
uses: actions/download-artifact@v3
with:
name: packer-manifest.json
path: packer
- name: Download Manifest (Govcloud)
uses: actions/download-artifact@v3
with:
name: govcloud-packer-manifest.json
path: packer
# Run the script to generate new image JSON.
- name: Update duplo images JSON
run: |
git config core.autocrlf false
cd packer
INPUT_FILES='packer-manifest.json govcloud-packer-manifest.json' DUPLO_SOURCE=../duplo-backend ./gen-native-images.sh
# Create a PR
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: '[duplo-bot] Update Duplo Docker AMI(s)'
branch: auto-update/duplo-docker-amis
base: master
add-paths: config/V1/BuiltInNativeImages.json
commit-message: '[duplo-bot] Update Duplo Docker AMI(s)'
body: 'Automated update of Duplo Docker AMI(s)'
committer: "${{ env.git_user }} <${{ env.git_email }}>"
delete-branch: true
path: duplo-backend
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}