Skip to content

Commit 3b1d250

Browse files
committed
Enable GHA cache for image build dependencies
Signed-off-by: apostasie <[email protected]>
1 parent 49a19ed commit 3b1d250

File tree

2 files changed

+113
-37
lines changed

2 files changed

+113
-37
lines changed

.github/workflows/test.yml

+93-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,47 @@ env:
1515
LONG_TIMEOUT: 60
1616

1717
jobs:
18+
# This job builds the dependency target of the test docker image for all supported architectures and cache it in GHA
19+
build-dependencies:
20+
timeout-minutes: 10
21+
name: dependencies | ${{ matrix.containerd }} | ${{ matrix.arch }}
22+
runs-on: "${{ matrix.runner }}"
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- runner: ubuntu-24.04
28+
containerd: v1.6.36
29+
arch: amd64
30+
- runner: ubuntu-24.04
31+
containerd: v1.7.23
32+
arch: amd64
33+
- runner: ubuntu-24.04
34+
containerd: v2.0.0-rc.5
35+
arch: amd64
36+
- runner: arm64-8core-32gb
37+
containerd: v2.0.0-rc.5
38+
arch: arm64
39+
env:
40+
CONTAINERD_VERSION: "${{ matrix.containerd }}"
41+
ARCH: "${{ matrix.arch }}"
42+
steps:
43+
- uses: actions/[email protected]
44+
with:
45+
fetch-depth: 1
46+
- name: "Expose GitHub Runtime variables for gha"
47+
uses: crazy-max/ghaction-github-runtime@v3
48+
- name: "Build dependencies for the integration test environment image"
49+
run: |
50+
docker buildx create --name with-gha --use
51+
docker buildx build \
52+
--output=type=docker \
53+
--cache-to type=gha,mode=max,scope=${ARCH}-${CONTAINERD_VERSION} \
54+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
55+
--target build-dependencies --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
56+
1857
test-unit:
58+
# FIXME:
1959
# Supposed to work: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#example-returning-a-json-data-type
2060
# Apparently does not
2161
# timeout-minutes: ${{ fromJSON(env.SHORT_TIMEOUT) }}
@@ -56,7 +96,8 @@ jobs:
5696
run: make test-unit
5797

5898
test-integration:
59-
timeout-minutes: 60
99+
needs: build-dependencies
100+
timeout-minutes: 30
60101
name: rootful | ${{ matrix.containerd }} | ${{ matrix.runner }}
61102
runs-on: "${{ matrix.runner }}"
62103
strategy:
@@ -67,24 +108,36 @@ jobs:
67108
- ubuntu: 20.04
68109
containerd: v1.6.36
69110
runner: "ubuntu-20.04"
111+
arch: amd64
70112
- ubuntu: 22.04
71113
containerd: v1.7.23
72114
runner: "ubuntu-22.04"
115+
arch: amd64
73116
- ubuntu: 24.04
74117
containerd: v2.0.0-rc.5
75118
runner: "ubuntu-24.04"
119+
arch: amd64
76120
- ubuntu: 24.04
77121
containerd: v2.0.0-rc.5
78-
runner: github-arm64-2c-8gb
122+
runner: arm64-8core-32gb
123+
arch: arm64
79124
env:
80-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
81125
CONTAINERD_VERSION: "${{ matrix.containerd }}"
126+
ARCH: "${{ matrix.arch }}"
127+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
82128
steps:
83129
- uses: actions/[email protected]
84130
with:
85131
fetch-depth: 1
132+
- name: "Expose GitHub Runtime variables for gha"
133+
uses: crazy-max/ghaction-github-runtime@v3
86134
- name: "Prepare integration test environment"
87-
run: docker build -t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
135+
run: |
136+
docker buildx create --name with-gha --use
137+
docker buildx build \
138+
--output=type=docker \
139+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
140+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
88141
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
89142
run: |
90143
sudo systemctl disable --now snapd.service snapd.socket
@@ -106,19 +159,22 @@ jobs:
106159
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true
107160

