How to link Azure.ResourceManager.AppContainers with Azure.ResourceManager.ContainerRegistry in container app configuration?

huangapple go评论63阅读模式
英文:

How to link Azure.ResourceManager.AppContainers with Azure.ResourceManager.ContainerRegistry in container app configuration?

问题

我正在尝试将Azure.ResourceManager.AppContainers与Azure.ResourceManager.ContainerRegistry集成,但我不清楚如何一起使用它们。我正在尝试设置容器应用程序配置,并在下面提供了我的代码原型:

// 加载容器注册表
var registries = await arm.GetContainerRegistriesAsync();
// 选择第一个注册表
var registry = registries.First();

// 创建新的容器应用程序配置
var appConfig = new ContainerAppConfiguration()
{
    Ingress =
    {
        AllowInsecure = false,
        TargetPort = service.dockerProfile.InternalPort,
        ExposedPort = service.dockerProfile.ExternalPort,
        Transport = Azure.ResourceManager.AppContainers.Models.ContainerAppIngressTransportMethod.Http,
        External = service.dockerProfile.ExternalPort is not null
    },
    Registries =
    {
        // 我应该如何在这里集成注册表?
    }
};

var container = await arm.CreateContainerApp(service.containerAppName, new(Azure.Core.AzureLocation.SouthCentralUS)
{
    EnvironmentId = environment.Id,
    Configuration = appConfig
});

是否有人遇到类似情况或知道如何正确设置"Registries"部分?我无法找到针对这个特定用例的文档。如果我获得了清晰的解答,我将愿意为文档做出贡献,以帮助将来的其他人。

英文:

I'm trying to integrate Azure.ResourceManager.AppContainers with Azure.ResourceManager.ContainerRegistry but I'm unclear on how to use them together. I'm attempting to set up a container app configuration and have provided a prototype of my code below:

// Load the container registry
var registries = await arm.GetContainerRegistriesAsync();
// Select the first registry
var registry = registries.First();

// Create a new container app configuration
var appConfig = new ContainerAppConfiguration()
{
    Ingress =
    {
        AllowInsecure = false,
        TargetPort = service.dockerProfile.InternalPort,
        ExposedPort = service.dockerProfile.ExternalPort,
        Transport = Azure.ResourceManager.AppContainers.Models.ContainerAppIngressTransportMethod.Http,
        External = service.dockerProfile.ExternalPort is not null
    },
    Registries =
    {
        // How should I integrate the registry here?
    }
};

var container = await arm.CreateContainerApp(service.containerAppName, new(Azure.Core.AzureLocation.SouthCentralUS)
{
    EnvironmentId = environment.Id,
    Configuration = appConfig
});

Has anyone encountered a similar situation or knows how to correctly set up the registries section? I've been unable to find documentation addressing this specific use case. If I get clarity, I'll be happy to contribute to the documentation to assist others in the future.

答案1

得分: 1

你需要创建一个 ContainerAppRegistryCredentials 对象。

以下是一个示例代码,你可以使用它。假设你将使用用户分配的托管标识进行访问设置。

Registries =
{
    new ContainerAppRegistryCredentials()
    {
        Identity = "", // 用户分配的托管标识的资源ID
        Server = registry.Data.LoginServer
    }
}

有关更多详细信息,你可以查看这里的示例,它提供了有关需要创建的对象的良好信息:https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.app/container-app-acr

英文:

You will have to create an ContainerAppRegistryCredentials object.

Following is an example code which you may use. This is assuming you will be setting up access using a user assigned managed identity.

Registries =
            {
    
                new ContainerAppRegistryCredentials()
                {
                    Identity = "",//Resource ID for user assigned managed identity
                    Server = registry.Data.LoginServer
                }
            }

For more details you can follow the example provided for bicep here. It gives good information about objects required to be created. https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.app/container-app-acr

huangapple
  • 本文由 发表于 2023年8月5日 01:33:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838078.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定