Skip to content

Commit d38e4b5

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

File tree

2 files changed

+118
-37
lines changed

2 files changed

+118
-37
lines changed

.github/workflows/test.yml

+98-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,50 @@ 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: build-deps | ${{ 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: "Enable containerd to be able to use gha cache"
49+
run: |
50+
sudo mkdir -p /etc/docker
51+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
52+
sudo systemctl restart docker
53+
- name: "Build dependencies for the integration test environment image"
54+
run: |
55+
docker build \
56+
--cache-to type=gha,mode=max,scope=${ARCH}-${CONTAINERD_VERSION} \
57+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
58+
--target build-dependencies --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
59+
1860
test-unit:
61+
# FIXME:
1962
# 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
2063
# Apparently does not
2164
# timeout-minutes: ${{ fromJSON(env.SHORT_TIMEOUT) }}
@@ -56,7 +99,7 @@ jobs:
5699
run: make test-unit
57100

58101
test-integration:
59-
timeout-minutes: 60
102+
timeout-minutes: 30
60103
name: rootful | ${{ matrix.containerd }} | ${{ matrix.runner }}
61104
runs-on: "${{ matrix.runner }}"
62105
strategy:
@@ -67,24 +110,39 @@ jobs:
67110
- ubuntu: 20.04
68111
containerd: v1.6.36
69112
runner: "ubuntu-20.04"
113+
arch: amd64
70114
- ubuntu: 22.04
71115
containerd: v1.7.23
72116
runner: "ubuntu-22.04"
117+
arch: amd64
73118
- ubuntu: 24.04
74119
containerd: v2.0.0-rc.5
75120
runner: "ubuntu-24.04"
121+
arch: amd64
76122
- ubuntu: 24.04
77123
containerd: v2.0.0-rc.5
78124
runner: github-arm64-2c-8gb
125+
arch: arm64
79126
env:
80-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
81127
CONTAINERD_VERSION: "${{ matrix.containerd }}"
128+
ARCH: "${{ matrix.arch }}"
129+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
82130
steps:
83131
- uses: actions/[email protected]
84132
with:
85133
fetch-depth: 1
134+
- name: "Expose GitHub Runtime variables for gha"
135+
uses: crazy-max/ghaction-github-runtime@v3
136+
- name: "Enable containerd to be able to use gha cache"
137+
run: |
138+
sudo mkdir -p /etc/docker
139+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
140+
sudo systemctl restart docker
86141
- 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} .
142+
run: |
143+
docker build \
144+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
145+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
88146
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
89147
run: |
90148
sudo systemctl disable --now snapd.service snapd.socket
@@ -106,19 +164,21 @@ jobs:
106164
run: docker run -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true
107165

108166
test-integration-ipv6:
109-
timeout-minutes: 60
167+
timeout-minutes: 10
110168
name: ipv6 | ${{ matrix.containerd }} | ${{ matrix.ubuntu }}
111169
runs-on: "ubuntu-${{ matrix.ubuntu }}"
112170
strategy:
113171
fail-fast: false
114172
matrix:
115-
# ubuntu-20.04: cgroup v1, ubuntu-22.04 and later: cgroup v2
116173
include:
117174
- ubuntu: 24.04
118175
containerd: v2.0.0-rc.5
176+
arch: amd64
119177
env:
120-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
121178
CONTAINERD_VERSION: "${{ matrix.containerd }}"
179+
ARCH: "${{ matrix.arch }}"
180+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
181+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
122182
steps:
123183
- uses: actions/[email protected]
124184
with:
@@ -127,13 +187,18 @@ jobs:
127187
run: |
128188
sudo sysctl -w net.ipv6.conf.all.forwarding=1
129189
sudo sysctl -w net.ipv4.ip_forward=1
130-
- name: Enable IPv6 for Docker
190+
- name: "Expose GitHub Runtime variables for gha"
191+
uses: crazy-max/ghaction-github-runtime@v3
192+
- name: Enable IPv6 for Docker, and configure docker to use containerd for gha
131193
run: |
132194
sudo mkdir -p /etc/docker
133-
echo '{"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
195+
echo '{"features": {"containerd-snapshotter": true}, "ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
134196
sudo systemctl restart docker
135197
- 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} .
198+
run: |
199+
docker build \
200+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
201+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
137202
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
138203
run: |
139204
sudo systemctl disable --now snapd.service snapd.socket
@@ -158,7 +223,8 @@ jobs:
158223
run: docker run --network host -t --rm --privileged test-integration ./hack/test-integration.sh -test.only-ipv6
159224

