Skip to content

Commit 4fd4147

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

File tree

2 files changed

+97
-25
lines changed

2 files changed

+97
-25
lines changed

.github/workflows/test.yml

+77-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ 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+
- runner: ubuntu-24.04
27+
containerd: v1.7.23
28+
- runner: ubuntu-24.04
29+
containerd: v2.0.0-rc.5
30+
- runner: github-arm64-2c-8gb
31+
containerd: v2.0.0-rc.5
32+
env:
33+
CONTAINERD_VERSION: "${{ matrix.containerd }}"
34+
RUNNER: "${{ matrix.runner }}"
35+
steps:
36+
- uses: actions/[email protected]
37+
with:
38+
fetch-depth: 1
39+
- name: Expose GitHub Runtime variables for gha
40+
uses: crazy-max/ghaction-github-runtime@v3
41+
- name: Enable containerd to be able to use gha cache
42+
run: |
43+
sudo mkdir -p /etc/docker
44+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
45+
sudo systemctl restart docker
46+
- name: "Prepare integration test environment"
47+
run: |
48+
docker build \
49+
--cache-to type=gha,mode=max,scope=${RUNNER}-${CONTAINERD_VERSION} \
50+
--cache-from type=gha,scope=${RUNNER}-${CONTAINERD_VERSION} \
51+
--target build-deps --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
52+
1653
test-unit:
1754
timeout-minutes: 5
1855
name: unit | ${{ matrix.goos }}
@@ -51,6 +88,7 @@ jobs:
5188
run: go test -v ./pkg/...
5289

5390
test-integration:
91+
needs: build-deps
5492
runs-on: "${{ matrix.runner }}"
5593
timeout-minutes: 40
5694
strategy:
@@ -71,14 +109,25 @@ jobs:
71109
containerd: v2.0.0-rc.5
72110
runner: github-arm64-2c-8gb
73111
env:
74-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
75112
CONTAINERD_VERSION: "${{ matrix.containerd }}"
113+
RUNNER: "${{ matrix.runner }}"
114+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
76115
steps:
77116
- uses: actions/[email protected]
78117
with:
79118
fetch-depth: 1
119+
- name: Expose GitHub Runtime variables for gha
120+
uses: crazy-max/ghaction-github-runtime@v3
121+
- name: Enable containerd to be able to use gha cache
122+
run: |
123+
sudo mkdir -p /etc/docker
124+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
125+
sudo systemctl restart docker
80126
- 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} .
127+
run: |
128+
docker build \
129+
--cache-from type=gha,scope=${RUNNER}-${CONTAINERD_VERSION} \
130+
-t test-integration --target test-integration --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
82131
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
83132
run: |
84133
sudo systemctl disable --now snapd.service snapd.socket
@@ -103,6 +152,7 @@ jobs:
103152
command: docker run -t --rm --privileged test-integration
104153

105154
test-integration-ipv6:
155+
needs: build-deps
106156
runs-on: "ubuntu-${{ matrix.ubuntu }}"
107157
timeout-minutes: 40
108158
strategy:
@@ -113,8 +163,9 @@ jobs:
113163
- ubuntu: 24.04
114164
containerd: v1.7.23
115165
env:
116-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
117166
CONTAINERD_VERSION: "${{ matrix.containerd }}"
167+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
168+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
118169
steps:
119170
- uses: actions/[email protected]
120171
with:
@@ -123,13 +174,19 @@ jobs:
123174
run: |
124175
sudo sysctl -w net.ipv6.conf.all.forwarding=1
125176
sudo sysctl -w net.ipv4.ip_forward=1
126-
- name: Enable IPv6 for Docker
177+
178+
- name: Expose GitHub Runtime variables for gha
179+
uses: crazy-max/ghaction-github-runtime@v3
180+
- name: Enable IPv6 for Docker and configure docker for gha
127181
run: |
128182
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
183+
echo '{"features": {"containerd-snapshotter": true}, "ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64", "experimental": true, "ip6tables": true}' | sudo tee /etc/docker/daemon.json
130184
sudo systemctl restart docker
131185
- 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} .
186+
run: |
187+
docker build \
188+
--cache-from type=gha,scope=${RUNNER}-${CONTAINERD_VERSION} \
189+
-t test-integration-ipv6 --target test-integration-ipv6 --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} .
133190
- name: "Remove snap loopback devices (conflicts with our loopback devices in TestRunDevice)"
134191
run: |
135192
sudo systemctl disable --now snapd.service snapd.socket
@@ -159,6 +216,7 @@ jobs:
159216
command: docker run --network host -t --rm --privileged test-integration-ipv6
160217

161218
test-integration-rootless:
219+
needs: build-deps
162220
runs-on: "ubuntu-${{ matrix.ubuntu }}"
163221
timeout-minutes: 60
164222
strategy:
@@ -183,8 +241,9 @@ jobs:
183241
rootlesskit: v2.3.1
184242
target: test-integration-rootless-port-slirp4netns
185243
env:
186-
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
187244
CONTAINERD_VERSION: "${{ matrix.containerd }}"
245+
RUNNER: "ubuntu-${{ matrix.ubuntu }}"
246+
UBUNTU_VERSION: "${{ matrix.ubuntu }}"
188247
ROOTLESSKIT_VERSION: "${{ matrix.rootlesskit }}"
189248
TEST_TARGET: "${{ matrix.target }}"
190249
steps:
@@ -215,8 +274,18 @@ jobs:
215274
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
216275
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
217276
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
277+
- name: Expose GitHub Runtime variables for gha
278+
uses: crazy-max/ghaction-github-runtime@v3
279+
- name: Enable containerd to be able to use gha cache
280+
run: |
281+
sudo mkdir -p /etc/docker
282+
echo '{"features": {"containerd-snapshotter": true}}' | sudo tee /etc/docker/daemon.json
283+
sudo systemctl restart docker
218284
- 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} .
285+
run: |
286+
docker build \
287+
--cache-from type=gha,scope=${RUNNER}-${CONTAINERD_VERSION} \
288+
-t ${TEST_TARGET} --target ${TEST_TARGET} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg CONTAINERD_VERSION=${CONTAINERD_VERSION} --build-arg ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION} .
220289
- name: "Disable BuildKit for RootlessKit v1 (workaround for issue #622)"
221290
run: |
222291
# 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)