Skip to content

Commit ed7df0b

Browse files
committed
GHA cache image build dependencies
Signed-off-by: apostasie <[email protected]>
1 parent 7e4f77d commit ed7df0b

File tree

2 files changed

+112
-25
lines changed

2 files changed

+112
-25
lines changed

.github/workflows/test.yml

+92-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,47 @@ env:
1313
GO_VERSION: 1.23.x
1414

1515
jobs:
16+
build-deps:
17+
runs-on: "${{ matrix.runner }}"
18+
timeout-minutes: 40
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
# ubuntu-20.04: cgroup v1, ubuntu-22.04 and later: cgroup v2
23+
include:
24+
- runner: ubuntu-24.04
25+
containerd: v1.6.36
26+
arch: amd64
27+
- runner: ubuntu-24.04
28+
containerd: v1.7.23
29+
arch: amd64
30+
- runner: ubuntu-24.04
31+
containerd: v2.0.0-rc.5
32+
arch: amd64
33+
- runner: github-arm64-2c-8gb
34+
containerd: v2.0.0-rc.5
35+
arch: arm64
36+
env:
37+
CONTAINERD_VERSION: "${{ matrix.containerd }}"
38+
ARCH: "${{ matrix.arch }}"
39+
steps:
40+
- uses: actions/[email protected]
41+
with:
42+
fetch-depth: 1
43+
- name: Expose GitHub Runtime variables for gha
44+
uses: crazy-max/ghaction-github-runtime@v3
45+
- name: Enable containerd to be able to use gha cache
46+
run: |
47+
sudo mkdir -p /etc/docker
48+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
49+
sudo systemctl restart docker
50+
- name: "Prepare integration test environment"
51+
run: |
52+
docker build \
53+
--cache-to type=gha,mode=max,scope=${ARCH}-${CONTAINERD_VERSION} \
54+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
55+
--target build-deps --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
56+
1657
test-unit:
1758
timeout-minutes: 5
1859
name: unit | ${{ matrix.goos }}
@@ -51,6 +92,7 @@ jobs:
5192
run: go test -v ./pkg/...
5293

5394
test-integration:
95+
needs: build-deps
5496
runs-on: "${{ matrix.runner }}"
5597
timeout-minutes: 40
5698
strategy:
@@ -61,24 +103,39 @@ jobs:
61103
- ubuntu: 20.04
62104
containerd: v1.6.36
63105
runner: "ubuntu-20.04"
106+
arch: amd64
64107
- ubuntu: 22.04
65108
containerd: v1.7.23
66109
runner: "ubuntu-22.04"
110+
arch: amd64
67111
- ubuntu: 24.04
68112
containerd: v2.0.0-rc.5
69113
runner: "ubuntu-24.04"
114+
arch: amd64
70115
- ubuntu: 24.04
71116
containerd: v2.0.0-rc.5
72117
runner: github-arm64-2c-8gb
118+
arch: arm64
73119
env:
74-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
75120
CONTAINERD_VERSION: "${{ matrix.containerd }}"
121+
ARCH: "${{ matrix.arch }}"
122+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
76123
steps:
77124
- uses: actions/[email protected]
78125
with:
79126
fetch-depth: 1
127+
- name: Expose GitHub Runtime variables for gha
128+
uses: crazy-max/ghaction-github-runtime@v3
129+
- name: Enable containerd to be able to use gha cache
130+
run: |
131+
sudo mkdir -p /etc/docker
132+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
133+
sudo systemctl restart docker
80134
- name: "Prepare integration test environment"
81-
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 build \
137+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
138+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
82139
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
83140
run: |
84141
sudo systemctl disable --now snapd.service snapd.socket
@@ -103,6 +160,7 @@ jobs:
103160
command: docker run -t --rm --privileged test-integration
104161

105162
test-integration-ipv6:
163+
needs: build-deps
106164
runs-on: "ubuntu-${{ matrix.ubuntu }}"
107165
timeout-minutes: 40
108166
strategy:
@@ -112,9 +170,12 @@ jobs:
112170
include:
113171
- ubuntu: 24.04
114172
containerd: v1.7.23
173+
arch: amd64
115174
env:
116-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
117175
CONTAINERD_VERSION: "${{ matrix.containerd }}"
176+
ARCH: "${{ matrix.arch }}"
177+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
178+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
118179
steps:
119180
- uses: actions/[email protected]
120181
with:
@@ -123,13 +184,19 @@ jobs:
123184
run: |
124185
sudo sysctl -w net.ipv6.conf.all.forwarding=1
125186
sudo sysctl -w net.ipv4.ip_forward=1
126-
- name: Enable IPv6 for Docker
187+
188+
- name: Expose GitHub Runtime variables for gha
189+
uses: crazy-max/ghaction-github-runtime@v3
190+
- name: Enable IPv6 for Docker and configure docker for gha
127191
run: |
128192
sudo mkdir -p /etc/docker
129-
echo '{"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
193+
echo '{"features": {"containerd-snapshotter": true}, "ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
130194
sudo systemctl restart docker
131195
- name: "Prepare integration test environment"
132-
run: docker build -t test-integration-ipv6 --target test-integration-ipv6 --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
196+
run: |
197+
docker build \
198+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
199+
-t test-integration-ipv6 --target test-integration-ipv6 --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
133200
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
134201
run: |
135202
sudo systemctl disable --now snapd.service snapd.socket
@@ -159,6 +226,7 @@ jobs:
159226
command: docker run --network host -t --rm --privileged test-integration-ipv6
160227

161228
test-integration-rootless:
229+
needs: build-deps
162230
runs-on: "ubuntu-${{ matrix.ubuntu }}"
163231
timeout-minutes: 60
164232
strategy:
@@ -170,21 +238,27 @@ jobs:
170238
containerd: v1.6.36
171239
rootlesskit: v1.1.1 # Deprecated
172240
target: test-integration-rootless
241+
arch: amd64
173242
- ubuntu: 22.04
174243
containerd: v1.7.23
175244
rootlesskit: v2.3.1
176245
target: test-integration-rootless
246+
arch: amd64
177247
- ubuntu: 24.04
178248
containerd: v2.0.0-rc.5
179249
rootlesskit: v2.3.1
180250
target: test-integration-rootless
251+
arch: amd64
181252
- ubuntu: 24.04
182253
containerd: v1.7.23
183254
rootlesskit: v2.3.1
184255
target: test-integration-rootless-port-slirp4netns
256+
arch: amd64
185257
env:
186-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
187258
CONTAINERD_VERSION: "${{ matrix.containerd }}"
259+
ARCH: "${{ matrix.arch }}"
260+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
261+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
188262
ROOTLESSKIT_VERSION: "${{ matrix.rootlesskit }}"
189263
TEST_TARGET: "${{ matrix.target }}"
190264
steps:
@@ -215,8 +289,18 @@ jobs:
215289
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
216290
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
217291
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
292+
- name: Expose GitHub Runtime variables for gha
293+
uses: crazy-max/ghaction-github-runtime@v3
294+
- name: Enable containerd to be able to use gha cache
295+
run: |
296+
sudo mkdir -p /etc/docker
297+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
298+
sudo systemctl restart docker
218299
- 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} .
300+
run: |
301+
docker build \
302+
--cache-from type=gha,scope=${ARCH}-${CONTAINERD_VERSION} \
303+
-t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
220304
- name: "Disable BuildKit for RootlessKit v1 (workaround for issue #622)"
221305
run: |
222306
# https://github.com/containerd/nerdctl/issues/622

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-deps
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-deps 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)