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
79 changes: 79 additions & 0 deletions build/buildEmbrDotNetRuntimeImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
# --------------------------------------------------------------------------------------------

set -euo pipefail

readonly REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly CONSTANTS_FILE="$REPO_DIR/images/constants.yml"
readonly EMBR_CONSTANTS_FILE="$REPO_DIR/images/embrconstants.yml"
readonly DOCKERFILE="$REPO_DIR/images/runtime/dotnetcore/embr/template.Dockerfile"
readonly ACR_NAME="${ACR_NAME:-oryxdevmcr.azurecr.io}"
readonly ACR_REPOSITORY="${ACR_REPOSITORY:-public/oryx/dotnetcore}"
readonly RELEASE_TAG_NAME="${RELEASE_TAG_NAME:-local}"
readonly BUILD_DEFINITIONNAME="${BUILD_DEFINITIONNAME:-local}"
readonly ARTIFACTS_DIR="${BUILD_ARTIFACTSTAGINGDIRECTORY:-$REPO_DIR/artifacts}"
readonly IMAGE_LIST="$ARTIFACTS_DIR/images/embr-dotnet-runtime-images-acr.resolute.txt"
readonly BASE_IMAGE="docker.io/library/embr_oryx_run_base_resolute"

yaml_value() {
local file="$1"
local key="$2"
local value
value="$(sed -n "s/^ ${key}:[[:space:]]*//p" "$file")"
if [[ -z "$value" ]]; then
echo "Missing $key in $file." >&2
return 1
fi
printf '%s\n' "$value"
}

os_flavor="$(yaml_value "$EMBR_CONSTANTS_FILE" dotnet100osFlavors)"
if [[ "$os_flavor" != "resolute" ]]; then
echo "Embr .NET 10 supports only Resolute, not '$os_flavor'." >&2
exit 1
fi

net_version="$(yaml_value "$CONSTANTS_FILE" NET_CORE_APP_100)"
aspnet_version="$(yaml_value "$CONSTANTS_FILE" ASPNET_CORE_APP_100)"
sdk_version="$(yaml_value "$CONSTANTS_FILE" DOTNET_SDK_100)"
agent_version="$(yaml_value "$CONSTANTS_FILE" USER_DOTNET_AI_VERSION)"

mkdir -p "$(dirname "$IMAGE_LIST")"
: > "$IMAGE_LIST"

docker build \
--file "$REPO_DIR/images/runtime/commonbase/Dockerfile" \
--tag "$BASE_IMAGE" \
--build-arg "OS_FLAVOR=$os_flavor" \
--build-arg "OS_TYPE=ubuntu" \
"$REPO_DIR"

secret_args=()
if [[ -n "${VSS_NUGET_ACCESSTOKEN:-}" ]]; then
secret_args+=(--secret id=vss_nuget_accesstoken,env=VSS_NUGET_ACCESSTOKEN)
fi

image="$ACR_NAME/$ACR_REPOSITORY:embr-10.0-ubuntu-resolute-$BUILD_DEFINITIONNAME.$RELEASE_TAG_NAME"
docker build \
--file "$DOCKERFILE" \
--tag "$image" \
"${secret_args[@]}" \
--build-arg "BASE_IMAGE=$BASE_IMAGE" \
--build-arg "DOTNET_SDK_VERSION=$sdk_version" \
--build-arg "NET_CORE_APP_100=$net_version" \
--build-arg "ASPNET_CORE_APP_100=$aspnet_version" \
--build-arg "USER_DOTNET_AI_VERSION=$agent_version" \
--build-arg "VSS_NUGET_URI_PREFIXES=${VSS_NUGET_URI_PREFIXES:-}" \
--build-arg "VSS_NUGET_EXTERNAL_FEED_ENDPOINTS=${VSS_NUGET_EXTERNAL_FEED_ENDPOINTS:-}" \
--build-arg "AI_CONNECTION_STRING=${AI_CONNECTION_STRING:-}" \
--build-arg "BUILD_NUMBER=${BUILD_BUILDNUMBER:-local}" \
--build-arg "GIT_COMMIT=${BUILD_SOURCEVERSION:-unspecified}" \
--build-arg "RELEASE_TAG_NAME=$RELEASE_TAG_NAME" \
"$REPO_DIR"
echo "$image" >> "$IMAGE_LIST"

