Skip to content

Commit

Permalink
don't pre-install rust packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mauwii committed Oct 19, 2023
1 parent 7b9b8c5 commit 282462d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
3 changes: 0 additions & 3 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ target "ubuntu" {
{
version = "22.04"
codename = "jammy"
CARGO_PACKAGES = "[\"bindgen-cli\",\"cbindgen\",\"cargo-audit\",\"cargo-outdated\"]"
DOTNET_CHANNEL = "LTS"
DOTNET_DEPS = "[\"libicu70\",\"libssl3\",\"libunwind8\",\"libgcc-s1\",\"liblttng-ust1\"]"
DOTNET_SDK_VERSION = "6.0.415"
Expand All @@ -93,7 +92,6 @@ target "ubuntu" {
{
version = "20.04"
codename = "focal"
CARGO_PACKAGES = "[\"--locked\",\"bindgen-cli\",\"cbindgen\",\"cargo-audit\",\"cargo-outdated\"]"
DOTNET_CHANNEL = "LTS"
DOTNET_DEPS = "[\"libicu66\",\"libssl1.1\"]"
DOTNET_SDK_VERSION = "6.0.415"
Expand All @@ -104,7 +102,6 @@ target "ubuntu" {
args = {
BICEP_VERSION = BICEP_VERSION
CARGO_HOME = "/etc/.skel/.cargo"
CARGO_PACKAGES = release.CARGO_PACKAGES
CODENAME = release.codename
DEPENDENCIES = DEPENDENCIES
DOTNET_CHANNEL = release.DOTNET_CHANNEL
Expand Down
46 changes: 17 additions & 29 deletions linux/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,16 @@ RUN bash -c "$(curl -fsSL https://raw.githubusercontent.com/ilikenwf/apt-fast/ma
&& rm -rf /etc/apt/sources.list.d/* \
&& rm -rf /var/lib/apt/lists/*

ARG FROM_VERSION=22.04
FROM buildpack-deps:${FROM_VERSION} as rust
FROM base as rust
ARG TARGETARCH
SHELL [ "/bin/bash", "--login", "-e", "-o", "pipefail", "-c" ]
ARG RUSTUP_HOME=/etc/skel/.rustup
ARG CARGO_HOME=/etc/skel/.cargo
ENV PATH=${CARGO_HOME}/bin:${PATH}
ARG CARGO_PACKAGES
RUN apt-get -y update \
&& apt-get -y install --no-install-recommends \
jq \
&& curl -fsSL https://sh.rustup.rs | sh -s -- -y \
--default-toolchain=stable \
--profile=complete \
--no-modify-path \
--component rustfmt clippy \
&& cargo_tools=() \
&& while IFS='' read -r pkg; do cargo_tools+=("$pkg"); done < <(printf "%s\n" "${CARGO_PACKAGES}" | jq -r '.[]') \
&& cargo install "${cargo_tools[@]}" \
&& apt-get clean \
&& rm -rf /etc/apt/sources.list.d/* \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y \
--default-toolchain=stable \
&& cargo --version \
&& rustc --version

FROM base as golang
ARG TARGETARCH
Expand Down Expand Up @@ -332,6 +320,18 @@ RUN apt-get -y update &>/dev/null \
&& rm -rf /etc/apt/sources.list.d/* \
&& rm -rf /var/lib/apt/lists/*

# add rust
ARG CARGO_HOME=/etc/skel/.cargo
COPY --link --from=rust ${CARGO_HOME} ${CARGO_HOME}
ARG RUSTUP_HOME=/etc/skel/.rustup
COPY --link --from=rust ${RUSTUP_HOME} ${RUSTUP_HOME}
ENV PATH=${CARGO_HOME}/bin:${PATH} \
CARGO_HOME=${CARGO_HOME} \
RUSTUP_HOME=${RUSTUP_HOME}
RUN sed "s|^PATH=|PATH=${CARGO_HOME}/bin:|mg" -i /etc/environment \
&& echo "CARGO_HOME=${CARGO_HOME}" | tee -a /etc/environment \
&& echo "RUSTUP_HOME=${RUSTUP_HOME}" | tee -a /etc/environment

# add go
COPY --link --from=golang /usr/local/go /usr/local/go
ENV PATH=/usr/local/go/bin:${PATH}
Expand All @@ -352,18 +352,6 @@ RUN ln -s "$(realpath --relative-to=/usr/local/bin "${TOOL_PATH_PWSH}")/pwsh" /u
COPY --link --from=dotnet-powershell-modules /usr/local/share/powershell /usr/local/share/powershell
COPY --link --from=dotnet-powershell-az-modules /usr/local/share/powershell /usr/local/share/powershell

# add rust
ARG CARGO_HOME=/etc/skel/.cargo
COPY --link --from=rust ${CARGO_HOME} ${CARGO_HOME}
ARG RUSTUP_HOME=/etc/skel/.rustup
COPY --link --from=rust ${RUSTUP_HOME} ${RUSTUP_HOME}
ENV PATH=${CARGO_HOME}/bin:${PATH} \
CARGO_HOME=${CARGO_HOME} \
RUSTUP_HOME=${RUSTUP_HOME}
RUN sed "s|^PATH=|PATH=${CARGO_HOME}/bin:|mg" -i /etc/environment \
&& echo "CARGO_HOME=${CARGO_HOME}" | tee -a /etc/environment \
&& echo "RUSTUP_HOME=${RUSTUP_HOME}" | tee -a /etc/environment

# upgrade and cleanup step
RUN apt-get -y update \
&& apt-get -y upgrade \
Expand Down

0 comments on commit 282462d

Please sign in to comment.