build: Dockerfile uses Rust version from `rust-toolchain.toml`

Instead of hardcoding the version of the Rust alpine file, introduce an `ARG` in
the `Dockerfile`. In `build/build`, we determine the version by inspecting
`rust-toolchain.toml`, and pass this value in. This ensures that the binaries
are built using the same toolchain that we develop with.
This commit is contained in:
Fintan Halpenny 2025-05-19 13:34:45 +02:00
parent 924b93283c
commit 7dcfe45781
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# Builds release binaries for Radicle. # Builds release binaries for Radicle.
FROM rust:1.80-alpine3.20 as builder ARG RUST_VERSION="1.85"
ARG ALPINE_VERSION="3.20"
FROM rust:${RUST_VERSION}-alpine${ALPINE_VERSION} as builder
LABEL maintainer="Radicle Team <team@radicle.xyz>" LABEL maintainer="Radicle Team <team@radicle.xyz>"
WORKDIR /src WORKDIR /src
COPY . . COPY . .

View File

@ -27,6 +27,7 @@ main() {
keypath="$(rad path)/keys/radicle.pub" keypath="$(rad path)/keys/radicle.pub"
version="$(build/version)" version="$(build/version)"
image=radicle-build-$version image=radicle-build-$version
rust_version="$(build/rust-version)"
if [ ! -f "$keypath" ]; then if [ ! -f "$keypath" ]; then
echo "fatal: no key found at $keypath" >&2 ; exit 1 echo "fatal: no key found at $keypath" >&2 ; exit 1
@ -40,6 +41,7 @@ main() {
echo "Building image ($image).." echo "Building image ($image).."
podman --cgroup-manager=cgroupfs build \ podman --cgroup-manager=cgroupfs build \
--build-arg "RUST_VERSION=$rust_version" \
--build-arg SOURCE_DATE_EPOCH \ --build-arg SOURCE_DATE_EPOCH \
--build-arg TZ \ --build-arg TZ \
--build-arg LC_ALL \ --build-arg LC_ALL \

7
build/rust-version Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
if ! version=$(grep -m 1 -oP "channel\s*=\s*\K(.*)" rust-toolchain.toml); then
echo "fatal: no rust version found via rust-toolchain.toml" >&2 ; exit 1
fi
echo "$version"