echo "Built Embr .NET runtime image:"
cat "$IMAGE_LIST"
111 changes: 111 additions & 0 deletions build/testEmbrDotNetRuntimeImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
# --------------------------------------------------------------------------------------------

set -euo pipefail

readonly REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly CONSTANTS_FILE="$REPO_DIR/images/constants.yml"

if [[ $# -ne 1 || ! -s "$1" ]]; then
echo "Usage: $0 <image-list>" >&2
exit 1
fi

sdk_version="$(sed -n 's/^ DOTNET_SDK_100:[[:space:]]*//p' "$CONSTANTS_FILE")"
net_version="$(sed -n 's/^ NET_CORE_APP_100:[[:space:]]*//p' "$CONSTANTS_FILE")"
aspnet_version="$(sed -n 's/^ ASPNET_CORE_APP_100:[[:space:]]*//p' "$CONSTANTS_FILE")"
if [[ -z "$sdk_version" || -z "$net_version" || -z "$aspnet_version" ]]; then
echo "Missing .NET 10 version metadata in $CONSTANTS_FILE." >&2
exit 1
fi

tested_image=false
while IFS= read -r image || [[ -n "$image" ]]; do
image="${image%$'\r'}"
[[ -n "$image" ]] || continue
if [[ "$image" != *:embr-10.0-ubuntu-resolute-?* ]]; then
echo "Unexpected Embr .NET image tag: $image" >&2
exit 1
fi

test_image="${image}-smoke-test"
docker build \
--file - \
--tag "$test_image" \
--build-arg "RUNTIME_IMAGE=$image" \
--build-arg "DOTNET_SDK_VERSION=$sdk_version" \
"$REPO_DIR" <<'DOCKERFILE'
ARG RUNTIME_IMAGE
ARG DOTNET_SDK_VERSION
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_VERSION} AS build
WORKDIR /src
RUN dotnet new web --name EmbrSmoke --output . --framework net10.0 --no-restore \
&& printf '%s\n' \
'using System.Globalization;' \
'var app = WebApplication.Create(args);' \
'app.MapGet("/", () => CultureInfo.GetCultureInfo("fr-FR").DateTimeFormat.GetMonthName(1));' \
'app.Run();' > Program.cs \
&& dotnet publish --configuration Release --output /app /p:UseAppHost=false
FROM ${RUNTIME_IMAGE}
COPY --from=build /app /tmp/embr-dotnet-smoke
DOCKERFILE
trap 'docker image rm "$test_image" >/dev/null' EXIT

docker run --rm \
--env "EXPECTED_NET_VERSION=$net_version" \
--env "EXPECTED_ASPNET_VERSION=$aspnet_version" \
"$test_image" bash -ceu '
. /etc/os-release
test "$VERSION_CODENAME" = resolute
test "$DOTNET_VERSION" = 10.0
runtimes="$(dotnet --list-runtimes)"
grep -Fq "Microsoft.NETCore.App $EXPECTED_NET_VERSION [" <<< "$runtimes"
grep -Fq "Microsoft.AspNetCore.App $EXPECTED_ASPNET_VERSION [" <<< "$runtimes"
test -z "$(dotnet --list-sdks)"
! ldd /usr/share/dotnet/dotnet | grep -q "not found"
test -n "$(find /usr/local/share/ca-certificates -name "azl_*.crt" -print -quit)"
curl --fail --silent --show-error --max-time 30 \
"https://builds.dotnet.microsoft.com/dotnet/Runtime/$EXPECTED_NET_VERSION/dotnet-runtime-$EXPECTED_NET_VERSION-linux-x64.tar.gz.sha512" >/dev/null
test -d /DotNetCoreAgent
test -x /opt/startupcmdgen/startupcmdgen
test "$(readlink /usr/local/bin/oryx)" = /opt/startupcmdgen/startupcmdgen
oryx create-script \
-appPath /tmp/embr-dotnet-smoke \
-output /tmp/embr-dotnet-startup.sh \
-bindPort 8123
grep -q "EmbrSmoke.dll" /tmp/embr-dotnet-startup.sh
bash /tmp/embr-dotnet-startup.sh >/tmp/embr-dotnet-startup.log 2>&1 &
server_pid=$!
trap "kill $server_pid" EXIT
for attempt in $(seq 1 30); do
if test "$(curl --silent --fail http://127.0.0.1:8123)" = janvier; then
break
fi
if ! kill -0 "$server_pid" 2>/dev/null; then
cat /tmp/embr-dotnet-startup.log >&2
exit 1
fi
sleep 1
done
if test "$(curl --silent --fail http://127.0.0.1:8123)" != janvier; then
cat /tmp/embr-dotnet-startup.log >&2
exit 1
fi
kill "$server_pid"
wait "$server_pid" || true
trap - EXIT
'
docker image rm "$test_image" >/dev/null
trap - EXIT
tested_image=true
done < "$1"

if [[ "$tested_image" != true ]]; then
echo "No Embr .NET runtime images found in $1." >&2
exit 1
fi

echo "All Embr .NET runtime image tests passed."
1 change: 1 addition & 0 deletions images/embrconstants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ variables:
python314osFlavors: resolute
python315osFlavors: resolute
pythonosFlavors: resolute
dotnet100osFlavors: resolute
104 changes: 104 additions & 0 deletions images/runtime/dotnetcore/embr/template.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
ARG BASE_IMAGE
ARG DOTNET_SDK_VERSION

FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_SDK_VERSION} AS tools-install
ARG VSS_NUGET_URI_PREFIXES
ARG VSS_NUGET_EXTERNAL_FEED_ENDPOINTS

