Skip to content
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

Add support for starting the application through CMD (instead of ENTRYPOINT). #33037

Merged
merged 10 commits into from
Jun 21, 2023

Conversation

tmds
Copy link
Member

@tmds tmds commented Jun 5, 2023

The new ContainerAppCommand and ContainerAppCommandArgs properties are used to hold the command line to start the application.

The ContainerAppCommandInstruction controls how the command line is emitted.

The default behavior is to emit an ENTRYPOINT when the base image has no ENTRYPOINT, and a CMD when the base image has an ENTRYPOINT (to use the base image ENTRYPOINT).

This also adds a ContainerCmd property, which can be used to directly set the image CMD.

Fixes dotnet/sdk-container-builds#398.

…YPOINT).

The new ContainerAppCommand and ContainerAppCommandArgs properties are used to hold
the command line to start the application.

The ContainerAppCommandInstruction controls how the command line is emitted.

The default behavior is to emit an ENTRYPOINT when the base image has no ENTRYPOINT,
and a CMD when the base image has an ENTRYPOINT (to use the base image ENTRYPOINT).

This also adds a ContainerCmd property, which can be used to directly set the image CMD.
@tmds tmds requested a review from a team as a code owner June 5, 2023 15:01
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jun 5, 2023
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@tmds
Copy link
Member Author

tmds commented Jun 5, 2023

@baronfel this is a WIP, it outlines most of the implementation. I want to share what I have so we can do an early feedback round. ptal.

/// <summary>
/// Looks up a localized string similar to CONTAINER2006: Unknown AppCommandInstruction &apos;{0}&apos;. Valid instructions are {1}..
/// </summary>
internal static string UnknownAppCommandInstruction {
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added this manually again.

Maybe it only works on Windows?

@baronfel when you run the top-level build script on Windows, does it update this file with new strings?

@baronfel
Copy link
Member

baronfel commented Jun 7, 2023

Sorry, finally getting to this. Will take a look this afternoon and give feedback.

@tmds tmds changed the title [WIP] Add support for starting the application through CMD (instead of ENTRYPOINT). Add support for starting the application through CMD (instead of ENTRYPOINT). Jun 8, 2023
@tmds
Copy link
Member Author

tmds commented Jun 8, 2023

Sorry, finally getting to this. Will take a look this afternoon and give feedback.

Take your time. I got just got it in a state that is good for a review.

I'll extend the unit test with some more cases, I don't have any other changes in mind currently.

if (baseImageEntrypoint.Length > 0)
{
Log.LogWarningWithCodeFromResources(nameof(Strings.BaseEntrypointOverwritten));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Rather than change between Entrypoint and Cmd based on the presence of a base entrypoint, for deterministic behavior, I've opted to prefer Entrypoint and print a warning if the base image defines an entrypoint already (as is the case with Red Hat images).

/// <summary>
/// Default arguments passed. These can be overridden by the user when the container is created.
/// </summary>
public ITaskItem[] DefaultArgs { get; set; }
Copy link
Member Author

Choose a reason for hiding this comment

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

This roughly corresponds to what dotnet/sdk-container-builds#11 called ContainerCommand.

@baronfel baronfel added the Area-Containers Related to dotnet SDK containers functionality label Jun 12, 2023
@tmds
Copy link
Member Author

tmds commented Jun 14, 2023

I'll extend the unit test with some more cases, I don't have any other changes in mind currently.

@baronfel I've just extended the test. If you look at it, it should describe well how these different properties combine together to determine the application image Entrypoint and Cmd.

@baronfel
Copy link
Member

Thanks @tmds - this LGTM overall, but I'm going to wait to merge until Friday. We're going over a batch of the open Containers PRs for detailed review then and I want to make sure the rest of the team is on board with the changes.

Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

Thanks for this - and especially thanks for the suite of tests illustrating the different scenarios.

@baronfel baronfel merged commit eb08fc9 into dotnet:main Jun 21, 2023
@@ -240,4 +242,108 @@ public void Dispose()
{
_cancellationTokenSource.Dispose();
}

internal (string[] entrypoint, string[] cmd) DetermineEntrypointAndCmd(string[]? baseImageEntrypoint)
Copy link
Member

Choose a reason for hiding this comment

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

we need to replicate this logic in the net472 version of the command - the validations there are only looking at EntryPoint/EntrypointArgs and so are breaking after this PR.

Copy link
Member Author

@tmds tmds Jul 3, 2023

Choose a reason for hiding this comment

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

Where is the net472 version implemented?

Copy link
Member

Choose a reason for hiding this comment

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

It's the sibling CreateNewImageToolTask.cs file next to CreateNewImage.cs - this task invokes the containerize exe with CLI variables, but does validation of those variables in its Execute method so that users get good MSBuild diagnostics.

The ToolTask and the 'normal' task share the same Interface.fs partial class, but are conditionally compiled for net472 or net8.0, respectively.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. Shall I look into making the necessary changes?

Copy link
Member

Choose a reason for hiding this comment

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

That would be awesome! I think it would be a matter of

  • pushing this entrypoint-detection method down into the .Interface.cs class
  • Using it in both CreateNewImage tasks separately
  • Emitting the new CLI args for the entrypoint args/command/etc in the ToolTask's 'GenerateCommandLine' method
  • A brief look at emitting nice diagnostics from the ToolTask

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into it. Thanks for the outline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Containers Related to dotnet SDK containers functionality untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support using the base image ENTRYPOINT and starting the application through CMD
2 participants