-
Notifications
You must be signed in to change notification settings - Fork 857
Expose Dockerfile builder APIs to polyglot apphosts #15867
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
Open
sebastienros
wants to merge
3
commits into
main
Choose a base branch
from
sebros/issue-15858-dockerfile-polyglot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #pragma warning disable ASPIREDOCKERFILEBUILDER001 // Type is for evaluation purposes only and is subject to change or removal in future updates. | ||
|
|
||
| using Aspire.Hosting.ApplicationModel; | ||
| using Aspire.Hosting.ApplicationModel.Docker; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Aspire.Hosting.Ats; | ||
|
|
||
| /// <summary> | ||
| /// ATS exports for the Dockerfile builder DSL. | ||
| /// </summary> | ||
| internal static class DockerfileBuilderExports | ||
| { | ||
| [AspireExport("dockerfileBuilderArg", MethodName = "arg", Description = "Adds a global ARG statement to the Dockerfile")] | ||
| public static DockerfileBuilder Arg(this DockerfileBuilder builder, string name, string? defaultValue = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| return defaultValue is null ? builder.Arg(name) : builder.Arg(name, defaultValue); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileBuilderFrom", MethodName = "from", Description = "Adds a FROM statement to start a Dockerfile stage")] | ||
| public static DockerfileStage From(this DockerfileBuilder builder, string image, string? stageName = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| return stageName is null ? builder.From(image) : builder.From(image, stageName); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileStageArg", MethodName = "arg", Description = "Adds an ARG statement to a Dockerfile stage")] | ||
| public static DockerfileStage Arg(this DockerfileStage stage, string name, string? defaultValue = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
|
|
||
| return defaultValue is null ? stage.Arg(name) : stage.Arg(name, defaultValue); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds a WORKDIR statement to a Dockerfile stage")] | ||
| public static DockerfileStage WorkDir(this DockerfileStage stage, string path) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.WorkDir(path); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileStageRun", MethodName = "run", Description = "Adds a RUN statement to a Dockerfile stage")] | ||
| public static DockerfileStage Run(this DockerfileStage stage, string command) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Run(command); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileStageCopy", MethodName = "copy", Description = "Adds a COPY statement to a Dockerfile stage")] | ||
| public static DockerfileStage Copy(this DockerfileStage stage, string source, string destination, string? chown = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
|
|
||
| return chown is null ? stage.Copy(source, destination) : stage.Copy(source, destination, chown); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileStageCopyFrom", MethodName = "copyFrom", Description = "Adds a COPY --from statement to a Dockerfile stage")] | ||
| public static DockerfileStage CopyFrom(this DockerfileStage stage, string from, string source, string destination, string? chown = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
|
|
||
| return chown is null ? stage.CopyFrom(from, source, destination) : stage.CopyFrom(from, source, destination, chown); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds an ENV statement to a Dockerfile stage")] | ||
| public static DockerfileStage Env(this DockerfileStage stage, string name, string value) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Env(name, value); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds an EXPOSE statement to a Dockerfile stage")] | ||
| public static DockerfileStage Expose(this DockerfileStage stage, int port) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Expose(port); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds a CMD statement to a Dockerfile stage")] | ||
| public static DockerfileStage Cmd(this DockerfileStage stage, string[] command) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Cmd(command); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds an ENTRYPOINT statement to a Dockerfile stage")] | ||
| public static DockerfileStage Entrypoint(this DockerfileStage stage, string[] command) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Entrypoint(command); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds a RUN statement with mounts to a Dockerfile stage")] | ||
| public static DockerfileStage RunWithMounts(this DockerfileStage stage, string command, string[] mounts) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.RunWithMounts(command, mounts); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds a USER statement to a Dockerfile stage")] | ||
| public static DockerfileStage User(this DockerfileStage stage, string user) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.User(user); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds an empty line to a Dockerfile stage")] | ||
| public static DockerfileStage EmptyLine(this DockerfileStage stage) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.EmptyLine(); | ||
| } | ||
|
|
||
| [AspireExport(Description = "Adds a comment to a Dockerfile stage")] | ||
| public static DockerfileStage Comment(this DockerfileStage stage, string comment) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| return stage.Comment(comment); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileBuilderAddContainerFilesStages", MethodName = "addContainerFilesStages", Description = "Adds Dockerfile stages for published container files")] | ||
| public static DockerfileBuilder AddContainerFilesStages(this DockerfileBuilder builder, IResource resource, ILogger? logger = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentNullException.ThrowIfNull(resource); | ||
|
|
||
| return ContainerFilesExtensions.AddContainerFilesStages(builder, resource, logger); | ||
| } | ||
|
|
||
| [AspireExport("dockerfileStageAddContainerFiles", MethodName = "addContainerFiles", Description = "Adds COPY --from statements for published container files")] | ||
| public static DockerfileStage AddContainerFiles(this DockerfileStage stage, IResource resource, string rootDestinationPath, ILogger? logger = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(stage); | ||
| ArgumentNullException.ThrowIfNull(resource); | ||
| ArgumentException.ThrowIfNullOrEmpty(rootDestinationPath); | ||
|
|
||
| return ContainerFilesExtensions.AddContainerFiles(stage, resource, rootDestinationPath, logger); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it safe to use the first here? The PY code below does a bunch of work to merge duplicates together.