108161
test-integration-ipv6:
109-
timeout-minutes: 60
162+
needs: build-dependencies
163+
timeout-minutes: 10
110164
name: ipv6 | ${{ matrix.containerd }} | ${{ matrix.ubuntu }}
111165
runs-on: "ubuntu-${{ matrix.ubuntu }}"
112166
strategy:
113167
fail-fast: false
114168
matrix:
115-
# ubuntu-20.04: cgroup v1, ubuntu-22.04 and later: cgroup v2
116169
include:
117170
- ubuntu: 24.04
118171
containerd: v2.0.0-rc.5
172+
arch: amd64
119173
env:
120-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
121174
CONTAINERD_VERSION: "${{ matrix.containerd }}"
175+
ARCH: "${{ matrix.arch }}"
176+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
177+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
122178
steps:
123179
- uses: actions/[email protected]
124180
with:
@@ -127,13 +183,20 @@ jobs:
127183
run: |
128184
sudo sysctl -w net.ipv6.conf.all.forwarding=1
129185
sudo sysctl -w net.ipv4.ip_forward=1
130-
- name: Enable IPv6 for Docker
186+
- name: "Expose GitHub Runtime variables for gha"
187+
uses: crazy-max/ghaction-github-runtime@v3
188+
- name: Enable IPv6 for Docker, and configure docker to use containerd for gha
131189
run: |
132190
sudo mkdir -p /etc/docker
133191
echo '{"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
134192
sudo systemctl restart docker
135193
- name: "Prepare integration test environment"
136-
run: docker build -t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
194+
run: |
195+
docker buildx create --name with-gha --use
196+
docker buildx build \
197+
--output=type=docker \
198+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
199+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
137200
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
138201
run: |
139202
sudo systemctl disable --now snapd.service snapd.socket
@@ -158,7 +221,8 @@ jobs:
158221
run: docker run --network host -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-ipv6
159222

160223
test-integration-rootless:
161-
timeout-minutes: 60
224+
needs: build-dependencies
225+
timeout-minutes: 30
162226
name: "${{ matrix.target }} | ${{ matrix.containerd }} | ${{ matrix.rootlesskit }} | ${{ matrix.ubuntu }}"
163227
runs-on: "ubuntu-${{ matrix.ubuntu }}"
164228
strategy:
@@ -170,21 +234,27 @@ jobs:
170234
containerd: v1.6.36
171235
rootlesskit: v1.1.1 # Deprecated
172236
target: rootless
237+
arch: amd64
173238
- ubuntu: 22.04
174239
containerd: v1.7.23
175240
rootlesskit: v2.3.1
176241
target: rootless
242+
arch: amd64
177243
- ubuntu: 24.04
178244
containerd: v2.0.0-rc.5
179245
rootlesskit: v2.3.1
180246
target: rootless
247+
arch: amd64
181248
- ubuntu: 24.04
182249
containerd: v1.7.23
183250
rootlesskit: v2.3.1
184251
target: rootless-port-slirp4netns
252+
arch: amd64
185253
env:
186-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
187254
CONTAINERD_VERSION: "${{ matrix.containerd }}"
255+
ARCH: "${{ matrix.arch }}"
256+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
257+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
188258
ROOTLESSKIT_VERSION: "${{ matrix.rootlesskit }}"
189259
TEST_TARGET: "test-integration-${{ matrix.target }}"
190260
steps:
@@ -215,8 +285,15 @@ jobs:
215285
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
216286
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
217287
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
288+
- name: "Expose GitHub Runtime variables for gha"
289+
uses: crazy-max/ghaction-github-runtime@v3
218290
- name: "Prepare (network driver=slirp4netns, port driver=builtin)"
219-
run: docker build -t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
291+
run: |
292+
docker buildx create --name with-gha --use
293+
docker buildx build \
294+
--output=type=docker \
295+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
296+
-t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
220297
- name: "Disable BuildKit for RootlessKit v1 (workaround for issue #622)"
221298
run: |
222299
# https://github.com/containerd/nerdctl/issues/622
@@ -250,7 +327,7 @@ jobs:
250327
run: GO_VERSION="$(echo ${{ matrix.go-version }} | sed -e s/.x//)" make binaries
251328

