Last active
February 20, 2023 07:43
-
-
Save kameshsampath/db6962db374d4483d5bdf90715a5da96 to your computer and use it in GitHub Desktop.
A custom docker file with rustlang tools and dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#syntax=docker/dockerfile:1.3-labs | |
FROM --platform=$TARGETPLATFORM rust:1.67-alpine3.17 AS bins | |
ARG TARGETPLATFORM | |
RUN --mount=type=cache,target=/usr/local/cargo/registry \ | |
apk add -U --no-cache alpine-sdk gcompat go-task \ | |
&& cargo install cargo-zigbuild | |
## The core builder that can be used to build rust applications | |
FROM --platform=$TARGETPLATFORM alpine:3.17 as final | |
ARG TARGETPLATFORM | |
ARG rust_version=1.67.1 | |
ARG rustup_version=1.25.2 | |
ARG user_id=1001 | |
ARG user=builder | |
ENV USER_ID=$user_id \ | |
USER=$user \ | |
RUST_VERSION=$rust_version \ | |
RUSTUP_VERSION=$rustup_version \ | |
RUSTUP_HOME=/usr/local/rustup \ | |
CARGO_HOME=/usr/local/cargo \ | |
PATH=/usr/local/cargo/bin:$PATH \ | |
RUST_VERSION=1.67.1 | |
COPY --from=bins /usr/bin/go-task /usr/local/bin/task | |
COPY --from=bins /usr/local/cargo/bin/cargo-zigbuild /usr/local/cargo/bin/ | |
RUN apk add -U --no-cache ca-certificates sudo shadow bash curl curl-dev file musl musl-dev gcc \ | |
&& adduser --uid $USER_ID --ingroup root --system --shell /bin/bash --disabled-password $USER; | |
&& echo "$USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER; | |
&& chmod 0440 /etc/sudoers.d/$USER \ | |
&& apkArch=$(apk --print-arch) \ | |
&& curl -L https://ziglang.org/download/$ZIG_VERSION/zig-linux-$apkArch-$ZIG_VERSION.tar.xz | tar -J -x -C /usr/local \ | |
&& ln -s /usr/local/zig-linux-$apkArch-$ZIG_VERSION/zig /usr/local/bin/zig ; | |
## these were copied from https://github.com/rust-lang/docker-rust/blob/master/1.67.1/alpine3.17/Dockerfile#L13-L25 | |
&& case "$apkArch" in \ | |
x86_64) rustArch='x86_64-unknown-linux-musl'; rustupSha256='241a99ff02accd2e8e0ef3a46aaa59f8d6934b1bb6e4fba158e1806ae028eb25' ;; \ | |
aarch64) rustArch='aarch64-unknown-linux-musl'; rustupSha256='6a2691ced61ef616ca196bab4b6ba7b0fc5a092923955106a0c8e0afa31dbce4' ;; \ | |
*) echo >&2 "unsupported architecture: $apkArch"; exit 1 ;; \ | |
esac; \ | |
url="https://static.rust-lang.org/rustup/archive/1.25.2/${rustArch}/rustup-init"; \ | |
wget "$url"; \ | |
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \ | |
chmod +x rustup-init; \ | |
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host $rustArch --target x86_64-unknown-linux-gnu \ | |
x86_64-unknown-linux-musl \ | |
aarch64-unknown-linux-musl \ | |
aarch64-unknown-linux-gnu | |
&& rm /usr/local/bin/rustup-init; \ | |
rm rustup-init; \ | |
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment