Skip to content

Commit

Permalink
Update samples to .NET 8 (#4742)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Anderson <jander-msft@users.noreply.github.com>
Co-authored-by: Logan Bussell <loganbussell@microsoft.com>
Co-authored-by: Damian Edwards <damian@damianedwards.com>
Co-authored-by: Matt Thalman <mthalman@microsoft.com>
  • Loading branch information
5 people authored Sep 14, 2023
1 parent 7c2fc5f commit c09ce8b
Show file tree
Hide file tree
Showing 102 changed files with 1,417 additions and 545 deletions.
20 changes: 10 additions & 10 deletions README.samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ See [Hosting ASP.NET Core Images with Docker over HTTPS](https://github.com/dotn
## Linux amd64 Tags
Tags | Dockerfile | OS Version
-----------| -------------| -------------
dotnetapp-alpine-slim-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine
aspnetapp-alpine-slim-amd64, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine
dotnetapp-jammy-chiseled-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.chiseled) | Ubuntu
aspnetapp-jammy-chiseled-composite-amd64, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.chiseled) | Ubuntu

## Linux arm32 Tags
Tags | Dockerfile | OS Version
-----------| -------------| -------------
dotnetapp-alpine-slim-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine
aspnetapp-alpine-slim-arm32v7, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine
dotnetapp-jammy-chiseled-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.chiseled) | Ubuntu
aspnetapp-jammy-chiseled-composite-arm32v7, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.chiseled-composite) | Ubuntu

## Linux arm64 Tags
Tags | Dockerfile | OS Version
-----------| -------------| -------------
dotnetapp-alpine-slim-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine
aspnetapp-alpine-slim-arm64v8, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine
dotnetapp-jammy-chiseled-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.chiseled) | Ubuntu
aspnetapp-jammy-chiseled-composite-arm64v8, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.chiseled-composite) | Ubuntu

## Nano Server 2022 amd64 Tags
Tag | Dockerfile
---------| ---------------
dotnetapp-nanoserver-ltsc2022, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile)
aspnetapp-nanoserver-ltsc2022, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.nanoserver-slim)
dotnetapp-nanoserver-ltsc2022, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.nanoserver)
aspnetapp-nanoserver-ltsc2022, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.nanoserver)

## Nano Server, version 1809 amd64 Tags
Tag | Dockerfile
---------| ---------------
dotnetapp-nanoserver-1809, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile)
aspnetapp-nanoserver-1809, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.nanoserver-slim)
dotnetapp-nanoserver-1809, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.nanoserver)
aspnetapp-nanoserver-1809, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.nanoserver)