RUN wget -q https://aka.ms/install-artifacts-credprovider.sh -O /tmp/install-artifacts-credprovider.sh \
&& bash /tmp/install-artifacts-credprovider.sh \
&& rm /tmp/install-artifacts-credprovider.sh

RUN --mount=type=secret,id=vss_nuget_accesstoken,target=/run/secrets/vss_nuget_accesstoken \
if [ -f /run/secrets/vss_nuget_accesstoken ]; then \
export VSS_NUGET_ACCESSTOKEN="$(cat /run/secrets/vss_nuget_accesstoken)"; \
fi \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-sos \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-trace \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-dump \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-counters \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-gcdump \
&& dotnet tool install --tool-path /dotnetcore-tools dotnet-monitor --version 10.0.0-rc.1.25460.1

FROM mcr.microsoft.com/oss/go/microsoft/golang:1.26-bookworm AS startupCmdGen
WORKDIR /go/src
COPY src/startupscriptgenerator/src .
ARG GIT_COMMIT=unspecified
ARG BUILD_NUMBER=unspecified
ARG RELEASE_TAG_NAME=unspecified
ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME} \
GIT_COMMIT=${GIT_COMMIT} \
BUILD_NUMBER=${BUILD_NUMBER} \
PATH_CA_CERTIFICATE="/etc/ssl/certs/ca-certificate.crt"
RUN chmod +x build.sh && ./build.sh dotnetcore /opt/startupcmdgen/startupcmdgen

FROM ${BASE_IMAGE} AS appInsights
ARG USER_DOTNET_AI_VERSION
RUN curl --fail --show-error --location \
"https://oryxsdksdev-h4a7b3fscnhggycc.b02.azurefd.net/appinsights-agent/DotNetCoreAgent.${USER_DOTNET_AI_VERSION}.zip" \
--output /tmp/appinsights.zip \
&& apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& unzip /tmp/appinsights.zip -d /DotNetCoreAgent

