Files
Lorenz Leutgeb 9ce88eda3f build/zig: 0.16.0 → 0.17.0
This reverts commit a87e0bd1c8, which
changed from downloading Zig to installing it via `apk`.

The reason to do this back then was because the download failed after
the version bump in 8d50b75826.
However, the reason for the download to fail was that the file name
pattern for the tarballs changed, see
<https://ziggit.dev/t/zig-0-14-1-released/10233/2> and that no
indirection via <https://ziglang.org/download/index.json> was done.

Now, as 0.17.0 is released, and the package in the Alpine repositories
is taking time to be updated, we revert the change, and rewrite the
download step to be more resilient.
2026-10-13 23:56:45 +02:00

123 lines
4.3 KiB
Docker

# Builds release binaries for Radicle.
ARG RUST_VERSION
ARG ALPINE_VERSION="3.24"
FROM docker.io/rust:${RUST_VERSION}-alpine${ALPINE_VERSION} as builder
LABEL maintainer="Radicle Team <team@radicle.dev>"
WORKDIR /src
COPY . .
ARG TZ
ARG LC_ALL
ARG SOURCE_DATE_EPOCH
ARG RADICLE_VERSION
ARG GIT_HEAD
# Copy cargo configuration we're going to use to specify compiler options.
RUN mkdir -p .cargo && cp build/config.toml .cargo/config.toml
# Install dependencies.
RUN apk update && apk add --no-cache \
asciidoctor \
curl \
git \
jq \
musl-dev \
xz
# Install a version of Zig that supports macOS TBD v4
ARG ZIG_VERSION="0.17.0"
RUN mkdir -p /usr/local/zig && \
ZIG_URL=$(\
curl -fsSL https://ziglang.org/download/index.json | \
jq -er --arg version "$ZIG_VERSION" '.[$version]["x86_64-linux"].tarball' \
) && \
curl -fsSL "$ZIG_URL" | tar -xJ -C /usr/local/zig --strip-components=1 && \
ln -s /usr/local/zig/zig /usr/local/bin/zig
# Build man pages and strip metadata. Removes all comments, since they include
# non-reproducible information, such as version numbers.
RUN asciidoctor --doctype manpage --backend manpage --destination-dir . *.1.adoc && \
find . -maxdepth 1 -type f -name '*.1' -exec sed -i '/^.\\\"/d' '{}' \;
# Add cargo targets.
RUN rustup target add \
x86_64-unknown-linux-musl \
aarch64-unknown-linux-musl \
x86_64-apple-darwin \
aarch64-apple-darwin
# Install dependencies for cross-compiling to macOS.
# We use Zig as the linker to perform the compilation from a Linux host.
# Zig is not yet available on Debian, so we download the official binary.
# Compilation is done via `cargo-zigbuild` which is a wrapper around `zig`.
RUN cargo install --locked cargo-zigbuild@0.23.4
# Parts of the macOS SDK are required to build Radicle, we make these available
# here. So far only `CoreFoundation` and `Security` frameworks are needed.
RUN xz -d -c build/macos-sdk-11.3.tar.xz | tar -x
# This env var is used by `cargo-zigbuild` to find the SDK.
ENV SDKROOT /src/macos-sdk-11.3
# Build binaries.
RUN cargo zigbuild --locked --release \
--target=x86_64-apple-darwin \
--target=aarch64-apple-darwin \
--target=aarch64-unknown-linux-musl \
--target=x86_64-unknown-linux-musl \
-p radicle-node \
-p radicle-remote-helper \
-p radicle-cli
# Now copy the files to a new image without all the intermediary artifacts to
# save some space.
FROM docker.io/alpine:${ALPINE_VERSION} as packager
ARG RADICLE_VERSION
ARG SOURCE_DATE_EPOCH
COPY --from=builder \
/src/target/x86_64-unknown-linux-musl/release/rad \
/src/target/x86_64-unknown-linux-musl/release/git-remote-rad \
/src/target/x86_64-unknown-linux-musl/release/radicle-node \
/builds/x86_64-unknown-linux-musl/bin/
COPY --from=builder \
/src/target/aarch64-unknown-linux-musl/release/rad \
/src/target/aarch64-unknown-linux-musl/release/git-remote-rad \
/src/target/aarch64-unknown-linux-musl/release/radicle-node \
/builds/aarch64-unknown-linux-musl/bin/
COPY --from=builder \
/src/target/aarch64-apple-darwin/release/rad \
/src/target/aarch64-apple-darwin/release/git-remote-rad \
/src/target/aarch64-apple-darwin/release/radicle-node \
/builds/aarch64-apple-darwin/bin/
COPY --from=builder \
/src/target/x86_64-apple-darwin/release/rad \
/src/target/x86_64-apple-darwin/release/git-remote-rad \
/src/target/x86_64-apple-darwin/release/radicle-node \
/builds/x86_64-apple-darwin/bin/
COPY --from=builder /src/*.1 /builds/x86_64-unknown-linux-musl/man/man1/
COPY --from=builder /src/*.1 /builds/aarch64-unknown-linux-musl/man/man1/
COPY --from=builder /src/*.1 /builds/aarch64-apple-darwin/man/man1/
COPY --from=builder /src/*.1 /builds/x86_64-apple-darwin/man/man1/
# Create and compress reproducible archive.
WORKDIR /builds
RUN x86_64-unknown-linux-musl/bin/rad version --json > radicle.json
RUN apk update && apk add --no-cache tar xz
RUN find * -maxdepth 0 -type d -exec mv '{}' "radicle-$RADICLE_VERSION-{}" \; && \
find * -maxdepth 0 -type d -exec tar \
--sort=name \
--verbose \
--mtime="@$SOURCE_DATE_EPOCH" \
--owner=0 \
--group=0 \
--numeric-owner \
--format=posix \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
--mode='go+u,go-w' \
--remove-files \
--create --xz \
--file="{}.tar.xz" \
'{}' \;