Repository navigation
205 lines (187 loc) · 8.82 KB
/
Copy pathdeploy.yml
File metadata and controls
205 lines (187 loc) · 8.82 KB
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
name: Deploy container
on:
push:
branches:
- main
permissions:
contents: read
packages: write
jobs:
matrix:
name: Generate build matrix
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
build_matrix: ${{ steps.generate.outputs.build_matrix }}
merge_matrix: ${{ steps.generate.outputs.merge_matrix }}
runner_tag: ${{ steps.versions.outputs.runner_tag }}
steps:
- uses: actions/checkout@v7
# The only place the Dockerfile is read: the build jobs take the VERSION
# build-arg from this job's outputs, and every image tag is computed here,
# per matrix entry.
- name: Extract versions from Dockerfile
id: versions
run: |
set -euo pipefail
RUNNER_TAG=$(grep -m1 '^ARG VERSION=' Dockerfile | cut -d= -f2)
RUNNER_VERSION=$(echo "$RUNNER_TAG" | cut -d- -f1)
COMPILE_SDK=$(grep -m1 '^ARG COMPILE_SDK=' Dockerfile | cut -d= -f2)
BUILD_TOOLS=$(grep -m1 '^ARG BUILD_TOOLS=' Dockerfile | cut -d= -f2)
NDK_VERSION=$(grep -m1 '^ARG NDK_VERSION=' Dockerfile | cut -d= -f2)
if [ -z "$RUNNER_TAG" ] || [ -z "$RUNNER_VERSION" ] || [ -z "$COMPILE_SDK" ] || [ -z "$BUILD_TOOLS" ] || [ -z "$NDK_VERSION" ]; then
echo "::error::Failed to extract versions from Dockerfile"
exit 1
fi
{
echo "runner_tag=${RUNNER_TAG}"
echo "runner_version=${RUNNER_VERSION}"
echo "compile_sdk=${COMPILE_SDK}"
echo "build_tools=${BUILD_TOOLS}"
echo "ndk_version=${NDK_VERSION}"
} >> "$GITHUB_OUTPUT"
- name: Generate matrices from matrix.json
id: generate
env:
RUNNER_VERSION: ${{ steps.versions.outputs.runner_version }}
COMPILE_SDK: ${{ steps.versions.outputs.compile_sdk }}
BUILD_TOOLS: ${{ steps.versions.outputs.build_tools }}
NDK_VERSION: ${{ steps.versions.outputs.ndk_version }}
run: |
set -euo pipefail
# Every JDK x Node pair is published as the `runner` target (variant
# "std"). The default pair is additionally published as `runner-ndk`
# (the image plus the NDK) and `runner-slim` (no Android SDK). Each
# variant has its own digests, cache scope and tags so they never mix
# with the standard image. The variant/platform/cache-scope table is
# shared with build.yml (.github/jq/matrix.jq); the tag rules are in
# .github/jq/tags.jq. A build entry carries the tag baked into the
# image, a merge entry the metadata-action `type=raw` lines of the
# manifest list.
ALL=$(jq -c -L .github/jq \
--arg runner_version "$RUNNER_VERSION" --arg compile_sdk "$COMPILE_SDK" \
--arg build_tools "$BUILD_TOOLS" --arg ndk_version "$NDK_VERSION" '
include "matrix"; include "tags";
{runner_version: $runner_version, compile_sdk: $compile_sdk,
build_tools: $build_tools, ndk_version: $ndk_version} as $v
| .default_jdk as $dj | .default_node as $dn
| [ .java_versions[] as $j | .node_versions[] as $n
| {java_version: $j, node_version: $n, variant: "std"} ] as $std
| ( $std
+ [ $std[] | select(.java_version == $dj and .node_version == $dn)
| (. + {variant: "ndk"}), (. + {variant: "slim"}) ] ) as $images
| { build: { include: [
$images[] as $i | ("amd64", "arm64") as $arch
| leg($i.java_version; $i.node_version; $i.variant; $arch)
+ {image_tag: ($i | image_tag($v))} ] },
merge: { include: [
$images[]
| . + {tags: (tags($v; $dj; $dn) | map("type=raw,value=" + .) | join("\n"))} ] } }' matrix.json)
echo "build_matrix=$(jq -c .build <<< "$ALL")" >> "$GITHUB_OUTPUT"
echo "merge_matrix=$(jq -c .merge <<< "$ALL")" >> "$GITHUB_OUTPUT"
build:
name: Build ${{ matrix.platform }} JDK ${{ matrix.java_version }} Node ${{ matrix.node_version }} (${{ matrix.variant }})
needs: matrix
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.build_matrix) }}
steps:
- uses: actions/checkout@v7
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
target: ${{ matrix.target }}
platforms: ${{ matrix.platform }}
# Layer cache in the GitHub Actions cache, one scope per platform
# (the ndk and slim variants keep their own scope and read the standard one).
cache-from: |
type=gha,scope=${{ matrix.arch }}
${{ matrix.cache_scope != matrix.arch && format('type=gha,scope={0}', matrix.cache_scope) || '' }}
cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }}
# Disable SLSA provenance: it wraps the image in a per-registry
# attestation index which produces unknown/unknown manifest entries
# and an extra attestation manifest per arch. Nothing in this
# pipeline consumes the provenance, and turning it off keeps the
# registry view to just amd64 + arm64.
provenance: false
# RUNNER_IMAGE_TAG is the fully pinned tag, which never changes meaning;
# the revision is the commit.
build-args: |
VERSION=${{ needs.matrix.outputs.runner_tag }}
JAVA_VERSION=${{ matrix.java_version }}
NODE_VERSION=${{ matrix.node_version }}
RUNNER_IMAGE_TAG=${{ matrix.image_tag }}
RUNNER_IMAGE_REVISION=${{ github.sha }}
# zstd layers pull and decompress faster on small hosts (Raspberry Pi) than gzip.
# force-compression recompresses cached/base layers too; oci-mediatypes is
# required for zstd. `imagetools create` below merges the per-arch OCI manifests.
outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/github-runner,push-by-digest=true,name-canonical=true,push=true,compression=zstd,compression-level=3,force-compression=true,oci-mediatypes=true
- name: Export digest
run: |
set -euo pipefail
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digests-${{ matrix.variant }}-jdk${{ matrix.java_version }}-node${{ matrix.node_version }}-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge JDK ${{ matrix.java_version }} Node ${{ matrix.node_version }} (${{ matrix.variant }})
needs: [matrix, build]
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.merge_matrix) }}
steps:
- name: Download digests
uses: actions/download-artifact@v8
with:
pattern: digests-${{ matrix.variant }}-jdk${{ matrix.java_version }}-node${{ matrix.node_version }}-*
merge-multiple: true
path: ${{ runner.temp }}/digests
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository_owner }}/github-runner
tags: ${{ matrix.tags }}
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/github-runner
run: |
set -euo pipefail
TAGS=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
# Source: one per arch, by digest, from the GHCR push in the build job.
SOURCES=$(printf "${IMAGE}@sha256:%s " *)
# TAGS and SOURCES are deliberately word-split into arguments.
# shellcheck disable=SC2086
docker buildx imagetools create $TAGS $SOURCES
for tag in $(jq -cr '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON"); do
docker buildx imagetools inspect "$tag"
done