You can retrieve a list of all available tags for dotnet/samples at https://mcr.microsoft.com/v2/dotnet/samples/tags/list.
<!--End of generated tags-->
Expand Down
2 changes: 1 addition & 1 deletion eng/common/templates/steps/init-docker-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ steps:
condition: and(succeeded(), ${{ parameters.condition }})
- script: >
echo "##vso[task.setvariable variable=runImageBuilderCmd]
docker run --rm
\$env:DOCKER_BUILDKIT=1; docker run --rm
-v /var/run/docker.sock:/var/run/docker.sock
-v $(Build.ArtifactStagingDirectory):$(artifactsPath)
-w /repo
Expand Down
12 changes: 6 additions & 6 deletions eng/mcr-tags-metadata-templates/samples-tags.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
$(McrTagsYmlRepo:samples)
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-amd64)
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-amd64)
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-arm32v7)
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-arm32v7)
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-arm64v8)
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-arm64v8)
$(McrTagsYmlTagGroup:dotnetapp-jammy-chiseled-amd64)
$(McrTagsYmlTagGroup:aspnetapp-jammy-chiseled-composite-amd64)
$(McrTagsYmlTagGroup:dotnetapp-jammy-chiseled-arm32v7)
$(McrTagsYmlTagGroup:aspnetapp-jammy-chiseled-composite-arm32v7)
$(McrTagsYmlTagGroup:dotnetapp-jammy-chiseled-arm64v8)
$(McrTagsYmlTagGroup:aspnetapp-jammy-chiseled-composite-arm64v8)
$(McrTagsYmlTagGroup:dotnetapp-nanoserver-ltsc2022)
$(McrTagsYmlTagGroup:aspnetapp-nanoserver-ltsc2022)
$(McrTagsYmlTagGroup:dotnetapp-nanoserver-1809)
Expand Down
56 changes: 31 additions & 25 deletions manifest.samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,38 @@
},
"platforms": [
{
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/dotnetapp/Dockerfile.chiseled",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"dotnetapp-alpine-slim-amd64": {}
"dotnetapp-jammy-chiseled-amd64": {}
}
},
{
"architecture": "arm",
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/dotnetapp/Dockerfile.chiseled",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"dotnetapp-alpine-slim-arm32v7": {}
"dotnetapp-jammy-chiseled-arm32v7": {}
},
"variant": "v7"
},
{
"architecture": "arm64",
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/dotnetapp/Dockerfile.chiseled",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"dotnetapp-alpine-slim-arm64v8": {}
"dotnetapp-jammy-chiseled-arm64v8": {}
},
"variant": "v8"
},
{
"dockerfile": "samples/dotnetapp",
"buildArgs": {
"TAG": "1809"
},
"dockerfile": "samples/dotnetapp/Dockerfile.nanoserver",
"os": "windows",
"osVersion": "nanoserver-1809",
"tags": {
Expand All @@ -71,7 +74,10 @@
}
},
{
"dockerfile": "samples/dotnetapp",
"buildArgs": {
"TAG": "ltsc2022"
},
"dockerfile": "samples/dotnetapp/Dockerfile.nanoserver",
"os": "windows",
"osVersion": "nanoserver-ltsc2022",
"tags": {
Expand All @@ -90,56 +96,56 @@
},
"platforms": [
{
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/aspnetapp/Dockerfile.chiseled",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"aspnetapp-alpine-slim-amd64": {}
"aspnetapp-jammy-chiseled-composite-amd64": {}
},
"customBuildLegGroups": [
{
"name": "test-dependencies",
"type": "Integral",
"dependencies": [
"$(Repo:samples):dotnetapp-alpine-slim-amd64"
"$(Repo:samples):dotnetapp-jammy-chiseled-amd64"
]
}
]
},
{
"architecture": "arm",
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/aspnetapp/Dockerfile.chiseled-composite",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"aspnetapp-alpine-slim-arm32v7": {}
"aspnetapp-jammy-chiseled-composite-arm32v7": {}
},
"variant": "v7",
"customBuildLegGroups": [
{
"name": "test-dependencies",
"type": "Integral",
"dependencies": [
"$(Repo:samples):dotnetapp-alpine-slim-arm32v7"
"$(Repo:samples):dotnetapp-jammy-chiseled-arm32v7"
]
}
]
},
{
"architecture": "arm64",
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-slim",
"dockerfile": "samples/aspnetapp/Dockerfile.chiseled-composite",
"os": "linux",
"osVersion": "alpine",
"osVersion": "ubuntu",
"tags": {
"aspnetapp-alpine-slim-arm64v8": {}
"aspnetapp-jammy-chiseled-composite-arm64v8": {}
},
"variant": "v8",
"customBuildLegGroups": [
{
"name": "test-dependencies",
"type": "Integral",
"dependencies": [
"$(Repo:samples):dotnetapp-alpine-slim-arm64v8"
"$(Repo:samples):dotnetapp-jammy-chiseled-arm64v8"
]
}
]
Expand All @@ -148,7 +154,7 @@
"buildArgs": {
"TAG": "1809"
},
"dockerfile": "samples/aspnetapp/Dockerfile.nanoserver-slim",
"dockerfile": "samples/aspnetapp/Dockerfile.nanoserver",
"os": "windows",
"osVersion": "nanoserver-1809",
"tags": {
Expand All @@ -172,7 +178,7 @@
"buildArgs": {
"TAG": "ltsc2022"
},
"dockerfile": "samples/aspnetapp/Dockerfile.nanoserver-slim",
"dockerfile": "samples/aspnetapp/Dockerfile.nanoserver",
"os": "windows",
"osVersion": "nanoserver-ltsc2022",
"tags": {
Expand Down
4 changes: 3 additions & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# .NET container samples

The following samples and guidance demonstrate how to use .NET and Docker for development, testing and production. You can equally use the samples for learning about containers or as the basis of your own container images.
The following samples and guidance demonstrate how to use .NET and Docker for development, testing and production. You can use the samples for learning about containers or as the basis of your own container images.

Kubernetes samples are provided in the [kubernetes](kubernetes/README.md) directory.

Expand All @@ -11,6 +11,8 @@ Kubernetes samples are provided in the [kubernetes](kubernetes/README.md) direct

* [Build a .NET container image](dotnetapp/README.md)
* [Build an ASP.NET Core container image](aspnetapp/README.md)
* [Build a single file app](releasesapp/README.md)
* [Build a native AOT app](releasesapi/README.md)
* [Building a globalization and time zone aware (or unaware) image](globalapp/README.md)
* [Build for a platform](build-for-a-platform.md)

Expand Down
14 changes: 8 additions & 6 deletions samples/aspnetapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /source

# copy csproj and restore as distinct layers
COPY aspnetapp/*.csproj .
RUN dotnet restore --use-current-runtime
RUN dotnet restore -a $TARGETARCH

# copy everything else and build app
# copy and publish app and libraries
COPY aspnetapp/. .
RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app
RUN dotnet publish -a $TARGETARCH --no-restore -o /app


# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
USER $APP_UID
ENTRYPOINT ["./aspnetapp"]
18 changes: 10 additions & 8 deletions samples/aspnetapp/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
WORKDIR /source

# copy csproj and restore as distinct layers
COPY aspnetapp/*.csproj .
RUN dotnet restore --use-current-runtime
# optimize
RUN --mount=type=bind,source=aspnetapp/aspnetapp.csproj,target=aspnetapp.csproj \
--mount=type=cache,target=/root/.nuget/ \
dotnet restore -a $TARGETARCH

# copy everything else and build app
# copy and publish app and libraries
COPY aspnetapp/. .
RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app
RUN dotnet publish -a $TARGETARCH --no-restore -o /app


# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
WORKDIR /app
COPY --from=build /app .
USER $APP_UID
ENTRYPOINT ["./aspnetapp"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ WORKDIR /source
COPY aspnetapp/*.csproj .
RUN dotnet restore -a $TARGETARCH

# copy everything else and build app
# copy and publish app and libraries
COPY aspnetapp/. .
RUN dotnet publish -a $TARGETARCH --no-restore -o /app


# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine

# These ENVs are only needed because the sample uses .NET 7
ENV DOTNET_ROLL_FORWARD=Major
ENV DOTNET_ROLL_FORWARD_PRE_RELEASE=1

FROM mcr.microsoft.com/dotnet/nightly/aspnet:8.0-alpine-composite
WORKDIR /app
COPY --from=build /app .

USER $APP_UID
ENTRYPOINT ["./aspnetapp"]
13 changes: 7 additions & 6 deletions samples/aspnetapp/Dockerfile.alpine-icu
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build

FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
WORKDIR /source

# copy csproj and restore as distinct layers
COPY aspnetapp/*.csproj .
RUN dotnet restore --use-current-runtime
RUN dotnet restore -a $TARGETARCH

# copy everything else and build app
# copy and publish app and libraries
COPY aspnetapp/. .
RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app
RUN dotnet publish -a $TARGETARCH --no-restore -o /app


# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine

ENV \
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
Expand All @@ -28,4 +28,5 @@ RUN apk add --no-cache \

WORKDIR /app
COPY --from=build /app .
USER $APP_UID
ENTRYPOINT ["./aspnetapp"]
24 changes: 0 additions & 24 deletions samples/aspnetapp/Dockerfile.alpine-slim

This file was deleted.

Loading

0 comments on commit c09ce8b

Please sign in to comment.