-
Notifications
You must be signed in to change notification settings - Fork 144
Add automatic Dockerfile generation with version detection for Golang integration #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
fa7b26d
9052215
590c9e0
1e62e49
3acd732
46c54ea
4fb890c
880ac36
65106bf
2ce0835
6897c21
927da41
8c72923
c9ac6c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,10 +68,55 @@ public static IResourceBuilder<GolangAppExecutableResource> AddGolangApp(this ID | |
|
|
||
| return builder.AddResource(resource) | ||
| .WithGolangDefaults() | ||
| .WithArgs([.. allArgs]); | ||
| .WithArgs([.. allArgs]) | ||
| .PublishAsGolangDockerfile(workingDirectory, executable, buildTags); | ||
| } | ||
|
|
||
| private static IResourceBuilder<GolangAppExecutableResource> WithGolangDefaults( | ||
| this IResourceBuilder<GolangAppExecutableResource> builder) => | ||
| builder.WithOtlpExporter(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configures the Golang application to be published as a Dockerfile with automatic multi-stage build generation. | ||
| /// </summary> | ||
| /// <param name="builder">The resource builder.</param> | ||
| /// <param name="workingDirectory">The working directory containing the Golang application.</param> | ||
| /// <param name="executable">The path to the Golang package directory or source file to be executed.</param> | ||
| /// <param name="buildTags">The optional build tags to be used when building the Golang application.</param> | ||
| /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||
| #pragma warning disable ASPIREDOCKERFILEBUILDER001 | ||
| private static IResourceBuilder<GolangAppExecutableResource> PublishAsGolangDockerfile( | ||
| this IResourceBuilder<GolangAppExecutableResource> builder, | ||
| string workingDirectory, | ||
| string executable, | ||
| string[]? buildTags) | ||
| { | ||
| return builder.PublishAsDockerFile(publish => | ||
| { | ||
| publish.WithDockerfileBuilder(workingDirectory, context => | ||
| { | ||
| var buildArgs = new List<string> { "build", "-o", "/app/server" }; | ||
|
|
||
| if (buildTags is { Length: > 0 }) | ||
| { | ||
| buildArgs.Add("-tags"); | ||
| buildArgs.Add(string.Join(",", buildTags)); | ||
| } | ||
|
|
||
| buildArgs.Add(executable); | ||
|
|
||
| var buildStage = context.Builder | ||
| .From("golang:1.23", "builder") | ||
|
||
| .WorkDir("/build") | ||
| .Copy(".", "./") | ||
| .Run(string.Join(" ", ["go", .. buildArgs])); | ||
|
|
||
| context.Builder | ||
| .From("alpine:3.21") | ||
| .CopyFrom(buildStage.StageName!, "/app/server", "/app/server") | ||
| .Entrypoint(["/app/server"]); | ||
| }); | ||
| }); | ||
| } | ||
| #pragma warning restore ASPIREDOCKERFILEBUILDER001 | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.