dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

Containers: support specifying a prefix to the container repository #36595

Open tmds opened 12 months ago

tmds commented 12 months ago

The container tooling will derive a name for the image based on the assembly name, and that name can be overridden by setting the ContainerRepository property.

When pushing to an image registry the name needs to be prefixed to have separate namespaces for users, apps, ...

This request is to have a property separate from ContainerRepository that allows to set this prefix.

Suggested name: ContainerRepositoryBase.

Example

in the csproj:

<ContainerRepository>frontend</ContainerRepository>

Publish with ContainerRepositoryBase set:

dotnet publish /p:PublishProfile=DefaultContainer /p:ContainerRegistry=quay.io /p:ContainerRepositoryBase=tmds/webstore

This publishes quay.io/tmds/webstore/frontend.

cc @baronfel

baronfel commented 12 months ago

This is a good request, and one that some users have asked for, especially with repositories like GitHub Packages that use a username or project name as a 'namespace'.

We should do this, but consider more names for the proposed new placeholder - for example ContainerNamespace or something. ContainerRepositoryBase is the most technically correct, I just wonder about what users will look for/expect.

jdevillard commented 1 month ago

I'm the same requirement,

seeing that is not close I suppose it's not available right now , so for those who are interested in this , here is a tips.

You can modify your csproj with :

<Target Name="SetContainerRepositoryBase" DependsOnTargets="$(PublishContainerDependsOn)" BeforeTargets="PublishContainer">
    <PropertyGroup>
        <ContainerRepository Condition=" '$(ContainerRepositoryBase)'!='' ">$(ContainerRepositoryBase)/$(ContainerRepository)</ContainerRepository>
    </PropertyGroup>
</Target>

and use the property in the cli :

dotnet publish --os linux --arch x64 -p ContainerRepositoryBase=MyPrefix /t:PublishContainer