diff --git a/src/usr/local/buildpack/tools/rust.sh b/src/usr/local/buildpack/tools/rust.sh deleted file mode 100644 index dda8450aa0..0000000000 --- a/src/usr/local/buildpack/tools/rust.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -set -e - -require_root -check_semver "${TOOL_VERSION}" - - -if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then - echo Invalid version: "${TOOL_VERSION}" - exit 1 -fi - -base_path=/usr/local/buildpack/${TOOL_NAME} -tool_path=$base_path/$TOOL_VERSION - -if [[ ! -d "${tool_path}" ]]; then - mkdir -p "$base_path" - curl -sSfLo rust.tar.gz "https://static.rust-lang.org/dist/rust-${TOOL_VERSION}-x86_64-unknown-linux-gnu.tar.gz" - mkdir rust - pushd rust - tar --strip 1 -xf ../rust.tar.gz - ./install.sh --prefix="$tool_path" --components=cargo,rust-std-x86_64-unknown-linux-gnu,rustc - popd - rm rust.tar.gz - rm -rf rust -fi - -reset_tool_env -export_tool_env RUST_BACKTRACE 1 -export_tool_env CARGO_HOME "${USER_HOME}/.cargo" -export_tool_path "\$CARGO_HOME/bin" - -link_wrapper rustc "${tool_path}/bin" -link_wrapper cargo "${tool_path}/bin" - -cargo --version -rustc --version diff --git a/src/usr/local/buildpack/tools/v2/rust.sh b/src/usr/local/buildpack/tools/v2/rust.sh new file mode 100644 index 0000000000..710e75dfe9 --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/rust.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +function prepare_tool() { + create_tool_path + export_env RUST_BACKTRACE 1 + export_env CARGO_HOME "${USER_HOME}/.cargo" + export_path "\$CARGO_HOME/bin" +} + +function install_tool () { + local versioned_tool_path + local file + local arch=x86_64 + local tool_path + tool_path=$(find_tool_path) + + if [[ ! -d "${tool_path}" ]]; then + if [[ $(is_root) -ne 0 ]]; then + echo "${TOOL_NAME} not prepared" + exit 1 + fi + prepare_tool + tool_path=$(find_tool_path) + fi + + versioned_tool_path=$(create_versioned_tool_path) + + file=$(get_from_url "https://static.rust-lang.org/dist/rust-${TOOL_VERSION}-${arch}-unknown-linux-gnu.tar.gz") + mkdir -p "${TEMP_DIR}/rust" + bsdtar --strip 1 -C "${TEMP_DIR}/rust" -xf "${file}" + "${TEMP_DIR}/rust/install.sh" --prefix="$versioned_tool_path" --components=cargo,rust-std-${arch}-unknown-linux-gnu,rustc + rm -rf "${TEMP_DIR}/rust" +} + +function link_tool () { + local versioned_tool_path + versioned_tool_path=$(find_versioned_tool_path) + + shell_wrapper "cargo" "${versioned_tool_path}/bin" + shell_wrapper "rustc" "${versioned_tool_path}/bin" + + cargo --version + rustc --version +} diff --git a/test/rust/Dockerfile b/test/rust/Dockerfile index f4a8d62ecf..92c6c7b3ce 100644 --- a/test/rust/Dockerfile +++ b/test/rust/Dockerfile @@ -1,7 +1,20 @@ ARG IMAGE=containerbase/buildpack -FROM ${IMAGE} as build +ARG BUILDPACK_DEBUG -ARG APT_HTTP_PROXY +FROM ${IMAGE} as base + +RUN touch /.dummy + +COPY --chown=1000:0 test test + +WORKDIR /test + +ARG BUILDPACK_DEBUG + +RUN prepare-tool rust + +FROM base as build +ARG BUILDPACK_DEBUG # renovate: datasource=docker versioning=docker RUN install-tool rust 1.65.0 @@ -9,12 +22,33 @@ RUN install-tool rust 1.65.0 # renovate: datasource=docker versioning=docker RUN install-tool rust 1.65.0 -COPY --chown=1000:0 test test -WORKDIR /test +USER 1000 + +#-------------------------------------- +# test a: root +#-------------------------------------- +FROM build as testa + +RUN set -ex; \ + cd a; \ + cargo update; \ + cargo update --manifest-path Cargo.toml --package serde; + +SHELL [ "/bin/sh", "-c" ] +RUN rustc --version +RUN cargo --version + +#-------------------------------------- +# test b: non-root +#-------------------------------------- +FROM base as testb +ARG BUILDPACK_DEBUG USER 1000 +# renovate: datasource=docker versioning=docker +RUN install-tool rust 1.65.0 RUN set -ex; \ cd a; \ @@ -24,3 +58,11 @@ RUN set -ex; \ SHELL [ "/bin/sh", "-c" ] RUN rustc --version RUN cargo --version + +#-------------------------------------- +# final +#-------------------------------------- +FROM base + +COPY --from=testa /.dummy /.dummy +COPY --from=testb /.dummy /.dummy