Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions src/usr/local/buildpack/tools/dotnet.sh

This file was deleted.

96 changes: 96 additions & 0 deletions src/usr/local/buildpack/tools/v2/dotnet.sh
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 26 additions & 3 deletions test/dotnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,7 +30,7 @@ SHELL [ "/bin/sh", "-c" ]
RUN dotnet --info

#--------------------------------------
# test: dotnet 3.1
# test: dotnet 3.1 (LTS)
#--------------------------------------
FROM net3 as testa

Expand All @@ -41,7 +43,7 @@ RUN set -ex; \


#--------------------------------------
# test: dotnet 6.0
# test: dotnet 6.0 (LTS)
#--------------------------------------
FROM base as testb

Expand All @@ -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

Expand All @@ -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
Expand All @@ -79,3 +101,4 @@ FROM base

COPY --from=testa /.dummy /.dummy
COPY --from=testb /.dummy /.dummy
COPY --from=testc /.dummy /.dummy