Skip to content

Commit d447bda

Browse files
authored
FromDockerfile (dotnet#4312)
* FromDockerfile
1 parent a891b99 commit d447bda

39 files changed

+4272
-26
lines changed

Aspire.sln

+19
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Azure.WebPub
489489
EndProject
490490
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Valkey", "src\Aspire.Hosting.Valkey\Aspire.Hosting.Valkey.csproj", "{5CB63205-24F4-4388-A41B-BAF3BEA59866}"
491491
EndProject
492+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dockerfile", "dockerfile", "{A6813855-E322-41EF-B2E6-7A44949EF962}"
493+
EndProject
494+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "withdockerfile", "withdockerfile", "{A6813855-E322-41EF-B2E6-7A44949EF962}"
495+
EndProject
496+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WithDockerfile.AppHost", "playground\withdockerfile\WithDockerfile.AppHost\WithDockerfile.AppHost.csproj", "{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}"
497+
EndProject
498+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Hosting.Containers.Tests", "tests\Aspire.Hosting.Containers.Tests\Aspire.Hosting.Containers.Tests.csproj", "{588CD2D7-EE70-43C1-8233-330854BDF53C}"
499+
EndProject
492500
Global
493501
GlobalSection(SolutionConfigurationPlatforms) = preSolution
494502
Debug|Any CPU = Debug|Any CPU
@@ -1287,6 +1295,14 @@ Global
12871295
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
12881296
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
12891297
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4}.Release|Any CPU.Build.0 = Release|Any CPU
1298+
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1299+
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
1300+
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
1301+
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9}.Release|Any CPU.Build.0 = Release|Any CPU
1302+
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1303+
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Debug|Any CPU.Build.0 = Debug|Any CPU
1304+
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Release|Any CPU.ActiveCfg = Release|Any CPU
1305+
{588CD2D7-EE70-43C1-8233-330854BDF53C}.Release|Any CPU.Build.0 = Release|Any CPU
12901306
EndGlobalSection
12911307
GlobalSection(SolutionProperties) = preSolution
12921308
HideSolutionNode = FALSE
@@ -1521,6 +1537,9 @@ Global
15211537
{1BFE3C02-3B81-4596-99A2-4DCDD9129C9A} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
15221538
{9FAE1602-2C69-4D24-8655-A164489441E8} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
15231539
{DF00FDA3-D3EC-4E07-B4EC-0EBB57A813A4} = {77CFE74A-32EE-400C-8930-5025E8555256}
1540+
{A6813855-E322-41EF-B2E6-7A44949EF962} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
1541+
{E6BE41D3-872C-47D2-B5B1-78C37AFAEAF9} = {A6813855-E322-41EF-B2E6-7A44949EF962}
1542+
{588CD2D7-EE70-43C1-8233-330854BDF53C} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
15241543
EndGlobalSection
15251544
GlobalSection(ExtensibilityGlobals) = postSolution
15261545
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}

eng/pipelines/templates/BuildAndTest.yml

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ steps:
3535
--settings $(Build.SourcesDirectory)/eng/CodeCoverage.config
3636
--output ${{ parameters.repoTestResultsPath }}/NonHelix.cobertura.xml
3737
"${{ parameters.buildScript }} -testnobuild -test -configuration ${{ parameters.buildConfig }} /bl:${{ parameters.repoLogPath }}/tests.binlog $(_OfficialBuildIdArgs)"
38+
env:
39+
DOCKER_BUILDKIT: 1
3840
displayName: Run non-helix tests
3941