252329
test-integration-docker-compatibility:
253-
timeout-minutes: 60
330+
timeout-minutes: 30
254331
name: docker
255332
runs-on: ubuntu-24.04
256333
steps:
@@ -262,11 +339,6 @@ jobs:
262339
go-version: ${{ env.GO_VERSION }}
263340
cache: true
264341
check-latest: true
265-
- name: "Print docker info"
266-
run: |
267-
set -eux -o pipefail
268-
docker info
269-
docker version
270342
- name: "Register QEMU (tonistiigi/binfmt)"
271343
run: |
272344
# `--install all` will only install emulation for architectures that cannot be natively executed
@@ -324,13 +396,14 @@ jobs:
324396
run: ./hack/test-integration.sh -test.only-flaky=true
325397

326398
test-integration-freebsd:
327-
timeout-minutes: 60
399+
timeout-minutes: 30
328400
name: FreeBSD
329401
# ubuntu-24.04 lacks the vagrant package
330402
runs-on: ubuntu-22.04
331-
332403
steps:
333404
- uses: actions/[email protected]
405+
with:
406+
fetch-depth: 1
334407
- uses: actions/cache@v4
335408
with:
336409
path: /root/.vagrant.d

Dockerfile

+20-17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ RUN xx-apt-get update -qq && xx-apt-get install -qq --no-install-recommends \
6969
libbtrfs-dev \
7070
libseccomp-dev \
7171
pkg-config
72+
RUN git config --global advice.detachedHead false
7273

7374
FROM build-base-debian AS build-containerd
7475
ARG TARGETARCH
@@ -117,25 +118,19 @@ RUN xx-go --wrap && \
117118

118119
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build-base
119120
RUN apk add --no-cache make git curl
120-
COPY . /go/src/github.com/containerd/nerdctl
121-
WORKDIR /go/src/github.com/containerd/nerdctl
121+
RUN git config --global advice.detachedHead false
122122

123123
FROM build-base AS build-minimal
124124
RUN BINDIR=/out/bin make binaries install
125125
# We do not set CMD to `go test` here, because it requires systemd
126126

