Skip to content

Commit f55f6c8

Browse files
ashnagamthalman
authored andcommitted
Update samples to Alpine (#4171)
(cherry picked from commit fb07c27)
1 parent d822db8 commit f55f6c8

File tree

13 files changed

+222
-86
lines changed

13 files changed

+222
-86
lines changed

README.samples.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ See [Hosting ASP.NET Core Images with Docker over HTTPS](https://github.com/dotn
6060
## Linux amd64 Tags
6161
Tags | Dockerfile | OS Version
6262
-----------| -------------| -------------
63-
dotnetapp-buster-slim-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile) | Debian 10
64-
aspnetapp-buster-slim-amd64, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile) | Debian 10
63+
dotnetapp-alpine-slim-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-x64-slim) | Alpine
64+
aspnetapp-alpine-slim-amd64, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-x64-slim) | Alpine
6565

6666
## Linux arm32 Tags
6767
Tags | Dockerfile | OS Version
6868
-----------| -------------| -------------
69-
dotnetapp-buster-slim-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.debian-arm32) | Debian 10
70-
aspnetapp-buster-slim-arm32v7, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.debian-arm32) | Debian 10
69+
dotnetapp-alpine-slim-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-arm32-slim) | Alpine
70+
aspnetapp-alpine-slim-arm32v7, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-arm32-slim) | Alpine
7171

7272
## Linux arm64 Tags
7373
Tags | Dockerfile | OS Version
7474
-----------| -------------| -------------
75-
dotnetapp-buster-slim-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile) | Debian 10
76-
aspnetapp-buster-slim-arm64v8, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile) | Debian 10
75+
dotnetapp-alpine-slim-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-arm64-slim) | Alpine
76+
aspnetapp-alpine-slim-arm64v8, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-arm64-slim) | Alpine
7777

7878
## Nano Server 2022 amd64 Tags
7979
Tag | Dockerfile

eng/mcr-tags-metadata-templates/samples-tags.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
$(McrTagsYmlRepo:samples)
2-
$(McrTagsYmlTagGroup:dotnetapp-buster-slim-amd64)
3-
$(McrTagsYmlTagGroup:aspnetapp-buster-slim-amd64)
4-
$(McrTagsYmlTagGroup:dotnetapp-buster-slim-arm32v7)
5-
$(McrTagsYmlTagGroup:aspnetapp-buster-slim-arm32v7)
6-
$(McrTagsYmlTagGroup:dotnetapp-buster-slim-arm64v8)
7-
$(McrTagsYmlTagGroup:aspnetapp-buster-slim-arm64v8)
2+
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-amd64)
3+
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-amd64)
4+
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-arm32v7)
5+
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-arm32v7)
6+
$(McrTagsYmlTagGroup:dotnetapp-alpine-slim-arm64v8)
7+
$(McrTagsYmlTagGroup:aspnetapp-alpine-slim-arm64v8)
88
$(McrTagsYmlTagGroup:dotnetapp-nanoserver-ltsc2022)
99
$(McrTagsYmlTagGroup:aspnetapp-nanoserver-ltsc2022)
1010
$(McrTagsYmlTagGroup:dotnetapp-nanoserver-1809)