160225
test-integration-rootless:
161-
timeout-minutes: 60
226+
needs: build-dependencies
227+
timeout-minutes: 30
162228
name: "${{ matrix.target }} | ${{ matrix.containerd }} | ${{ matrix.rootlesskit }} | ${{ matrix.ubuntu }}"
163229
runs-on: "ubuntu-${{ matrix.ubuntu }}"
164230
strategy:
@@ -170,21 +236,27 @@ jobs:
170236
containerd: v1.6.36
171237
rootlesskit: v1.1.1 # Deprecated
172238
target: rootless
239+
arch: amd64
173240
- ubuntu: 22.04
174241
containerd: v1.7.23
175242
rootlesskit: v2.3.1
176243
target: rootless
244+
arch: amd64
177245
- ubuntu: 24.04
178246
containerd: v2.0.0-rc.5
179247
rootlesskit: v2.3.1
180248
target: rootless
249+
arch: amd64
181250
- ubuntu: 24.04
182251
containerd: v1.7.23
183252
rootlesskit: v2.3.1
184253
target: rootless-port-slirp4netns
254+
arch: amd64
185255
env:
186-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
187256
CONTAINERD_VERSION: "${{ matrix.containerd }}"
257+
ARCH: "${{ matrix.arch }}"
258+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
259+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
188260
ROOTLESSKIT_VERSION: "${{ matrix.rootlesskit }}"
189261
TEST_TARGET: "test-integration-${{ matrix.target }}"
190262
steps:
@@ -215,8 +287,18 @@ jobs:
215287
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
216288
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
217289
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
290+
- name: "Expose GitHub Runtime variables for gha"
291+
uses: crazy-max/ghaction-github-runtime@v3
292+
- name: "Enable containerd to be able to use gha cache"
293+
run: |
294+
sudo mkdir -p /etc/docker
295+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
296+
sudo systemctl restart docker
218297
- 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} .
298+
run: |
299+
docker build \
300+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
301+
-t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
220302
- name: "Disable BuildKit for RootlessKit v1 (workaround for issue #622)"
221303
run: |
222304
# https://github.com/containerd/nerdctl/issues/622
@@ -250,7 +332,7 @@ jobs:
250332
run: GO_VERSION="$(echo ${{ matrix.go-version }} | sed -e s/.x//)" make binaries
251333

252334
test-integration-docker-compatibility:
253-
timeout-minutes: 60
335+
timeout-minutes: 30
254336
name: docker
255337
runs-on: ubuntu-24.04
256338
steps:
@@ -262,11 +344,6 @@ jobs:
262344
go-version: ${{ env.GO_VERSION }}
263345
cache: true
264346
check-latest: true
265-
- name: "Print docker info"
266-
run: |
267-
set -eux -o pipefail
268-
docker info
269-
docker version
270347
- name: "Register QEMU (tonistiigi/binfmt)"
271348
run: |
272349
# `--install all` will only install emulation for architectures that cannot be natively executed
@@ -324,13 +401,14 @@ jobs:
324401
run: ./hack/test-integration.sh -test.only-flaky=true
325402

326403
test-integration-freebsd:
327-
timeout-minutes: 60
404+
timeout-minutes: 30
328405
name: FreeBSD
329406
# ubuntu-24.04 lacks the vagrant package
330407
runs-on: ubuntu-22.04
331-
332408
steps:
333409
- uses: actions/[email protected]
410+
with:
411+
fetch-depth: 1
334412
- uses: actions/cache@v4
335413
with:
336414
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)