0

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.

Arcalise76
  • 56
  • 7

1 Answers1

1

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

Daredevil
  • 732
  • 5
  • 13
  • Yes i saw that class. My registry is contained to azure and has no system or user identity. From the azure portal i can still assign the registry to my container app. My question is, how do i accomplish the same thing with the resourcemanager sdk – Arcalise76 Aug 06 '23 at 16:10
  • 1
    Your container app needs a security context to connect to Azure Container Registry. It can either be a managed identity or Admin credentials. Above example is for using managed identity. If you want to use admin credentials on container registry, you will have to enable admin credentials on container registry and then you can use Username and PasswordSecretRef properties of ContainerAppRegistryCredentials class. – Daredevil Aug 06 '23 at 19:36
  • I do have admin credentials enabled. What would I put as the identity for that? – Arcalise76 Aug 07 '23 at 12:58
  • PasswordSecretRef The name of the Secret that contains the registry login password. Server Container Registry Server. Username Container Registry Username. – Daredevil Aug 07 '23 at 14:26