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..cca214bce1 --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/dotnet.sh @@ -0,0 +1,96 @@ +#!/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" --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 () { + local tool_path + tool_path=$(find_tool_path) + + shell_wrapper "${TOOL_NAME}" "${tool_path}" + + 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..21a6291f23 100644 --- a/test/dotnet/Dockerfile +++ b/test/dotnet/Dockerfile @@ -10,15 +10,17 @@ 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 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 +RUN set -ex; dotnet --version | grep 3.1. USER 1000 @@ -28,7 +30,7 @@ SHELL [ "/bin/sh", "-c" ] RUN dotnet --info #-------------------------------------- -# test: dotnet 3.1 +# test: dotnet 3.1 (LTS) #-------------------------------------- FROM net3 as testa @@ -41,7 +43,7 @@ RUN set -ex; \ #-------------------------------------- -# test: dotnet 6.0 +# test: dotnet 6.0 (LTS) #-------------------------------------- FROM base as testb @@ -58,11 +60,13 @@ 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 restore --use-lock-file @@ -71,6 +75,24 @@ RUN set -ex; \ dotnet restore --force-evaluate; \ dotnet build +#-------------------------------------- +# 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 | grep 6.0. + +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 +101,4 @@ FROM base COPY --from=testa /.dummy /.dummy COPY --from=testb /.dummy /.dummy +COPY --from=testc /.dummy /.dummy