rust-lang / docker-rust

The official Docker images for Rust
430 stars 89 forks source link

Provide image with only rustup #107

Open synek317 opened 2 years ago

synek317 commented 2 years ago

Do you think it would be possible to provide Dockerfile that only installs rustup?

It would be useful for people who are fine with stable rustup but would like to use any version of rust via rust-toolchain file.

I'm not a Docker expert but I think it could be the same as the image in this repository except installing cargo. I've been using the example below for quite a while with cached several directories (--mount=type=cache,target="/usr/local/rustup" --mount=type=cache,target="/usr/local/cargo/git" --mount=type=cache,target="/usr/local/cargo/registry" --mount=type=cache,target="/src/target",sharing=private):

# syntax=docker/dockerfile:1.3

FROM buildpack-deps:bullseye AS builder

ARG RUSTUP_HOME=/usr/local/rustup
ARG CARGO_HOME=/usr/local/cargo

ENV RUSTUP_HOME=${RUSTUP_HOME} \
    CARGO_HOME=${CARGO_HOME} \
    PATH=${CARGO_HOME}/bin:$PATH \
    GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"

RUN set -eux; \
    dpkgArch="$(dpkg --print-architecture)"; \
    case "${dpkgArch##*-}" in \
        amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='3dc5ef50861ee18657f9db2eeb7392f9c2a6c95c90ab41e45ab4ca71476b4338' ;; \
        armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='67777ac3bc17277102f2ed73fd5f14c51f4ca5963adadf7f174adf4ebc38747b' ;; \
        arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='32a1532f7cef072a667bac53f1a5542c99666c4071af0c9549795bbdb2069ec1' ;; \
        i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='e50d1deb99048bc5782a0200aa33e4eea70747d49dffdc9d06812fd22a372515' ;; \
        *) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
    esac; \
    url="https://static.rust-lang.org/rustup/archive/1.24.3/${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 none --default-host ${rustArch}; \
    rm rustup-init; \
    chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
    rustup --version;
sfackler commented 2 years ago

This seems pretty reasonable to me I think. We'd probably want to call the image rustup rather than rust to avoid too much tag confusion.

kjvalencik commented 1 year ago

This would be especially handy for CI when you have multiple targets managed by rust-toolchain. It makes it easy to cache the RUSTUP_HOME to store all of the targets/components without needing to double download targets that are baked into the docker image.