Skip to content

Commit 58a5fe0

Browse files
committed
Dockerfile: fix cross-compiling gomodjail
Fix issue 4241 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 8cc057f commit 58a5fe0

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.github/workflows/ghcr-image-build-and-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- name: Checkout repository
3434
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3535

36+
# FIXME: setup-qemu-action is depended by `gomodjail pack`
3637
- name: Set up QEMU
3738
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
3839

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
attestations: write # for provenances
2525
steps:
2626
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
# FIXME: setup-qemu-action is depended by `gomodjail pack`
28+
- name: "Set up QEMU"
29+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
2730
- name: "Install go"
2831
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
2932
with:

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ ENV CGO_ENABLED=1
107107
RUN GO=xx-go make static && \
108108
xx-verify --static bypass4netns && cp -a bypass4netns bypass4netnsd /out/${TARGETARCH}
109109

110+
FROM build-base-debian AS build-gomodjail
111+
ARG GOMODJAIL_VERSION
112+
ARG TARGETARCH
113+
RUN git clone --quiet --depth 1 --branch "${GOMODJAIL_VERSION%@*}" https://github.com/AkihiroSuda/gomodjail.git /go/src/github.com/AkihiroSuda/gomodjail
114+
WORKDIR /go/src/github.com/AkihiroSuda/gomodjail
115+
RUN git-checkout-tag-with-hash.sh ${GOMODJAIL_VERSION} && \
116+
mkdir -p /out/${TARGETARCH}
117+
RUN GO=xx-go make STATIC=1 && \
118+
xx-verify --static _output/bin/gomodjail && cp -a _output/bin/gomodjail /out/${TARGETARCH}
119+
110120
FROM build-base-debian AS build-kubo
111121
ARG KUBO_VERSION
112122
ARG TARGETARCH
@@ -234,12 +244,8 @@ RUN ROOTLESSKIT_VERSION=${ROOTLESSKIT_VERSION/@BINARY}; \
234244
rm -f "${fname}" /out/bin/rootlesskit-docker-proxy && \
235245
echo "- RootlessKit: ${ROOTLESSKIT_VERSION}" >> /out/share/doc/nerdctl-full/README.md
236246
ARG GOMODJAIL_VERSION
237-
RUN git clone https://github.com/AkihiroSuda/gomodjail.git /go/src/github.com/AkihiroSuda/gomodjail && \
238-
cd /go/src/github.com/AkihiroSuda/gomodjail && \
239-
git-checkout-tag-with-hash.sh "${GOMODJAIL_VERSION}" && \
240-
make STATIC=1 && \
241-
cp -a _output/bin/gomodjail /out/bin/ && \
242-
echo "- gomodjail: ${GOMODJAIL_VERSION}" >> /out/share/doc/nerdctl-full/README.md
247+
COPY --from=build-gomodjail /out/${TARGETARCH:-amd64}/* /out/bin/
248+
RUN echo "- gomodjail: ${GOMODJAIL_VERSION}" >> /out/share/doc/nerdctl-full/README.md
243249

244250
RUN echo "" >> /out/share/doc/nerdctl-full/README.md && \
245251
echo "## License" >> /out/share/doc/nerdctl-full/README.md && \
@@ -254,6 +260,8 @@ COPY . /go/src/github.com/containerd/nerdctl
254260
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
255261
WORKDIR /go/src/github.com/containerd/nerdctl
256262
RUN BINDIR=/out/bin make binaries install
263+
# FIXME: `gomodjail pack` depends on QEMU for non-native architecture
264+
# TODO: gomodjail should provide a plain shell script that utilizes `zip(1)` for packing the self-extract archive, without running `gomodjail pack`..
257265
RUN /out/bin/gomodjail pack --go-mod=/go/src/github.com/containerd/nerdctl/go.mod /out/bin/nerdctl && \
258266
cp -a nerdctl.gomodjail /out/bin/
259267
COPY README.md /out/share/doc/nerdctl/

0 commit comments

Comments
 (0)