Skip to content

Move PublishAsDockerFile to use container resources.#7072

Merged
davidfowl merged 6 commits intomainfrom
davidfowl/publishasdockerfile2
Jan 14, 2025
Merged

Move PublishAsDockerFile to use container resources.#7072
davidfowl merged 6 commits intomainfrom
davidfowl/publishasdockerfile2

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented Jan 11, 2025

Description

This allows full customization of the docker building process and removes a dependency on the limited docker.v0 resource type.

  • Updated DockerfileBuildAnnotation to allow nullable build arguments.
  • Modified WithBuildArg to accept nullable values.
  • Revised tests in ManifestGenerationTests.cs and PublishAsDockerfileTests.cs to align with new behavior.
  • Adjusted SchemaTests.cs to use temporary context paths for Dockerfile testing.

Fixes #4067

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

This allows full customization of the docker builing process and removes a dependency on the limited docker.v0 resource type.

- Updated `DockerfileBuildAnnotation` to allow nullable build arguments.
- Modified `WithBuildArg` to accept nullable values.
- Updated API documentation in `PublicAPI.Shipped.txt` and `PublicAPI.Unshipped.txt`.
- Revised tests in `ManifestGenerationTests.cs` and `PublishAsDockerfileTests.cs` to align with new behavior.
- Adjusted `SchemaTests.cs` to use temporary context paths for Dockerfile testing.

Fixes #4067
@davidfowl davidfowl requested a review from mitchdenny as a code owner January 11, 2025 20:42
@davidfowl davidfowl requested review from JamesNK, eerhardt and sebastienros and removed request for mitchdenny January 11, 2025 20:42
@davidfowl davidfowl added this to the 9.1 milestone Jan 11, 2025
@davidfowl davidfowl added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 11, 2025
- Updated the ExecutableReference's manifest writer even though the resource gets removed from the list.
- Updated tests (including the python tests)
Comment thread tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs Outdated
Comment thread tests/Aspire.Hosting.Tests/Schema/SchemaTests.cs Outdated
Comment thread src/Aspire.Hosting/ExecutableResourceBuilderExtensions.cs Outdated
}
var container = new ExecutableContainerResource(builder.Resource);
var cb = builder.ApplicationBuilder.AddResource(container);
cb.WithImage(builder.Resource.Name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, why do we need to call WithImage when we call WithDockerfile? Is that just to name the image that will be produced?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah you need aan image name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    System.InvalidOperationException : The resource 'foo' does not have a container image specified. Use WithImage to specify the container image and tag.

Copy link
Copy Markdown
Member

@eerhardt eerhardt Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah - it's because of the ORDER of the calls above. If you change WithDockerfile to:

        return builder.WithAnnotation(annotation, ResourceAnnotationMutationBehavior.Replace)
                      .WithImage(imageName)
                      .WithImageRegistry(registry: null)
                      .WithImageTag("latest");

it will work. WithImageRegistry is throwing because it can't find the ContainerImageAnnotation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fix WithDockerfile.

The current proposed code is confusing because you are going to get a different Image name that what is being specified here - since WithDockerfile is going to overwrite it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think the code you are adding in this PR is confusing. But I'm not going to block on it.

Comment thread tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs
Comment thread tests/Aspire.Hosting.Tests/PublishAsDockerfileTests.cs Outdated
Comment thread src/Aspire.Hosting/ExecutableResourceBuilderExtensions.cs Outdated
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
@davidfowl
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl davidfowl merged commit 4baaa4d into main Jan 14, 2025
@davidfowl davidfowl deleted the davidfowl/publishasdockerfile2 branch January 14, 2025 04:08
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change PublishAsDockerFile to use a ContainerResource

2 participants