manifest.samples.json

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,30 @@
3131
},
3232
"platforms": [
3333
{
34-
"dockerfile": "samples/dotnetapp",
34+
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-x64-slim",
3535
"os": "linux",
36-
"osVersion": "buster",
36+
"osVersion": "alpine",
3737
"tags": {
38-
"dotnetapp-buster-slim-amd64": {
39-
"syndication": {
40-
"repo": "dotnet/core/samples"
41-
}
42-
}
38+
"dotnetapp-alpine-slim-amd64": {}
4339
}
4440
},
4541
{
4642
"architecture": "arm",
47-
"dockerfile": "samples/dotnetapp/Dockerfile.debian-arm32",
43+
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-arm32-slim",
4844
"os": "linux",
49-
"osVersion": "buster",
45+
"osVersion": "alpine",
5046
"tags": {
51-
"dotnetapp-buster-slim-arm32v7": {
52-
"syndication": {
53-
"repo": "dotnet/core/samples"
54-
}
55-
}
47+
"dotnetapp-alpine-slim-arm32v7": {}
5648
},
5749
"variant": "v7"
5850
},
5951
{
6052
"architecture": "arm64",
61-
"dockerfile": "samples/dotnetapp",
53+
"dockerfile": "samples/dotnetapp/Dockerfile.alpine-arm64-slim",
6254
"os": "linux",
63-
"osVersion": "buster",
55+
"osVersion": "alpine",
6456
"tags": {
65-
"dotnetapp-buster-slim-arm64v8": {
66-
"syndication": {
67-
"repo": "dotnet/core/samples"
68-
}
69-
}
57+
"dotnetapp-alpine-slim-arm64v8": {}
7058
},
7159
"variant": "v8"
7260
},
@@ -102,68 +90,56 @@
10290
},
10391
"platforms": [
10492
{
105-
"dockerfile": "samples/aspnetapp",
93+
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-x64-slim",
10694
"os": "linux",
107-
"osVersion": "buster",
95+
"osVersion": "alpine",
10896
"tags": {
109-
"aspnetapp-buster-slim-amd64": {
110-
"syndication": {
111-
"repo": "dotnet/core/samples"
112-
}
113-
}
97+
"aspnetapp-alpine-slim-amd64": {}
11498
},
11599
"customBuildLegGroups": [
116100
{
117101
"name": "test-dependencies",
118102
"type": "Integral",
119103
"dependencies": [
120-
"$(Repo:samples):dotnetapp-buster-slim-amd64"
104+
"$(Repo:samples):dotnetapp-alpine-slim-amd64"
121105
]
122106
}
123107
]
124108
},
125109
{
126110
"architecture": "arm",
127-
"dockerfile": "samples/aspnetapp/Dockerfile.debian-arm32",
111+
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-arm32-slim",
128112
"os": "linux",
129-
"osVersion": "buster",
113+
"osVersion": "alpine",
130114
"tags": {
131-
"aspnetapp-buster-slim-arm32v7": {
132-
"syndication": {
133-
"repo": "dotnet/core/samples"
134-
}
135-
}
115+
"aspnetapp-alpine-slim-arm32v7": {}
136116
},
137117
"variant": "v7",
138118
"customBuildLegGroups": [
139119
{
140120
"name": "test-dependencies",
141121
"type": "Integral",
142122
"dependencies": [
143-
"$(Repo:samples):dotnetapp-buster-slim-arm32v7"
123+
"$(Repo:samples):dotnetapp-alpine-slim-arm32v7"
144124
]
145125
}
146126
]
147127
},
148128
{
149129
"architecture": "arm64",
150-
"dockerfile": "samples/aspnetapp",
130+
"dockerfile": "samples/aspnetapp/Dockerfile.alpine-arm64-slim",
151131
"os": "linux",
152-
"osVersion": "buster",
132+
"osVersion": "alpine",
153133
"tags": {
154-
"aspnetapp-buster-slim-arm64v8": {
155-
"syndication": {
156-
"repo": "dotnet/core/samples"
157-
}
158-
}
134+
"aspnetapp-alpine-slim-arm64v8": {}
159135
},
160136
"variant": "v8",
161137
"customBuildLegGroups": [
162138
{
163139
"name": "test-dependencies",
164140
"type": "Integral",
165141
"dependencies": [
166-
"$(Repo:samples):dotnetapp-buster-slim-arm64v8"
142+
"$(Repo:samples):dotnetapp-alpine-slim-arm64v8"
167143
]
168144
}
169145
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://hub.docker.com/_/microsoft-dotnet
2+
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
3+
WORKDIR /source
4+
5+
# copy csproj and restore as distinct layers
6+
COPY aspnetapp/*.csproj .
7+
RUN dotnet restore -r linux-musl-arm /p:PublishReadyToRun=true
8+
9+
# copy everything else and build app
10+
COPY aspnetapp/. .
11+
RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
12+
13+
# final stage/image
14+
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm32v7
15+
WORKDIR /app
16+
COPY --from=build /app .
17+
ENTRYPOINT ["./aspnetapp"]
18+
19+
# See: https://github.com/dotnet/announcements/issues/20
20+
# Uncomment to enable globalization APIs (or delete)
21+
# ENV \
22+
# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
23+
# LC_ALL=en_US.UTF-8 \
24+
# LANG=en_US.UTF-8
25+
# RUN apk add --no-cache \
26+
# icu-data-full \
27+
# icu-libs
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://hub.docker.com/_/microsoft-dotnet
2+
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
3+
WORKDIR /source
4+
5+
# copy csproj and restore as distinct layers
6+
COPY aspnetapp/*.csproj .
7+
RUN dotnet restore -r linux-musl-arm64 /p:PublishReadyToRun=true
8+
9+
# copy everything else and build app
10+
COPY aspnetapp/. .
11+
RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
12+
13+
# final stage/image
14+
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm64v8
15+
WORKDIR /app
16+
COPY --from=build /app .
17+
ENTRYPOINT ["./aspnetapp"]
18+
19+
# See: https://github.com/dotnet/announcements/issues/20
20+
# Uncomment to enable globalization APIs (or delete)
21+
# ENV \
22+
# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
23+
# LC_ALL=en_US.UTF-8 \
24+
# LANG=en_US.UTF-8
25+
# RUN apk add --no-cache \
26+
# icu-data-full \
27+
# icu-libs
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://hub.docker.com/_/microsoft-dotnet
2+
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
3+
WORKDIR /source
4+
5+
# copy csproj and restore as distinct layers
6+
COPY *.csproj .
7+
RUN dotnet restore -r linux-musl-arm /p:PublishReadyToRun=true
8+
9+
# copy and publish app and libraries
10+
COPY . .
11+
RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
12+
13+
# final stage/image
14+
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm32v7
15+
WORKDIR /app
16+
COPY --from=build /app .
17+
ENTRYPOINT ["./dotnetapp"]
18+
19+
# See: https://github.com/dotnet/announcements/issues/20
20+
# Uncomment to enable globalization APIs (or delete)
21+
# ENV \
22+
# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
23+
# LC_ALL=en_US.UTF-8 \
24+
# LANG=en_US.UTF-8
25+
# RUN apk add --no-cache \
26+
# icu-data-full \
27+
# icu-libs
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://hub.docker.com/_/microsoft-dotnet
2+
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
3+
WORKDIR /source
4+
5+
# copy csproj and restore as distinct layers
6+
COPY *.csproj .
7+
RUN dotnet restore -r linux-musl-arm64 /p:PublishReadyToRun=true
8+
9+
# copy and publish app and libraries
10+
COPY . .
11+
RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
12+
13+
# final stage/image
14+
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm64v8
15+
WORKDIR /app
16+
COPY --from=build /app .
17+
ENTRYPOINT ["./dotnetapp"]
18+
19+
# See: https://github.com/dotnet/announcements/issues/20
20+
# Uncomment to enable globalization APIs (or delete)
21+
# ENV \
22+
# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
23+
# LC_ALL=en_US.UTF-8 \
24+
# LANG=en_US.UTF-8
25+
# RUN apk add --no-cache \
26+
# icu-data-full \
27+
# icu-libs

tests/Microsoft.DotNet.Docker.Tests/DockerHelper.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void Build(
3535
string target = null,
3636
string contextDir = ".",
3737
bool pull = false,
38+
string platform = null,
3839
params string[] buildArgs)
3940
{
4041
string buildArgsOption = string.Empty;
@@ -46,11 +47,17 @@ public void Build(
4647
}
4748
}
4849

50+
string platformOption = string.Empty;
51+
if (platform is not null)
52+
{
53+
platformOption = $" --platform {platform}";
54+
}
55+
4956
string targetArg = target == null ? string.Empty : $" --target {target}";
5057
string dockerfileArg = dockerfile == null ? string.Empty : $" -f {dockerfile}";
5158
string pullArg = pull ? " --pull" : string.Empty;
5259

53-
ExecuteWithLogging($"build -t {tag}{targetArg}{buildArgsOption}{dockerfileArg}{pullArg} {contextDir}");
60+
ExecuteWithLogging($"build -t {tag}{targetArg}{buildArgsOption}{dockerfileArg}{pullArg}{platformOption} {contextDir}");
5461
}
5562

5663
/// <summary>
@@ -71,9 +78,12 @@ public string BuildDistrolessHelper(DotNetImageType imageType, ProductImageData
7178

7279
string tag = imageData.GetIdentifier("distroless-helper");
7380
Build(tag, dockerfile, null, TestArtifactsDir, false,
74-
$"distroless_image={distrolessImageTag}",
75-
$"base_image={baseImageTag}",
76-
$"root_destination={rootDestination}");
81+
buildArgs: new string[]
82+
{
83+
$"distroless_image={distrolessImageTag}",
84+
$"base_image={baseImageTag}",
85+
$"root_destination={rootDestination}"
86+
});
7787
return tag;
7888
}
7989

tests/Microsoft.DotNet.Docker.Tests/ImageData.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ static ImageData()
4040
});
4141
}
4242

43+
public string Platform
44+
{
45+
get
46+
{
47+
string os = IsWindows ? "windows" : "linux";
48+
string arch = Arch.ToString().ToLowerInvariant();
49+
if (ArchVariant.Length > 0)
50+
{
51+
arch += $"/{ArchVariant}";
52+
}
53+
54+
return $"{os}/{arch}";
55+
}
56+
}
57+
58+
public string ArchVariant =>
59+
Arch switch
60+
{
61+
Arch.Amd64 => string.Empty,
62+
Arch.Arm => "v7",
63+
Arch.Arm64 => "v8",
64+
_ => throw new NotImplementedException()
65+
};
66+
67+
public bool IsWindows => OS.StartsWith(Tests.OS.NanoServer) || OS.StartsWith(Tests.OS.ServerCore);
68+
4369
public int DefaultPort => IsDistroless ? 8080 : 80;
4470

4571
public string Rid
@@ -48,7 +74,7 @@ public string Rid
4874
{
4975
string rid;
5076

51-
if (OS.StartsWith(Tests.OS.NanoServer) || OS.StartsWith(Tests.OS.ServerCore))
77+
if (IsWindows)
5278
{
5379
rid = "win-x64";
5480
}

tests/Microsoft.DotNet.Docker.Tests/MonitorImageTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@ private void GetNames(SampleImageData imageData, out string imageName, out strin
585585
{
586586
// Need to allow pulling of the sample image since these are not built in the same pipeline
587587
// as the other images; otherwise, these tests will fail due to lack of sample image.
588-
imageName = imageData.GetImage(SampleImageType.Aspnetapp, DockerHelper, allowPull: true);
588+
string tag = imageData.GetTagNameBase(SampleImageType.Aspnetapp);
589+
imageName = imageData.GetImage(tag, DockerHelper, allowPull: true);
589590
containerName = imageData.GetIdentifier("monitortest-sample");
590591
}
591592

0 commit comments

Comments
 (0)