FROM ${BASE_IMAGE}

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libc6 \
libgcc-s1 \
libgssapi-krb5-2 \
libicu78 \
libssl3 \
libstdc++6 \
zlib1g \
lldb-18 \
curl \
file \
libgdiplus \
tzdata \
unzip \
&& apt-get upgrade --assume-yes \
&& rm -rf /var/lib/apt/lists/*

ENV ASPNETCORE_URLS=http://+:80 \
DOTNET_RUNNING_IN_CONTAINER=true \
DOTNET_VERSION="10.0" \
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true \
PATH="/opt/dotnetcore-tools:${PATH}"

COPY --from=tools-install /dotnetcore-tools /opt/dotnetcore-tools
ARG NET_CORE_APP_100
ARG ASPNET_CORE_APP_100

RUN set -ex \
&& mkdir -p /tmp/dotnet-download /usr/share/dotnet \
&& cd /tmp/dotnet-download \
&& curl --fail --show-error --location \
--remote-name "https://builds.dotnet.microsoft.com/dotnet/Runtime/${NET_CORE_APP_100}/dotnet-runtime-${NET_CORE_APP_100}-linux-x64.tar.gz" \
--remote-name "https://builds.dotnet.microsoft.com/dotnet/Runtime/${NET_CORE_APP_100}/dotnet-runtime-${NET_CORE_APP_100}-linux-x64.tar.gz.sha512" \
&& sha512sum -c "dotnet-runtime-${NET_CORE_APP_100}-linux-x64.tar.gz.sha512" \
&& tar -zxf "dotnet-runtime-${NET_CORE_APP_100}-linux-x64.tar.gz" -C /usr/share/dotnet \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& curl --fail --show-error --location \
--remote-name "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/${ASPNET_CORE_APP_100}/aspnetcore-runtime-${ASPNET_CORE_APP_100}-linux-x64.tar.gz" \
--remote-name "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/${ASPNET_CORE_APP_100}/aspnetcore-runtime-${ASPNET_CORE_APP_100}-linux-x64.tar.gz.sha512" \
&& sha512sum -c "aspnetcore-runtime-${ASPNET_CORE_APP_100}-linux-x64.tar.gz.sha512" \
&& tar -zxf "aspnetcore-runtime-${ASPNET_CORE_APP_100}-linux-x64.tar.gz" -C /usr/share/dotnet ./shared/Microsoft.AspNetCore.App \
&& dotnet-sos install \
&& rm -rf /tmp/dotnet-download /tmp/oryx

ARG AI_CONNECTION_STRING
ARG USER_DOTNET_AI_VERSION
ENV ORYX_AI_CONNECTION_STRING=${AI_CONNECTION_STRING} \
USER_DOTNET_AI_VERSION=${USER_DOTNET_AI_VERSION} \
PATH_CA_CERTIFICATE="/etc/ssl/certs/ca-certificate.crt" \
LANG="C.UTF-8" \
LANGUAGE="C.UTF-8" \
LC_ALL="C.UTF-8" \
CNB_STACK_ID="oryx.stacks.skeleton"
LABEL io.buildpacks.stack.id="oryx.stacks.skeleton"

COPY --from=appInsights /DotNetCoreAgent /DotNetCoreAgent
COPY --from=startupCmdGen /opt/startupcmdgen/startupcmdgen /opt/startupcmdgen/startupcmdgen
RUN ln -s /opt/startupcmdgen/startupcmdgen /usr/local/bin/oryx
10 changes: 10 additions & 0 deletions platforms/dotnet/getDotNetSdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ getDotNetCoreSdk() {
echo
echo "Getting .NET Core Sdks..."
echo
if [ "$debianFlavor" == "resolute" ]; then
# Share .NET 10 release metadata without changing Noble builds or Resolute's .NET 11 manifest.
dotnet10Versions="$(awk -F, '$1 ~ /^[[:space:]]*10[.]/ { print }' "$dotNetPlatformDir/versions/noble/versionsToBuild.txt")"
if [ -z "$dotnet10Versions" ]; then
echo "No .NET 10 SDK versions found in the Noble manifest." >&2
exit 1
fi
buildPlatform <(printf '%s\n' "$dotnet10Versions") getDotNetCoreSdk
fi

buildPlatform "$dotNetPlatformDir/versions/$debianFlavor/versionsToBuild.txt" getDotNetCoreSdk

cp "$dotNetPlatformDir/versions/$debianFlavor/defaultVersion.txt" "$targetDir/defaultVersion.$debianFlavor.txt"
Loading