-
Notifications
You must be signed in to change notification settings - Fork 18
325 lines (272 loc) · 10.6 KB
/
registry-publish.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
# This workflow will build a steampipe plugin image and publish it to Google Container Registry
#
# To configure this workflow:
#
# 1. Share the following secrets with your repository:
# - STEAMPIPE_REGISTRY_SA_KEY with the Base64 encoded JSON service account key (https://github.com/GoogleCloudPlatform/github-actions/tree/docs/service-account-key/setup-gcloud#inputs).
# 2. Change the values for the environment variables (below) if required.
name: Build and Deploy OCI Image
on:
push:
tags:
- 'v*'
env:
PROJECT_ID: steampipe
ORG: turbot
PLUGIN_REPO: us-docker.pkg.dev/steampipe/plugins
CONFIG_SCHEMA_VERSION: '2020-11-18'
ORAS_VERSION: '0.14.0'
jobs:
build:
name: Build
runs-on:
group: large-runners
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set environment variables
run: |
plugin_name=$(echo $GITHUB_REPOSITORY | cut -d'-' -f 3)
echo $plugin_name
echo "PLUGIN_NAME=${plugin_name}" >> $GITHUB_ENV
- name: Exit if goreleaser file is missing
run: |
test -f .goreleaser.yml
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Get latest version tag
run: |-
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Trim tag
run: |-
echo $VERSION
trim=${VERSION#"v"}
echo $trim
echo "VERSION=${trim}" >> $GITHUB_ENV
- name: Validate Version String
run: |-
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version OK: $VERSION"
else
echo "Invalid version: $VERSION"
exit 1
fi
- name: Ensure Version Does Not Exist
run: |-
URL=https://$(echo $PLUGIN_REPO | sed 's/\//\/v2\//')/$ORG/$PLUGIN_NAME/tags/list
IDX=$(curl -L $URL | jq ".tags | index(\"$VERSION\")")
if [ $IDX == "null" ]; then
echo "OK - Version does not exist: $VERSION"
else
echo "Version already exists: $VERSION"
exit 1
fi
- name: Increase swapfile
run: |
sudo swapoff -a
sudo fallocate -l 15G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --skip-publish --timeout=60m
- name: List Build Artifacts
run: ls -laR ./dist
- name: Save Linux Build Artifact - AMD64
uses: actions/upload-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_linux_amd64
path: ./dist/steampipe-plugin-${{ env.PLUGIN_NAME }}_linux_amd64.gz
if-no-files-found: error
- name: Save Linux Build Artifact - ARM64
uses: actions/upload-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_linux_arm64
path: ./dist/steampipe-plugin-${{ env.PLUGIN_NAME }}_linux_arm64.gz
if-no-files-found: error
- name: Save MacOS Build Artifact - AMD64
uses: actions/upload-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_darwin_amd64
path: ./dist/steampipe-plugin-${{ env.PLUGIN_NAME }}_darwin_amd64.gz
if-no-files-found: error
- name: Save MacOS Build Artifact - ARM64
uses: actions/upload-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_darwin_arm64
path: ./dist/steampipe-plugin-${{ env.PLUGIN_NAME }}_darwin_arm64.gz
if-no-files-found: error
publish-deploy:
name: Publish and Deploy
runs-on:
labels: ubuntu_4_core
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set environment variables
run: |
plugin_name=$(echo $GITHUB_REPOSITORY | cut -d'-' -f 3)
echo $plugin_name
echo "PLUGIN_NAME=${plugin_name}" >> $GITHUB_ENV
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.STEAMPIPE_REGISTRY_SA_KEY }}
project_id: ${{ env.PROJECT_ID }}
- run: gcloud config list
- run: gcloud components install beta
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud beta auth configure-docker us-docker.pkg.dev
# oras is pre-installed on the image, but we should install a specific version
# to protect against unexpected breaking changes
- run: |
curl -LO https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_amd64.tar.gz
sudo tar xzf oras_${ORAS_VERSION}_linux_amd64.tar.gz -C /usr/local/bin oras
oras version
- name: Download linux-amd64 artifact
uses: actions/download-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_linux_amd64
- name: Download linux_arm64 artifact
uses: actions/download-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_linux_arm64
- name: Download darwin_amd64 artifact
uses: actions/download-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_darwin_amd64
- name: Download darwin_arm64 artifact
uses: actions/download-artifact@v2
with:
name: steampipe-${{ env.PLUGIN_NAME }}_darwin_arm64
- name: List files
run: ls -l
- name: Get latest version tag
run: |-
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Trim tag
run: |-
echo $VERSION
trim=${VERSION#"v"}
echo $trim
echo "VERSION=${trim}" >> $GITHUB_ENV
- name: Validate Version String
run: |-
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version OK: $VERSION"
else
echo "Invalid version: $VERSION"
exit 1
fi
# create the config file
- run: |-
JSON_STRING=$( jq -n \
--arg name "$PLUGIN_NAME" \
--arg organization "$ORG" \
--arg version "$VERSION" \
--arg schemaVersion "$CONFIG_SCHEMA_VERSION" \
'{schemaVersion: $schemaVersion, plugin: { name: $name, organization: $organization, version: $version} }' )
echo $JSON_STRING > config.json
- run: cat config.json
# create the annotations file
- run: |-
JSON_STRING=$( jq -n \
--arg title "$PLUGIN_NAME" \
--arg desc "$ORG" \
--arg version "$VERSION" \
--arg timestamp "$(date +%FT%T%z)" \
--arg repo "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--arg commit "$GITHUB_SHA" \
--arg vendor "Turbot HQ, Inc." \
'{
"$manifest": {
"org.opencontainers.image.title": $title,
"org.opencontainers.image.description": $desc,
"org.opencontainers.image.version": $version,
"org.opencontainers.image.created": $timestamp,
"org.opencontainers.image.source": $repo,
"org.opencontainers.image.revision": $commit,
"org.opencontainers.image.vendor": $vendor
}
}' )
echo $JSON_STRING > annotations.json
- run: cat annotations.json
- run: cat README.md
# push to the registry
- run: |-
REF="$PLUGIN_REPO/$ORG/$PLUGIN_NAME:$GITHUB_RUN_ID"
oras push $REF \
--config config.json:application/vnd.turbot.steampipe.config.v1+json \
--annotation-file annotations.json \
steampipe-plugin-${PLUGIN_NAME}_darwin_amd64.gz:application/vnd.turbot.steampipe.plugin.darwin-amd64.layer.v1+gzip \
steampipe-plugin-${PLUGIN_NAME}_darwin_arm64.gz:application/vnd.turbot.steampipe.plugin.darwin-arm64.layer.v1+gzip \
steampipe-plugin-${PLUGIN_NAME}_linux_amd64.gz:application/vnd.turbot.steampipe.plugin.linux-amd64.layer.v1+gzip \
steampipe-plugin-${PLUGIN_NAME}_linux_arm64.gz:application/vnd.turbot.steampipe.plugin.linux-arm64.layer.v1+gzip \
docs:application/vnd.turbot.steampipe.plugin.docs.layer.v1+tar \
config:application/vnd.turbot.steampipe.plugin.spc.layer.v1+tar
tag-versions:
name: Set Version tags
runs-on:
labels: ubuntu_4_core
needs:
- publish-deploy
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set environment variables
run: |
plugin_name=$(echo $GITHUB_REPOSITORY | cut -d'-' -f 3)
echo $plugin_name
echo "PLUGIN_NAME=${plugin_name}" >> $GITHUB_ENV
# Setup gcloud CLI
- uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.STEAMPIPE_REGISTRY_SA_KEY }}
project_id: ${{ env.PROJECT_ID }}
- run: gcloud config list --quiet
- run: gcloud components install alpha --quiet
- name: Get latest version tag
run: |-
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Trim tag
run: |-
echo $VERSION
trim=${VERSION#"v"}
echo $trim
echo "VERSION=${trim}" >> $GITHUB_ENV
- name: Validate Version String
run: |-
if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version OK: $VERSION"
else
echo "Invalid version: $VERSION"
exit 1
fi
- name: Ensure Version Does Not Exist
run: |-
URL=https://$(echo $PLUGIN_REPO | sed 's/\//\/v2\//')/$ORG/$PLUGIN_NAME/tags/list
IDX=$(curl -L $URL | jq ".tags | index(\"$VERSION\")")
if [ $IDX == "null" ]; then
echo "OK - Version does not exist: $VERSION"
else
echo "Version already exists: $VERSION"
exit 1
fi
- name: Set version tags
uses: turbot/steampipe-workflows/.github/actions/semver-tags@main
id: semver
with:
image-to-tag: '${{ env.PLUGIN_REPO }}/${{ env.ORG }}/${{ env.PLUGIN_NAME }}:${{ github.run_id }}'
image-version: ${{ env.VERSION }}