Skip to content

Commit 7e5c3e6

Browse files
Produce composite crossgen2 image for entire aspnet docker contents (#1775)
1 parent 32d1b3f commit 7e5c3e6

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed
Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
ARG REPO=mcr.microsoft.com/dotnet/core/runtime
2-
FROM $REPO:5.0-alpine3.11
1+
ARG REPO=mcr.microsoft.com/dotnet/core/runtime-deps
2+
3+
# Create standard image
4+
FROM $REPO:5.0-alpine3.11 AS StandardImage
5+
6+
# Install .NET Core
7+
8+
RUN dotnet_version=5.0.0-preview.2.20160.6 \
9+
&& wget -O dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Runtime/$dotnet_version/dotnet-runtime-$dotnet_version-linux-musl-x64.tar.gz \
10+
&& dotnet_sha512='f8dcf9f498feffbca4b0649086cffd298cd98189b2950c32dd52b07179b7f33e1acfe14ae59a266502a3518089ca55f224e007628d16194f94be7dc419c1b2b4' \
11+
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
12+
&& mkdir -p /usr/share/dotnet \
13+
&& tar -C /usr/share/dotnet -oxzf dotnet.tar.gz \
14+
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
15+
&& rm dotnet.tar.gz
316

417
# Install ASP.NET Core
518
RUN aspnetcore_version=5.0.0-preview.2.20167.3 \
@@ -8,3 +21,81 @@ RUN aspnetcore_version=5.0.0-preview.2.20167.3 \
821
&& echo "$aspnetcore_sha512 aspnetcore.tar.gz" | sha512sum -c - \
922
&& tar -ozxf aspnetcore.tar.gz -C /usr/share/dotnet ./shared/Microsoft.AspNetCore.App \
1023
&& rm aspnetcore.tar.gz
24+
25+
RUN dotnet --list-runtimes
26+
27+
# CROSSGEN the binaries from the standard image
28+
FROM $REPO:5.0-alpine3.11 AS SdkImage
29+
30+
ENV \
31+
# Unset the value from the base image
32+
ASPNETCORE_URLS= \
33+
# Disable the invariant mode (set in base image)
34+
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
35+
# Enable correct mode for dotnet watch (only mode supported in a container)
36+
DOTNET_USE_POLLING_FILE_WATCHER=true \
37+
LC_ALL=en_US.UTF-8 \
38+
LANG=en_US.UTF-8 \
39+
# Skip extraction of XML docs - generally not useful within an image/container - helps performance
40+
NUGET_XMLDOC_MODE=skip \
41+
# PowerShell telemetry for docker image usage
42+
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetCoreSDK-Alpine-3.10
43+
44+
# Add dependencies for disabling invariant mode (set in base image)
45+
RUN apk add --no-cache icu-libs
46+
47+
# Install .NET Core SDK
48+
RUN dotnet_sdk_version=5.0.100-preview.2.20175.2 \
49+
&& wget -O dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$dotnet_sdk_version/dotnet-sdk-$dotnet_sdk_version-linux-musl-x64.tar.gz \
50+
&& dotnet_sha512='07b2e91410306297d7d8ccd84aa00be06181efb8cb3cc4fab57cd370aca65409ba59c87dba70d2b46e1dd05c0597c2f0c8f38cde35032910febb08f51b65731a' \
51+
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
52+
&& mkdir -p /usr/share/dotnet \
53+
&& tar -C /usr/share/dotnet -oxzf dotnet.tar.gz \
54+
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
55+
&& rm dotnet.tar.gz \
56+
# Trigger first run experience by running arbitrary cmd
57+
&& dotnet help
58+
59+
# Install PowerShell global tool
60+
RUN powershell_version=7.0.0 \
61+
&& wget -O PowerShell.Linux.Alpine.$powershell_version.nupkg https://pwshtool.blob.core.windows.net/tool/$powershell_version/PowerShell.Linux.Alpine.$powershell_version.nupkg \
62+
&& powershell_sha512='afca5d8553d612e36d04597de14cdba9731442d567d25fb9b0f1451116f299f773b4f49b5be7d4d89e3e874eb43f8c062ae70c2ed1d620244a2a52ba443cf4cb' \
63+
&& echo "$powershell_sha512 PowerShell.Linux.Alpine.$powershell_version.nupkg" | sha512sum -c - \
64+
&& mkdir -p /usr/share/powershell \
65+
&& dotnet tool install --add-source / --tool-path /usr/share/powershell --version $powershell_version PowerShell.Linux.Alpine \
66+
&& dotnet nuget locals all --clear \
67+
&& rm PowerShell.Linux.Alpine.$powershell_version.nupkg \
68+
&& chmod 755 /usr/share/powershell/pwsh \
69+
&& ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \
70+
# To reduce image size, remove the copy nupkg that nuget keeps.
71+
&& find /usr/share/powershell -print | grep -i '.*[.]nupkg$' | xargs rm \
72+
# Add ncurses-terminfo-base to resolve psreadline dependency
73+
&& apk add --no-cache ncurses-terminfo-base
74+
75+
RUN dotnet --list-runtimes
76+
RUN dotnet --list-sdks
77+
78+
RUN dotnet --list-runtimes | grep Microsoft.NETCore.App | cut -d ' ' -f 2 > runtime-version.txt
79+
RUN dotnet --list-runtimes | grep Microsoft.AspNetCore.App | cut -d ' ' -f 2 > aspnet-version.txt
80+
81+
RUN dotnet new console -o /tmp
82+
COPY nuget.config /tmp
83+
RUN dotnet publish /tmp/tmp.csproj -p:PublishReadyToRun=true -p:PublishReadyToRunUseCrossgen2=true -r linux-musl-x64
84+
COPY --from=StandardImage /usr/share/dotnet/shared/Microsoft.NETCore.App /usr/cpinput
85+
COPY --from=StandardImage /usr/share/dotnet/shared/Microsoft.AspNetCore.App /usr/cpaspinput
86+
RUN mkdir /usr/input
87+
RUN cp /usr/cpinput/$(cat runtime-version.txt)/*.dll /usr/input
88+
RUN cp /usr/cpaspinput/$(cat aspnet-version.txt)/*.dll /usr/input
89+
RUN mkdir /usr/crossgen2
90+
RUN ~/.nuget/packages/microsoft.netcore.app.crossgen2.linux-musl-x64/$(cat runtime-version.txt)/tools/crossgen2 --inputbubble -o /usr/crossgen2/sharedframework.dll --composite -O --Os /usr/input/*.dll
91+
92+
COPY --from=StandardImage /usr/share/dotnet /usr/output
93+
RUN for b in /usr/output/shared/Microsoft.NETCore.App/$(cat runtime-version.txt)/*.dll; do a=/usr/crossgen2/`basename ${b}`; test -e ${a} && cp ${a} /usr/output/shared/Microsoft.NETCore.App/$(cat runtime-version.txt); done
94+
RUN for b in /usr/output/shared/Microsoft.AspNetCore.App/$(cat aspnet-version.txt)/*.dll; do a=/usr/crossgen2/`basename ${b}`; test -e ${a} && cp ${a} /usr/output/shared/Microsoft.AspNetCore.App/$(cat aspnet-version.txt); done
95+
RUN cp /usr/crossgen2/sharedframework.dll /usr/output/shared/Microsoft.NETCore.App/$(cat runtime-version.txt)
96+
97+
# Create optimized monolithic docker image
98+
FROM $REPO:5.0-alpine3.11
99+
100+
COPY --from=SdkImage /usr/output /usr/share/dotnet
101+
RUN ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<configuration>
2+
<packageSources>
3+
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
4+
<add key="dotnet-windowsdesktop" value="https://dotnetfeed.blob.core.windows.net/dotnet-windowsdesktop/index.json" />
5+
<add key="aspnet-aspnetcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore/index.json" />
6+
<add key="aspnet-aspnetcore-tooling" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore-tooling/index.json" />
7+
<add key="aspnet-entityframeworkcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-entityframeworkcore/index.json" />
8+
<add key="aspnet-extensions" value="https://dotnetfeed.blob.core.windows.net/aspnet-extensions/index.json" />
9+
<add key="gRPC repository" value="https://grpc.jfrog.io/grpc/api/nuget/v3/grpc-nuget-dev" />
10+
</packageSources>
11+
</configuration>
12+

0 commit comments

Comments
 (0)