127-
FROM build-base AS build-full
127+
FROM build-base AS build-dependencies
128128
ARG TARGETARCH
129129
ENV GOARCH=${TARGETARCH}
130-
RUN BINDIR=/out/bin make binaries install
131-
WORKDIR /nowhere
132130
COPY ./Dockerfile.d/SHA256SUMS.d/ /SHA256SUMS.d
133-
COPY README.md /out/share/doc/nerdctl/
134-
COPY docs /out/share/doc/nerdctl/docs
131+
WORKDIR /nowhere
135132
RUN echo "${TARGETARCH:-amd64}" | sed -e s/amd64/x86_64/ -e s/arm64/aarch64/ | tee /target_uname_m
136-
RUN mkdir -p /out/share/doc/nerdctl-full && \
137-
echo "# nerdctl (full distribution)" > /out/share/doc/nerdctl-full/README.md && \
138-
echo "- nerdctl: $(cd /go/src/github.com/containerd/nerdctl && git describe --tags)" >> /out/share/doc/nerdctl-full/README.md
133+
RUN mkdir -p /out/share/doc/nerdctl-full && touch /out/share/doc/nerdctl-full/README.md
139134
ARG CONTAINERD_VERSION
140135
COPY --from=build-containerd /out/${TARGETARCH:-amd64}/* /out/bin/
141136
COPY --from=build-containerd /out/containerd.service /out/lib/systemd/system/containerd.service
@@ -181,13 +176,6 @@ RUN git clone https://github.com/containerd/imgcrypt.git /go/src/github.com/cont
181176
git checkout "${IMGCRYPT_VERSION}" && \
182177
CGO_ENABLED=0 make && DESTDIR=/out make install && \
183178
echo "- imgcrypt: ${IMGCRYPT_VERSION}" >> /out/share/doc/nerdctl-full/README.md
184-
ARG ROOTLESSKIT_VERSION
185-
RUN fname="rootlesskit-$(cat /target_uname_m).tar.gz" && \
186-
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/rootless-containers/rootlesskit/releases/download/${ROOTLESSKIT_VERSION}/${fname}" && \
187-
grep "${fname}" "/SHA256SUMS.d/rootlesskit-${ROOTLESSKIT_VERSION}" | sha256sum -c && \
188-
tar xzf "${fname}" -C /out/bin && \
189-
rm -f "${fname}" /out/bin/rootlesskit-docker-proxy && \
190-
echo "- RootlessKit: ${ROOTLESSKIT_VERSION}" >> /out/share/doc/nerdctl-full/README.md
191179
ARG SLIRP4NETNS_VERSION
192180
RUN fname="slirp4netns-$(cat /target_uname_m)" && \
193181
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/rootless-containers/slirp4netns/releases/download/${SLIRP4NETNS_VERSION}/${fname}" && \
@@ -225,6 +213,13 @@ RUN fname="buildg-${BUILDG_VERSION}-${TARGETOS:-linux}-${TARGETARCH:-amd64}.tar.
225213
tar xzf "${fname}" -C /out/bin && \
226214
rm -f "${fname}" && \
227215
echo "- buildg: ${BUILDG_VERSION}" >> /out/share/doc/nerdctl-full/README.md
216+
ARG ROOTLESSKIT_VERSION
217+
RUN fname="rootlesskit-$(cat /target_uname_m).tar.gz" && \
218+
curl -o "${fname}" -fsSL --proto '=https' --tlsv1.2 "https://github.com/rootless-containers/rootlesskit/releases/download/${ROOTLESSKIT_VERSION}/${fname}" && \
219+
grep "${fname}" "/SHA256SUMS.d/rootlesskit-${ROOTLESSKIT_VERSION}" | sha256sum -c && \
220+
tar xzf "${fname}" -C /out/bin && \
221+
rm -f "${fname}" /out/bin/rootlesskit-docker-proxy && \
222+
echo "- RootlessKit: ${ROOTLESSKIT_VERSION}" >> /out/share/doc/nerdctl-full/README.md
228223

229224
RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
230225
echo "## License" >> /out/share/doc/nerdctl-full/README.md && \
@@ -237,6 +232,14 @@ RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
237232
mv /tmp/SHA256SUMS /out/share/doc/nerdctl-full/SHA256SUMS && \
238233
chown -R 0:0 /out
239234

235+
FROM build-dependencies AS build-full
236+
COPY . /go/src/github.com/containerd/nerdctl
237+
RUN { echo "# nerdctl (full distribution)"; echo "- nerdctl: $(cd /go/src/github.com/containerd/nerdctl && git describe --tags)"; cat /out/share/doc/nerdctl-full/README.md; } > /out/share/doc/nerdctl-full/README.md.new; mv /out/share/doc/nerdctl-full/README.md.new /out/share/doc/nerdctl-full/README.md
238+
WORKDIR /go/src/github.com/containerd/nerdctl
239+
RUN BINDIR=/out/bin make binaries install
240+
COPY README.md /out/share/doc/nerdctl/
241+
COPY docs /out/share/doc/nerdctl/docs
242+
240243
FROM scratch AS out-full
241244
COPY --from=build-full /out /
242245

0 commit comments

Comments
 (0)