Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide image with only rustup #107

Open
synek317 opened this issue Jun 17, 2022 · 3 comments
Open

Provide image with only rustup #107

synek317 opened this issue Jun 17, 2022 · 3 comments

Comments

@synek317
Copy link

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
Copy link
Member

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
Copy link

kjvalencik commented Apr 5, 2023

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.

@fenollp
Copy link

fenollp commented Aug 17, 2024

FYI here's my way of using rustup within a build:

FROM scratch AS rustup
ADD --chmod=0755 --checksum=sha256:6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d \
  https://static.rust-lang.org/rustup/archive/1.27.1/x86_64-unknown-linux-gnu/rustup-init /rustup-init
FROM docker.io/library/debian:12-slim@sha256:2ccc7e39b0a6f504d252f807da1fc4b5bcd838e83e4dec3e2f57b2a4a64e7214 AS rust-base
ENV RUSTUP_HOME=/usr/local/rustup \
     CARGO_HOME=/usr/local/cargo \
           PATH=/usr/local/cargo/bin:$PATH
RUN \
    set -ux \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
      ca-certificates \
      gcc \
      libc6-dev
RUN \
  --mount=from=rustup,source=/rustup-init,target=/rustup-init \
    set -ux \
 && /rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly-2024-08-14 --default-host x86_64-unknown-linux-gnu \
 && chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
 && rustup --version \
 && cargo --version \
 && rustc --version \
 && apt-get remove -y --auto-remove \
 && rm -rf /var/lib/apt/lists/* \
# clean up for reproducibility
 && rm -rf /var/log/* /var/cache/ldconfig/aux-cache

One should be able to generalize and trim this to provide a single layer (ADD) image :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants