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

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

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

问题

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

  1. // 加载容器注册表
  2. var registries = await arm.GetContainerRegistriesAsync();
  3. // 选择第一个注册表
  4. var registry = registries.First();
  5. // 创建新的容器应用程序配置
  6. var appConfig = new ContainerAppConfiguration()
  7. {
  8. Ingress =
  9. {
  10. AllowInsecure = false,
  11. TargetPort = service.dockerProfile.InternalPort,
  12. ExposedPort = service.dockerProfile.ExternalPort,
  13. Transport = Azure.ResourceManager.AppContainers.Models.ContainerAppIngressTransportMethod.Http,
  14. External = service.dockerProfile.ExternalPort is not null
  15. },
  16. Registries =
  17. {
  18. // 我应该如何在这里集成注册表?
  19. }
  20. };
  21. var container = await arm.CreateContainerApp(service.containerAppName, new(Azure.Core.AzureLocation.SouthCentralUS)
  22. {
  23. EnvironmentId = environment.Id,
  24. Configuration = appConfig
  25. });

是否有人遇到类似情况或知道如何正确设置"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:

  1. // Load the container registry
  2. var registries = await arm.GetContainerRegistriesAsync();
  3. // Select the first registry
  4. var registry = registries.First();
  5. // Create a new container app configuration
  6. var appConfig = new ContainerAppConfiguration()
  7. {
  8. Ingress =
  9. {
  10. AllowInsecure = false,
  11. TargetPort = service.dockerProfile.InternalPort,
  12. ExposedPort = service.dockerProfile.ExternalPort,
  13. Transport = Azure.ResourceManager.AppContainers.Models.ContainerAppIngressTransportMethod.Http,
  14. External = service.dockerProfile.ExternalPort is not null
  15. },
  16. Registries =
  17. {
  18. // How should I integrate the registry here?
  19. }
  20. };
  21. var container = await arm.CreateContainerApp(service.containerAppName, new(Azure.Core.AzureLocation.SouthCentralUS)
  22. {
  23. EnvironmentId = environment.Id,
  24. Configuration = appConfig
  25. });

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 对象。

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

  1. Registries =
  2. {
  3. new ContainerAppRegistryCredentials()
  4. {
  5. Identity = "", // 用户分配的托管标识的资源ID
  6. Server = registry.Data.LoginServer
  7. }
  8. }

有关更多详细信息,你可以查看这里的示例,它提供了有关需要创建的对象的良好信息: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.

  1. Registries =
  2. {
  3. new ContainerAppRegistryCredentials()
  4. {
  5. Identity = "",//Resource ID for user assigned managed identity
  6. Server = registry.Data.LoginServer
  7. }
  8. }

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:

确定