Description
This docker-images would ideal to be used in the Docker From step inside a builder, to build mutliplatform images.
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:aarch64-unknown-linux-musl AS builder
SHELL ["/bin/bash", "-uo", "pipefail", "-c"]
ARG version
RUN apt-get -y update && apt-get -y install protobuf-compiler musl musl-dev musl-tools
ENV PROTOC=/usr/bin/protoc
RUN echo "build version ${version}"
RUN cargo install --locked --git https://github.com/ankitects/anki.git --tag ${version} anki-sync-server
RUN ldd /usr/local/cargo/bin/anki-sync-server
FROM --platform=$BUILDPLATFORM scratch
ENV SYNC_BASE=/data
COPY --from=builder --chmod=0755 /usr/local/cargo/bin/anki-sync-server /
CMD ["./anki-sync-server"]
For this you must choose an different image tag for each platform.
Docker does provide the option to use docker Args linke TARGETPLATFORM
here. Which are created by buildx.
So you can modifiy the From
step like this:
FROM --platform=$BUILDPLATFORM ghcr.io/rust-cross/rust-musl-cross:$TARGETPLATFORM AS builder
The problem is that TARGETPLATFORM
platform does not match the name of the rust toolchain. Instead it has values like linux/amd64
, linux/arm64
, linux/arm/v7
. Sadly docker does not allow to use a function here, also variables for previous build steps can not be used, so they is currently no way to map this values to the required toolchain.
My suggestion is to add additional linux/amd64
, linux/arm64
, linux/arm/v7
, etc tags, so TARGETPLATFORM
platform can be used directly.