From 95165ec91249c442d1a7a968cb7d5280fb8efeee Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 21:41:06 +0200 Subject: [PATCH 1/6] feat(dotnet): convert to v2 tool --- src/usr/local/buildpack/tools/dotnet.sh | 61 --------------- src/usr/local/buildpack/tools/v2/dotnet.sh | 91 ++++++++++++++++++++++ test/dotnet/Dockerfile | 18 +++++ 3 files changed, 109 insertions(+), 61 deletions(-) delete mode 100644 src/usr/local/buildpack/tools/dotnet.sh create mode 100644 src/usr/local/buildpack/tools/v2/dotnet.sh diff --git a/src/usr/local/buildpack/tools/dotnet.sh b/src/usr/local/buildpack/tools/dotnet.sh deleted file mode 100644 index 510e6f592c..0000000000 --- a/src/usr/local/buildpack/tools/dotnet.sh +++ /dev/null @@ -1,61 +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 - -DOTNET_INSTALL_DIR=/usr/local/buildpack/${TOOL_NAME} - -if [[ -d "${DOTNET_INSTALL_DIR}/sdk/${TOOL_VERSION}" ]]; then - echo "Skipping, already installed" - exit 0 -fi - -version_codename=$(get_distro) - -case "$version_codename" in - "bionic") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu60 libssl1.1 libstdc++6 zlib1g;; - "focal") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu66 libssl1.1 libstdc++6 zlib1g;; - "jammy") apt_install libc6 libgcc1 libgssapi-krb5-2 libicu70 libssl3 libstdc++6 zlib1g;; - *) - echo "Tool '${TOOL_NAME}' not supported on: ${version_codename}! Please use 'ubuntu' or 'bionic'." >&2 - exit 1 - ;; -esac - - -mkdir -p "$DOTNET_INSTALL_DIR" - -if [[ -z "${DOTNET_ROOT+x}" ]]; then - export_env DOTNET_ROOT "${DOTNET_INSTALL_DIR}" - export_env DOTNET_CLI_TELEMETRY_OPTOUT "1" - export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1" -fi - -curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir "$DOTNET_INSTALL_DIR" --no-path -version "$TOOL_VERSION" - -link_wrapper dotnet "$DOTNET_INSTALL_DIR" - -# first time experience -dotnet new > /dev/null -su "$USER_NAME" -c 'dotnet new' > /dev/null - -su "$USER_NAME" -c "mkdir -p \$HOME/.nuget" > /dev/null - -# command available since net core 3.1 -# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-list-source -if [[ ${MAJOR} -gt 3 || (${MAJOR} -eq 3 && ${MINOR} -ge 1) ]]; then - # See https://github.com/NuGet/Home/issues/11607 - dotnet nuget list source > /dev/null - su "$USER_NAME" -c 'dotnet nuget list source' > /dev/null -fi - -chmod -R g+w "$USER_HOME/.nuget" - -dotnet --info diff --git a/src/usr/local/buildpack/tools/v2/dotnet.sh b/src/usr/local/buildpack/tools/v2/dotnet.sh new file mode 100644 index 0000000000..4e1a2edd39 --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/dotnet.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +function prepare_tool() { + local version_codename + + version_codename=$(get_distro) + case "$version_codename" in + "bionic") apt_install \ + libc6 \ + libgcc1 \ + libgssapi-krb5-2 \ + libicu60 \ + libssl1.1 \ + libstdc++6 \ + zlib1g \ + ;; + "focal") apt_install \ + libc6 \ + libgcc1 \ + libgssapi-krb5-2 \ + libicu66 \ + libssl1.1 \ + libstdc++6 \ + zlib1g \ + ;; + "jammy") apt_install \ + libc6 \ + libgcc1 \ + libgssapi-krb5-2 \ + libicu70 \ + libssl3 \ + libstdc++6 \ + zlib1g \ + ;; + *) + echo "Tool '${TOOL_NAME}' not supported on: ${version_codename}! Please use ubuntu 'bionic', 'focal' or 'jammy'." >&2 + exit 1 + ;; + esac + + local tool_path + tool_path=$(create_tool_path) + + export_env DOTNET_ROOT "${tool_path}" + export_env DOTNET_CLI_TELEMETRY_OPTOUT "1" + export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1" + + mkdir -p "${USER_HOME}/.nuget" > /dev/null + chown "${USER_NAME}" "${USER_HOME}/.nuget" + chmod -R g+w "${USER_HOME}/.nuget" +} + +function install_tool () { + 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 + + curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir "$tool_path" --no-path --version "$TOOL_VERSION" +} + +function link_tool () { + local tool_path + tool_path=$(find_tool_path) + + shell_wrapper "${TOOL_NAME}" "${tool_path}/bin" + + dotnet new > /dev/null + if [[ $(is_root) -eq 0 ]]; then + su "$USER_NAME" -c 'dotnet new' > /dev/null + fi + + # command available since net core 3.1 + # https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-list-source + if [[ ${MAJOR} -gt 3 || (${MAJOR} -eq 3 && ${MINOR} -ge 1) ]]; then + # See https://github.com/NuGet/Home/issues/11607 + dotnet nuget list source > /dev/null + if [[ $(is_root) -eq 0 ]]; then + su "$USER_NAME" -c 'dotnet nuget list source' > /dev/null + fi + fi + + dotnet --info +} diff --git a/test/dotnet/Dockerfile b/test/dotnet/Dockerfile index 01b8dde5f4..a2da8199a3 100644 --- a/test/dotnet/Dockerfile +++ b/test/dotnet/Dockerfile @@ -17,6 +17,7 @@ FROM base as net3 ARG BUILDPACK_DEBUG ARG APT_HTTP_PROXY +# stay at 3.1 # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker RUN install-tool dotnet 3.1.419 @@ -71,6 +72,22 @@ RUN set -ex; \ dotnet restore --force-evaluate; \ dotnet build +#-------------------------------------- +# test: dotnet 6.0 (non-root) +#-------------------------------------- +FROM net3 as testc + +ARG BUILDPACK_DEBUG + +# renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker +RUN install-tool dotnet 6.0.300 + +RUN set -ex; \ + dotnet restore --use-lock-file + +RUN set -ex; \ + dotnet add package Newtonsoft.Json --version 12.0.3; \ + dotnet restore --force-evaluate #-------------------------------------- # final @@ -79,3 +96,4 @@ FROM base COPY --from=testa /.dummy /.dummy COPY --from=testb /.dummy /.dummy +COPY --from=testc /.dummy /.dummy From d0944fcf7a41889eecf154a0f51b5554fb39be07 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 21:46:04 +0200 Subject: [PATCH 2/6] fix: wrong link path --- src/usr/local/buildpack/tools/v2/dotnet.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/local/buildpack/tools/v2/dotnet.sh b/src/usr/local/buildpack/tools/v2/dotnet.sh index 4e1a2edd39..016846f8aa 100644 --- a/src/usr/local/buildpack/tools/v2/dotnet.sh +++ b/src/usr/local/buildpack/tools/v2/dotnet.sh @@ -70,7 +70,7 @@ function link_tool () { local tool_path tool_path=$(find_tool_path) - shell_wrapper "${TOOL_NAME}" "${tool_path}/bin" + shell_wrapper "${TOOL_NAME}" "${tool_path}" dotnet new > /dev/null if [[ $(is_root) -eq 0 ]]; then From 41e12f4f81333ae4be2d8feb53a1c283836f1762 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 21:49:55 +0200 Subject: [PATCH 3/6] chore: fix access --- src/usr/local/buildpack/tools/v2/dotnet.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/local/buildpack/tools/v2/dotnet.sh b/src/usr/local/buildpack/tools/v2/dotnet.sh index 016846f8aa..bbf920fd54 100644 --- a/src/usr/local/buildpack/tools/v2/dotnet.sh +++ b/src/usr/local/buildpack/tools/v2/dotnet.sh @@ -64,6 +64,8 @@ function install_tool () { fi curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir "$tool_path" --no-path --version "$TOOL_VERSION" + # we need write access to some sub dirs + chmod -R g+w "$tool_path" } function link_tool () { From ba47d2dda90fbd963c250e41b97094540d31649b Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 22:19:09 +0200 Subject: [PATCH 4/6] fix: wrong perm change --- src/usr/local/buildpack/tools/v2/dotnet.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/usr/local/buildpack/tools/v2/dotnet.sh b/src/usr/local/buildpack/tools/v2/dotnet.sh index bbf920fd54..cca214bce1 100644 --- a/src/usr/local/buildpack/tools/v2/dotnet.sh +++ b/src/usr/local/buildpack/tools/v2/dotnet.sh @@ -63,9 +63,12 @@ function install_tool () { tool_path=$(find_tool_path) fi - curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir "$tool_path" --no-path --version "$TOOL_VERSION" - # we need write access to some sub dirs - chmod -R g+w "$tool_path" + curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir "$tool_path" --no-path --version "$TOOL_VERSION" --skip-non-versioned-files + + # we need write access to some sub dirs for non root + if [[ $(is_root) -eq 0 ]]; then + find "$tool_path" -type d -exec chmod g+w {} \; + fi } function link_tool () { From da248636230c5ee6364884a40c121c011d7cadca Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 22:49:19 +0200 Subject: [PATCH 5/6] test: add move tests --- test/dotnet/Dockerfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/dotnet/Dockerfile b/test/dotnet/Dockerfile index a2da8199a3..47f32196b5 100644 --- a/test/dotnet/Dockerfile +++ b/test/dotnet/Dockerfile @@ -10,7 +10,7 @@ COPY --chown=1000:0 test test WORKDIR /test #-------------------------------------- -# net3: dotnet 3.1 base image +# net3: dotnet 3.1 base image (LTS) #-------------------------------------- FROM base as net3 @@ -29,7 +29,7 @@ SHELL [ "/bin/sh", "-c" ] RUN dotnet --info #-------------------------------------- -# test: dotnet 3.1 +# test: dotnet 3.1 (LTS) #-------------------------------------- FROM net3 as testa @@ -42,7 +42,7 @@ RUN set -ex; \ #-------------------------------------- -# test: dotnet 6.0 +# test: dotnet 6.0 (LTS) #-------------------------------------- FROM base as testb @@ -64,6 +64,8 @@ USER 1000 RUN dotnet --info +RUN set -ex; dotnet --version | tee | grep 6.0 + RUN set -ex; \ dotnet restore --use-lock-file @@ -73,15 +75,18 @@ RUN set -ex; \ dotnet build #-------------------------------------- -# test: dotnet 6.0 (non-root) +# test: dotnet 6.0 (non-root, LTS) #-------------------------------------- FROM net3 as testc ARG BUILDPACK_DEBUG +# only patch updates # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker RUN install-tool dotnet 6.0.300 +RUN set -ex; dotnet --version | tee | grep 6.0 + RUN set -ex; \ dotnet restore --use-lock-file From c6158e5e5497b5332a984e76fbb178214c4d89b2 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 13 Jun 2022 22:56:06 +0200 Subject: [PATCH 6/6] test: better tests --- test/dotnet/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/dotnet/Dockerfile b/test/dotnet/Dockerfile index 47f32196b5..21a6291f23 100644 --- a/test/dotnet/Dockerfile +++ b/test/dotnet/Dockerfile @@ -20,6 +20,7 @@ ARG APT_HTTP_PROXY # stay at 3.1 # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker RUN install-tool dotnet 3.1.419 +RUN set -ex; dotnet --version | grep 3.1. USER 1000 @@ -59,12 +60,12 @@ RUN install-tool dotnet 6.0.300 # Test duplicate install # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker RUN install-tool dotnet 6.0.300 +RUN set -ex; dotnet --version | grep 6.0. USER 1000 RUN dotnet --info -RUN set -ex; dotnet --version | tee | grep 6.0 RUN set -ex; \ dotnet restore --use-lock-file @@ -84,8 +85,7 @@ ARG BUILDPACK_DEBUG # only patch updates # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker RUN install-tool dotnet 6.0.300 - -RUN set -ex; dotnet --version | tee | grep 6.0 +RUN set -ex; dotnet --version | grep 6.0. RUN set -ex; \ dotnet restore --use-lock-file