4042
- script: ${{ parameters.buildScript }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
6+
<Import Project="../../../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.props" />
7+
8+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
6+
<Import Project="..\..\..\src\Aspire.Hosting.AppHost\build\Aspire.Hosting.AppHost.targets" />
7+
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />
8+
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
var builder = DistributedApplication.CreateBuilder(args);
5+
builder.Configuration["Parameters:goversion"] = "1.22"; // Just for validating parameter handling in Dockerfile builds.
6+
7+
var goVersion = builder.AddParameter("goversion");
8+
var secret = builder.AddParameter("secret", secret: true);
9+
10+
builder.AddDockerfile("mycontainer", "qots")
11+
.WithBuildArg("GO_VERSION", goVersion)
12+
.WithBuildSecret("SECRET_ASFILE", new FileInfo("Program.cs"))
13+
.WithBuildSecret("SECRET_ASENV", secret);
14+
15+
builder.AddRedis("vanillaredis").WithRedisCommander();
16+
17+
builder.AddRedis("spicyredis")
18+
.WithDockerfile("spicyredis") // This overrides the port that we listen on.
19+
.WithEndpoint("tcp", (endpoint) =>
20+
{
21+
endpoint.TargetPort = 6380; // This fixes the app model so it still works.
22+
}).WithRedisCommander();
23+
24+
// This project is only added in playground projects to support development/debugging
25+
// of the dashboard. It is not required in end developer code. Comment out this code
26+
// to test end developer dashboard launch experience. Refer to Directory.Build.props
27+
// for the path to the dashboard binary (defaults to the Aspire.Dashboard bin output
28+
// in the artifacts dir).
29+
builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
30+
31+
builder.Build().Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:15887;http://localhost:15888",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16175",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17037",
14+
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
15+
"DCP_DIAGNOSTICS_LOG_LEVEL": "debug"
16+
}
17+
},
18+
"http": {
19+
"commandName": "Project",
20+
"dotnetRunMessages": true,
21+
"launchBrowser": true,
22+
"applicationUrl": "http://localhost:15888",
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development",
25+
"DOTNET_ENVIRONMENT": "Development",
26+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
27+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17038",
28+
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
29+
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
30+
}
31+
},
32+
"generate-manifest": {
33+
"commandName": "Project",
34+
"launchBrowser": true,
35+
"dotnetRunMessages": true,
36+
"commandLineArgs": "--publisher manifest --output-path aspire-manifest.json",
37+
"applicationUrl": "http://localhost:15888",
38+
"environmentVariables": {
39+
"ASPNETCORE_ENVIRONMENT": "Development",
40+
"DOTNET_ENVIRONMENT": "Development",
41+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175"
42+
}
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
17+
<ProjectReference Include="..\..\..\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
18+
<ProjectReference Include="..\..\..\src\Aspire.Hosting.Redis\Aspire.Hosting.Redis.csproj" IsAspireProjectResource="false" />
19+
</ItemGroup>
20+
21+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning",
7+
"Aspire.Hosting.Dashboard": "Warning"
8+
}
9+
},
10+
"Parameters": {
11+
"secret": "opensesame"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"$schema": "https://json.schemastore.org/aspire-8.0.json",
3+
"resources": {
4+
"goversion": {
5+
"type": "parameter.v0",
6+
"value": "{goversion.inputs.value}",
7+
"inputs": {
8+
"value": {
9+
"type": "string"
10+
}
11+
}
12+
},
13+
"secret": {
14+
"type": "parameter.v0",
15+
"value": "{secret.inputs.value}",
16+
"inputs": {
17+
"value": {
18+
"type": "string",
19+
"secret": true
20+
}
21+
}
22+
},
23+
"mycontainer": {
24+
"type": "container.v1",
25+
"build": {
26+
"context": "qots",
27+
"dockerfile": "qots/Dockerfile",
28+
"args": {
29+
"GO_VERSION": "{goversion.value}"
30+
},
31+
"secrets": {
32+
"SECRET_ASFILE": {
33+
"type": "file",
34+
"source": "Program.cs"
35+
},
36+
"SECRET_ASENV": {
37+
"type": "env",
38+
"value": "{secret.value}"
39+
}
40+
}
41+
}
42+
},
43+
"vanillaredis": {
44+
"type": "container.v0",
45+
"connectionString": "{vanillaredis.bindings.tcp.host}:{vanillaredis.bindings.tcp.port}",
46+
"image": "docker.io/library/redis:7.2",
47+
"bindings": {
48+
"tcp": {
49+
"scheme": "tcp",
50+
"protocol": "tcp",
51+
"transport": "tcp",
52+
"targetPort": 6379
53+
}
54+
}
55+
},
56+
"spicyredis": {
57+
"type": "container.v1",
58+
"connectionString": "{spicyredis.bindings.tcp.host}:{spicyredis.bindings.tcp.port}",
59+
"build": {
60+
"context": "spicyredis",
61+
"dockerfile": "spicyredis/Dockerfile"
62+
},
63+
"bindings": {
64+
"tcp": {
65+
"scheme": "tcp",
66+
"protocol": "tcp",
67+
"transport": "tcp",
68+
"targetPort": 6380
69+
}
70+
}
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Stage 1: Build the Go program
2+
ARG GO_VERSION=1.16
3+
FROM golang:${GO_VERSION} AS builder
4+
WORKDIR /app
5+
COPY . .
6+
RUN go build qots.go
7+
8+
# Stage 2: Run the Go program
9+
ARG GO_VERSION
10+
FROM golang:${GO_VERSION}
11+
WORKDIR /app
12+
RUN --mount=type=secret,id=SECRET_ASENV cp /run/secrets/SECRET_ASENV /app/SECRET_ASENV
13+
RUN --mount=type=secret,id=SECRET_ASFILE cp /run/secrets/SECRET_ASFILE /app/SECRET_ASFILE
14+
COPY --from=builder /app/qots .
15+
CMD ["./qots"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"math/rand"
6+
"runtime"
7+
"time"
8+
)
9+
10+
func main() {
11+
fmt.Println("Go runtime version:", runtime.Version())
12+
13+
quotes := []string{
14+
"With great power comes great responsibility. - Spider-Man",
15+
"I'm Batman. - Batman",
16+
"I am Iron Man. - Iron Man",
17+
"Why so serious? - The Joker",
18+
"I'm always angry. - The Hulk",
19+
}
20+
21+
rand.Seed(time.Now().UnixNano())
22+
23+
for {
24+
quote := quotes[rand.Intn(len(quotes))]
25+
fmt.Println(quote)
26+
time.Sleep(time.Second)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM redis
2+
EXPOSE 6380
3+
COPY redis.conf /usr/local/etc/redis/redis.conf
4+
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

0 commit comments

Comments
 (0)