/**
         * Azure Container Instance sample for managing container groups with private image repositories.
         *  - Create an Azure Container Registry to be used for holding the Docker images
         *  - If a local Docker engine cannot be found, create a Linux virtual machine that will host a Docker engine
         *      to be used for this sample
         *  - Use Docker DotNet to create a Docker client that will push an image to Azure Container Registry
         *  - Create a new container group with one container instance from the image that was pushed in the registry
         */
        public static void RunSample(IAzure azure)
        {
            string rgName              = SdkContext.RandomResourceName("rgACI", 15);
            string acrName             = SdkContext.RandomResourceName("acr", 20);
            string aciName             = SdkContext.RandomResourceName("acisample", 20);
            string saName              = SdkContext.RandomResourceName("sa", 20);
            string dockerImageName     = "microsoft/aci-helloworld";
            string dockerImageTag      = "latest";
            string dockerContainerName = "sample-hello";

            try
            {
                //=============================================================
                // Create an Azure Container Registry to store and manage private Docker container images

                Utilities.Log("Creating an Azure Container Registry");

                IRegistry azureRegistry = azure.ContainerRegistries.Define(acrName)
                                          .WithRegion(region)
                                          .WithNewResourceGroup(rgName)
                                          .WithBasicSku()
                                          .WithRegistryNameAsAdminUser()
                                          .Create();

                Utilities.Print(azureRegistry);

                var acrCredentials = azureRegistry.GetCredentials();

                //=============================================================
                // Create a Docker client that will be used to push/pull images to/from the Azure Container Registry

                using (DockerClient dockerClient = DockerUtils.CreateDockerClient(azure, rgName, region))
                {
                    var pullImgResult = dockerClient.Images.PullImage(
                        new Docker.DotNet.Models.ImagesPullParameters()
                    {
                        Parent = dockerImageName,
                        Tag    = dockerImageTag
                    },
                        new Docker.DotNet.Models.AuthConfig());

                    Utilities.Log("List Docker images for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listImages = dockerClient.Images.ListImages(
                        new Docker.DotNet.Models.ImagesListParameters()
                    {
                        All = true
                    });
                    foreach (var img in listImages)
                    {
                        Utilities.Log("\tFound image " + img.RepoTags[0] + " (id:" + img.ID + ")");
                    }

                    var createContainerResult = dockerClient.Containers.CreateContainer(
                        new Docker.DotNet.Models.CreateContainerParameters()
                    {
                        Name  = dockerContainerName,
                        Image = dockerImageName + ":" + dockerImageTag
                    });
                    Utilities.Log("List Docker containers for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listContainers = dockerClient.Containers.ListContainers(
                        new Docker.DotNet.Models.ContainersListParameters()
                    {
                        All = true
                    });
                    foreach (var container in listContainers)
                    {
                        Utilities.Log("\tFound container " + container.Names[0] + " (id:" + container.ID + ")");
                    }

                    //=============================================================
                    // Commit the new container

                    string privateRepoUrl = azureRegistry.LoginServerUrl + "/" + dockerContainerName;
                    Utilities.Log("Commiting image at: " + privateRepoUrl);

                    var commitContainerResult = dockerClient.Miscellaneous.CommitContainerChanges(
                        new Docker.DotNet.Models.CommitContainerChangesParameters()
                    {
                        ContainerID    = dockerContainerName,
                        RepositoryName = privateRepoUrl,
                        Tag            = dockerImageTag
                    });

                    //=============================================================
                    // Push the new Docker image to the Azure Container Registry

                    var pushImageResult = dockerClient.Images.PushImage(privateRepoUrl,
                                                                        new Docker.DotNet.Models.ImagePushParameters()
                    {
                        ImageID = privateRepoUrl,
                        Tag     = dockerImageTag
                    },
                                                                        new Docker.DotNet.Models.AuthConfig()
                    {
                        Username      = acrCredentials.Username,
                        Password      = acrCredentials.AccessKeys[AccessKeyType.Primary],
                        ServerAddress = azureRegistry.LoginServerUrl
                    });

                    //=============================================================
                    // Create a container group with one container instance of default CPU core count and memory size
                    //   using public Docker image "microsoft/aci-helloworld" and mounts a new file share as read/write
                    //   shared container volume.

                    IContainerGroup containerGroup = azure.ContainerGroups.Define(aciName)
                                                     .WithRegion(region)
                                                     .WithNewResourceGroup(rgName)
                                                     .WithLinux()
                                                     .WithPrivateImageRegistry(azureRegistry.LoginServerUrl, acrCredentials.Username, acrCredentials.AccessKeys[AccessKeyType.Primary])
                                                     .WithoutVolume()
                                                     .DefineContainerInstance(aciName)
                                                     .WithImage(privateRepoUrl)
                                                     .WithExternalTcpPort(80)
                                                     .Attach()
                                                     .Create();

                    Utilities.Print(containerGroup);

                    //=============================================================
                    // Check the container instance logs

                    SdkContext.DelayProvider.Delay(15000);

                    string logContent = containerGroup.GetLogContent(aciName);
                    Utilities.Log($"Logs for container instance: {aciName}\n{logContent}");
                }
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                    Utilities.Log("Deleted Resource Group: " + rgName);
                }
                catch (Exception)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
            }
        }
예제 #2
0
        /**
         * Azure Container Registry sample for managing container registry.
         *  - Create an Azure Container Registry to be used for holding the Docker images
         *  - If a local Docker engine cannot be found, create a Linux virtual machine that will host a Docker engine
         *      to be used for this sample
         *  - Use Docker DotNet to create a Docker client that will push/pull an image to/from Azure Container Registry
         *  - Pull a test image from the public Docker repo (hello-world:latest) to be used as a sample for pushing/pulling
         *      to/from an Azure Container Registry
         *  - Create a new Docker container from an image that was pulled from Azure Container Registry
         */
        public static void RunSample(IAzure azure)
        {
            string rgName              = SdkContext.RandomResourceName("rgACR", 15);
            string acrName             = SdkContext.RandomResourceName("acrsample", 20);
            string saName              = SdkContext.RandomResourceName("sa", 20);
            Region region              = Region.USEast2;
            string dockerImageName     = "hello-world";
            string dockerImageTag      = "latest";
            string dockerContainerName = "sample-hello";
            string dockerImageRelPath  = "samplesdotnet";

            try
            {
                //=============================================================
                // Create an Azure Container Registry to store and manage private Docker container images

                Utilities.Log("Creating an Azure Container Registry");

                IRegistry azureRegistry = azure.ContainerRegistries.Define(acrName)
                                          .WithRegion(region)
                                          .WithNewResourceGroup(rgName)
                                          .WithBasicSku()
                                          .WithRegistryNameAsAdminUser()
                                          .Create();

                Utilities.Print(azureRegistry);

                var acrCredentials = azureRegistry.GetCredentials();

                //=============================================================
                // Create a Docker client that will be used to push/pull images to/from the Azure Container Registry

                using (DockerClient dockerClient = DockerUtils.CreateDockerClient(azure, rgName, region))
                {
                    var pullImgResult = dockerClient.Images.PullImage(
                        new Docker.DotNet.Models.ImagesPullParameters()
                    {
                        Parent = dockerImageName,
                        Tag    = dockerImageTag
                    },
                        new Docker.DotNet.Models.AuthConfig());

                    Utilities.Log("List Docker images for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listImages = dockerClient.Images.ListImages(
                        new Docker.DotNet.Models.ImagesListParameters()
                    {
                        All = true
                    });
                    foreach (var img in listImages)
                    {
                        Utilities.Log("\tFound image " + img.RepoTags[0] + " (id:" + img.ID + ")");
                    }

                    var createContainerResult = dockerClient.Containers.CreateContainer(
                        new Docker.DotNet.Models.CreateContainerParameters()
                    {
                        Name  = dockerContainerName,
                        Image = dockerImageName + ":" + dockerImageTag
                    });
                    Utilities.Log("List Docker containers for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listContainers = dockerClient.Containers.ListContainers(
                        new Docker.DotNet.Models.ContainersListParameters()
                    {
                        All = true
                    });
                    foreach (var container in listContainers)
                    {
                        Utilities.Log("\tFound container " + container.Names[0] + " (id:" + container.ID + ")");
                    }

                    //=============================================================
                    // Commit the new container

                    string privateRepoUrl = azureRegistry.LoginServerUrl + "/" + dockerImageRelPath + "/" + dockerContainerName;
                    Utilities.Log("Commiting image at: " + privateRepoUrl);

                    var commitContainerResult = dockerClient.Miscellaneous.CommitContainerChanges(
                        new Docker.DotNet.Models.CommitContainerChangesParameters()
                    {
                        ContainerID    = dockerContainerName,
                        RepositoryName = privateRepoUrl,
                        Tag            = dockerImageTag
                    });

                    //=============================================================
                    // Push the new Docker image to the Azure Container Registry

                    var pushImageResult = dockerClient.Images.PushImage(privateRepoUrl,
                                                                        new Docker.DotNet.Models.ImagePushParameters()
                    {
                        ImageID = privateRepoUrl,
                        Tag     = dockerImageTag
                    },
                                                                        new Docker.DotNet.Models.AuthConfig()
                    {
                        Username      = acrCredentials.Username,
                        Password      = acrCredentials.AccessKeys[AccessKeyType.Primary],
                        ServerAddress = azureRegistry.LoginServerUrl
                    });

                    //=============================================================
                    // Verify that the image we saved in the Azure Container registry can be pulled and instantiated locally

                    var pullAcrImgResult = dockerClient.Images.PullImage(
                        new Docker.DotNet.Models.ImagesPullParameters()
                    {
                        Parent = privateRepoUrl,
                        Tag    = dockerImageTag
                    },
                        new Docker.DotNet.Models.AuthConfig()
                    {
                        Username      = acrCredentials.Username,
                        Password      = acrCredentials.AccessKeys[AccessKeyType.Primary],
                        ServerAddress = azureRegistry.LoginServerUrl
                    });

                    Utilities.Log("List Docker images for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    listImages = dockerClient.Images.ListImages(
                        new Docker.DotNet.Models.ImagesListParameters()
                    {
                        All = true
                    });
                    foreach (var img in listImages)
                    {
                        Utilities.Log("\tFound image " + img.RepoTags[0] + " (id:" + img.ID + ")");
                    }

                    var createAcrContainerResult = dockerClient.Containers.CreateContainer(
                        new Docker.DotNet.Models.CreateContainerParameters()
                    {
                        Name  = dockerContainerName + "fromazure",
                        Image = privateRepoUrl + ":" + dockerImageTag
                    });

                    Utilities.Log("List Docker containers for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    listContainers = dockerClient.Containers.ListContainers(
                        new Docker.DotNet.Models.ContainersListParameters()
                    {
                        All = true
                    });
                    foreach (var container in listContainers)
                    {
                        Utilities.Log("\tFound container " + container.Names[0] + " (id:" + container.ID + ")");
                    }
                }
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                    Utilities.Log("Deleted Resource Group: " + rgName);
                }
                catch (Exception)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
            }
        }
예제 #3
0
        public void ContainerRegistryCRUD()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                var       regName         = TestUtilities.GenerateName("acr");
                var       regName1        = TestUtilities.GenerateName("acr") + "1";
                var       regName2        = TestUtilities.GenerateName("acr") + "2";
                var       rgName          = "rg" + regName;
                var       saName          = "sa" + regName;
                var       webhookName1    = "webhookbing1";
                var       webhookName2    = "webhookbing2";
                var       registryManager = TestHelper.CreateRegistryManager();
                var       resourceManager = TestHelper.CreateResourceManager();
                IRegistry registry1       = null;
                IRegistry registry2       = null;

                try
                {
                    registry1 = registryManager.ContainerRegistries.Define(regName1)
                                .WithRegion(Region.USWestCentral)
                                .WithNewResourceGroup(rgName)
                                .WithClassicSku()
                                .WithNewStorageAccount(saName)
                                .WithRegistryNameAsAdminUser()
                                .WithTag("tag1", "value1")
                                .Create();

                    Assert.True(registry1.AdminUserEnabled);
                    Assert.Equal(registry1.StorageAccountName, saName);

                    var regs = registryManager.ContainerRegistries.List();
                    Assert.True(regs.Count() > 0);

                    IRegistryCredentials registryCredentials1 = registry1.GetCredentials();
                    Assert.NotNull(registryCredentials1);
                    Assert.Equal(regName1, registryCredentials1.Username);
                    Assert.Equal(2, registryCredentials1.AccessKeys.Count);

                    Assert.Empty(registry1.Webhooks.List());

                    registry2 = registryManager.ContainerRegistries.Define(regName2)
                                .WithRegion(Region.USWestCentral)
                                .WithExistingResourceGroup(rgName)
                                .WithBasicSku()
                                .WithRegistryNameAsAdminUser()
                                .DefineWebhook(webhookName1)
                                .WithTriggerWhen(WebhookAction.Push, WebhookAction.Delete)
                                .WithServiceUri("https://www.bing.com")
                                .WithRepositoriesScope("")
                                .WithTag("tag", "value")
                                .WithCustomHeader("name", "value")
                                .Attach()
                                .DefineWebhook(webhookName2)
                                .WithTriggerWhen(WebhookAction.Push)
                                .WithServiceUri("https://www.bing.com")
                                .Enabled(false)
                                .WithRepositoriesScope("")
                                .WithTag("tag", "value")
                                .WithCustomHeader("name", "value")
                                .Attach()
                                .WithTag("tag1", "value1")
                                .Create();

                    Assert.True(registry2.AdminUserEnabled);

                    IRegistryCredentials registryCredentials2 = registry2.GetCredentials();
                    Assert.NotNull(registryCredentials2);

                    Assert.Equal(regName2, registryCredentials2.Username);
                    Assert.Equal(2, registryCredentials2.AccessKeys.Count);

                    Assert.True(registry2.Webhooks.List().Count() == 2);

                    IWebhook webhook = registry2.Webhooks.Get(webhookName1);
                    Assert.True(webhook.IsEnabled());
                    Assert.True(webhook.Tags.ContainsKey("tag"));
                    Assert.Equal("https://www.bing.com", webhook.ServiceUri());
                    Assert.Equal(2, webhook.Triggers().Count);

                    webhook = registryManager.ContainerRegistries.Webhooks.Get(rgName, regName2, webhookName2);
                    Assert.False(webhook.IsEnabled());
                    Assert.True(webhook.Tags.ContainsKey("tag"));
                    Assert.Equal("https://www.bing.com", webhook.ServiceUri());
                    Assert.Equal(1, webhook.Triggers().Count);
                    Assert.Equal(WebhookAction.Push, webhook.Triggers().First());

                    IRegistry registry3 = registryManager.ContainerRegistries.GetById(webhook.ParentId());

                    registry2 = registry3.Update()
                                .WithoutWebhook(webhookName1)
                                .DefineWebhook("webhookms")
                                .WithTriggerWhen(WebhookAction.Push, WebhookAction.Delete)
                                .WithServiceUri("https://www.microsoft.com")
                                .WithRepositoriesScope("")
                                .Enabled(true)
                                .Attach()
                                .UpdateWebhook(webhookName2)
                                .WithServiceUri("https://www.bing.com/maps")
                                .WithTriggerWhen(WebhookAction.Delete)
                                .WithCustomHeader("name", "value")
                                .WithoutTag("tag")
                                .WithTag("tag2", "value2")
                                .Parent()
                                .WithStandardSku()
                                .WithoutTag("tag1")
                                .WithTag("tag2", "value2")
                                .Apply();

                    Assert.True(registry2.Tags.ContainsKey("tag2"));
                    Assert.False(registry2.Tags.ContainsKey("tag1"));

                    webhook = registry2.Webhooks.Get(webhookName2);
                    Assert.False(webhook.IsEnabled());
                    Assert.False(webhook.Tags.ContainsKey("tag"));
                    Assert.True(webhook.Tags.ContainsKey("tag2"));
                    Assert.Equal("https://www.bing.com/maps", webhook.ServiceUri());
                    Assert.Equal(1, webhook.Triggers().Count);
                    Assert.Equal(WebhookAction.Delete, webhook.Triggers().First());

                    webhook.Refresh();
                    webhook.Enable();

                    webhook.Update()
                    .Enabled(false)
                    .WithServiceUri("https://www.msn.com")
                    .WithTriggerWhen(WebhookAction.Push)
                    .WithCustomHeader("header1", "value1")
                    .WithoutTag("tag2")
                    .WithTag("tag3", "value3")
                    .Apply();

                    Assert.False(webhook.IsEnabled());
                    Assert.False(webhook.Tags.ContainsKey("tag2"));
                    Assert.True(webhook.Tags.ContainsKey("tag3"));
                    Assert.Equal("https://www.msn.com", webhook.ServiceUri());
                    Assert.Equal(1, webhook.Triggers().Count);
                    Assert.Equal(WebhookAction.Push, webhook.Triggers().First());

                    webhook.Ping();
                    Assert.NotEmpty(webhook.ListEvents());

                    registry2.Webhooks.Delete(webhookName2);
                }
                finally
                {
                    try
                    {
                        resourceManager.ResourceGroups.BeginDeleteByName(rgName);
                    }
                    catch { }
                }
            }
        }
        /**
         * Azure App Service sample for deploying from an Azure Container Registry.
         *    - Create an Azure Container Registry to be used for holding the Docker images
         *    - If a local Docker engine cannot be found, create a Linux virtual machine that will host a Docker engine
         *        to be used for this sample
         *    - Use Docker Java to create a Docker client that will push/pull an image to/from Azure Container Registry
         *    - Pull a test image from the public Docker repo (tomcat:8-jre8) to be used as a sample for pushing/pulling
         *        to/from an Azure Container Registry
         *    - Deploys to a new web app from the Tomcat image
         */

        public static void RunSample(IAzure azure)
        {
            string rgName              = SdkContext.RandomResourceName("rgACR", 15);
            string acrName             = SdkContext.RandomResourceName("acrsample", 20);
            string saName              = SdkContext.RandomResourceName("sa", 20);
            string appName             = SdkContext.RandomResourceName("webapp", 20);
            string appUrl              = appName + ".azurewebsites.net";
            Region region              = Region.USWest;
            string dockerImageName     = "tomcat";
            string dockerImageTag      = "8-jre8";
            string dockerContainerName = "tomcat-privates";

            try
            {
                //=============================================================
                // Create an Azure Container Registry to store and manage private Docker container images

                Utilities.Log("Creating an Azure Container Registry");

                IRegistry azureRegistry = azure.ContainerRegistries.Define(acrName)
                                          .WithRegion(region)
                                          .WithNewResourceGroup(rgName)
                                          .WithBasicSku()
                                          .WithRegistryNameAsAdminUser()
                                          .Create();

                Utilities.Print(azureRegistry);

                var acrCredentials = azureRegistry.GetCredentials();

                //=============================================================
                // Create a Docker client that will be used to push/pull images to/from the Azure Container Registry

                using (DockerClient dockerClient = DockerUtils.CreateDockerClient(azure, rgName, region))
                {
                    var pullImgResult = dockerClient.Images.PullImage(
                        new Docker.DotNet.Models.ImagesPullParameters()
                    {
                        Parent = dockerImageName,
                        Tag    = dockerImageTag
                    },
                        new Docker.DotNet.Models.AuthConfig());

                    Utilities.Log("List Docker images for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listImages = dockerClient.Images.ListImages(
                        new Docker.DotNet.Models.ImagesListParameters()
                    {
                        All = true
                    });
                    foreach (var img in listImages)
                    {
                        Utilities.Log("\tFound image " + img.RepoTags[0] + " (id:" + img.ID + ")");
                    }

                    var createContainerResult = dockerClient.Containers.CreateContainer(
                        new Docker.DotNet.Models.CreateContainerParameters()
                    {
                        Name  = dockerContainerName,
                        Image = dockerImageName + ":" + dockerImageTag
                    });
                    Utilities.Log("List Docker containers for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listContainers = dockerClient.Containers.ListContainers(
                        new Docker.DotNet.Models.ContainersListParameters()
                    {
                        All = true
                    });
                    foreach (var container in listContainers)
                    {
                        Utilities.Log("\tFound container " + container.Names[0] + " (id:" + container.ID + ")");
                    }

                    //=============================================================
                    // Commit the new container

                    string privateRepoUrl = azureRegistry.LoginServerUrl + "/samples/" + dockerContainerName;
                    Utilities.Log("Commiting image at: " + privateRepoUrl);

                    var commitContainerResult = dockerClient.Miscellaneous.CommitContainerChanges(
                        new Docker.DotNet.Models.CommitContainerChangesParameters()
                    {
                        ContainerID    = dockerContainerName,
                        RepositoryName = privateRepoUrl,
                        Tag            = "latest"
                    });

                    //=============================================================
                    // Push the new Docker image to the Azure Container Registry

                    var pushImageResult = dockerClient.Images.PushImage(privateRepoUrl,
                                                                        new Docker.DotNet.Models.ImagePushParameters()
                    {
                        ImageID = privateRepoUrl,
                        Tag     = "latest"
                    },
                                                                        new Docker.DotNet.Models.AuthConfig()
                    {
                        Username      = acrCredentials.Username,
                        Password      = acrCredentials.AccessKeys[AccessKeyType.Primary],
                        ServerAddress = azureRegistry.LoginServerUrl
                    });

                    //============================================================
                    // Create a web app with a new app service plan

                    Utilities.Log("Creating web app " + appName + " in resource group " + rgName + "...");

                    IWebApp app = azure.WebApps.Define(appName)
                                  .WithRegion(Region.USWest)
                                  .WithExistingResourceGroup(rgName)
                                  .WithNewLinuxPlan(PricingTier.StandardS1)
                                  .WithPrivateRegistryImage(privateRepoUrl + ":latest", "http://" + azureRegistry.LoginServerUrl)
                                  .WithCredentials(acrCredentials.Username, acrCredentials.AccessKeys[AccessKeyType.Primary])
                                  .WithAppSetting("PORT", "8080")
                                  .Create();

                    Utilities.Log("Created web app " + app.Name);
                    Utilities.Print(app);

                    // warm up
                    Utilities.Log("Warming up " + appUrl + "...");
                    Utilities.CheckAddress("http://" + appUrl);
                    SdkContext.DelayProvider.Delay(5000);
                    Utilities.Log("CURLing " + appUrl + "...");
                    Utilities.Log(Utilities.CheckAddress("http://" + appUrl));
                }
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                    Utilities.Log("Deleted Resource Group: " + rgName);
                }
                catch (Exception)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
            }
        }
예제 #5
0
        /**
         * Azure Container Registry sample for managing container registry with webhooks.
         *    - Create an Azure Container Registry and setup couple Webhooks to be triggered on registry related actions (push, delete)
         *  - If a local Docker engine cannot be found, create a Linux virtual machine that will host a Docker engine
         *      to be used for this sample
         *  - Use Docker DotNet to create a Docker client that will push/pull an image to/from Azure Container Registry
         *  - Pull a test image from the public Docker repo (hello-world:latest) to be used as a sample for pushing/pulling
         *      to/from an Azure Container Registry
         *    - List the container registry webhook event notifications after pushing a container image to the registry
         */
        public static void RunSample(IAzure azure)
        {
            string rgName              = SdkContext.RandomResourceName("rgACR", 15);
            string acrName             = SdkContext.RandomResourceName("acrsample", 20);
            string saName              = SdkContext.RandomResourceName("sa", 20);
            Region region              = Region.USEast2;
            string dockerImageName     = "hello-world";
            string dockerImageTag      = "latest";
            string dockerContainerName = "sample-hello";
            string dockerImageRelPath  = "samplesdotnet";
            string webhookName1        = "webhookbing1";
            string webhookName2        = "webhookbing2";
            string webhookServiceUri1  = "https://www.bing.com";
            string webhookServiceUri2  = "https://www.bing.com";

            try
            {
                //=============================================================
                // Create an Azure Container Registry to store and manage private Docker container images

                Utilities.Log("Creating an Azure Container Registry");

                IRegistry azureRegistry = azure.ContainerRegistries.Define(acrName)
                                          .WithRegion(region)
                                          .WithNewResourceGroup(rgName)
                                          .WithBasicSku()
                                          .WithRegistryNameAsAdminUser()
                                          .DefineWebhook(webhookName1)
                                          .WithTriggerWhen(WebhookAction.Push, WebhookAction.Delete)
                                          .WithServiceUri(webhookServiceUri1)
                                          .WithTag("tag", "value")
                                          .WithCustomHeader("name", "value")
                                          .Attach()
                                          .DefineWebhook(webhookName2)
                                          .WithTriggerWhen(WebhookAction.Push)
                                          .WithServiceUri(webhookServiceUri2)
                                          .Enabled(false)
                                          .WithRepositoriesScope("")
                                          .Attach()
                                          .WithTag("tag1", "value1")
                                          .Create();

                Utilities.Print(azureRegistry);

                //=============================================================
                // Ping the container registry webhook to validate it works as expected

                IWebhook webhook = azureRegistry.Webhooks.Get(webhookName1);
                webhook.Ping();
                var webhookEvents = webhook.ListEvents();
                Utilities.Log($"Found {webhookEvents.Count()} webhook events for: {webhook.Name} with container service: {azureRegistry.Name}/n");
                foreach (var webhookEventInfo in webhookEvents)
                {
                    Utilities.Log($"\t{webhookEventInfo.EventResponseMessage.Content}");
                }


                //=============================================================
                // Create a Docker client that will be used to push/pull images to/from the Azure Container Registry

                var acrCredentials = azureRegistry.GetCredentials();

                using (DockerClient dockerClient = DockerUtils.CreateDockerClient(azure, rgName, region))
                {
                    var pullImgResult = dockerClient.Images.PullImage(
                        new Docker.DotNet.Models.ImagesPullParameters()
                    {
                        Parent = dockerImageName,
                        Tag    = dockerImageTag
                    },
                        new Docker.DotNet.Models.AuthConfig());

                    Utilities.Log("List Docker images for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listImages = dockerClient.Images.ListImages(
                        new Docker.DotNet.Models.ImagesListParameters()
                    {
                        All = true
                    });
                    foreach (var img in listImages)
                    {
                        Utilities.Log("\tFound image " + img.RepoTags[0] + " (id:" + img.ID + ")");
                    }

                    var createContainerResult = dockerClient.Containers.CreateContainer(
                        new Docker.DotNet.Models.CreateContainerParameters()
                    {
                        Name  = dockerContainerName,
                        Image = dockerImageName + ":" + dockerImageTag
                    });
                    Utilities.Log("List Docker containers for: " + dockerClient.Configuration.EndpointBaseUri.AbsoluteUri);
                    var listContainers = dockerClient.Containers.ListContainers(
                        new Docker.DotNet.Models.ContainersListParameters()
                    {
                        All = true
                    });
                    foreach (var container in listContainers)
                    {
                        Utilities.Log("\tFound container " + container.Names[0] + " (id:" + container.ID + ")");
                    }

                    //=============================================================
                    // Commit the new container

                    string privateRepoUrl = azureRegistry.LoginServerUrl + "/" + dockerImageRelPath + "/" + dockerContainerName;
                    Utilities.Log("Commiting image at: " + privateRepoUrl);

                    var commitContainerResult = dockerClient.Miscellaneous.CommitContainerChanges(
                        new Docker.DotNet.Models.CommitContainerChangesParameters()
                    {
                        ContainerID    = dockerContainerName,
                        RepositoryName = privateRepoUrl,
                        Tag            = dockerImageTag
                    });

                    //=============================================================
                    // Push the new Docker image to the Azure Container Registry

                    var pushImageResult = dockerClient.Images.PushImage(privateRepoUrl,
                                                                        new Docker.DotNet.Models.ImagePushParameters()
                    {
                        ImageID = privateRepoUrl,
                        Tag     = dockerImageTag
                    },
                                                                        new Docker.DotNet.Models.AuthConfig()
                    {
                        Username      = acrCredentials.Username,
                        Password      = acrCredentials.AccessKeys[AccessKeyType.Primary],
                        ServerAddress = azureRegistry.LoginServerUrl
                    });

                    //=============================================================
                    // Gets the container registry webhook after pushing a container image and lists the event notifications

                    webhook       = azureRegistry.Webhooks.Get(webhookName1);
                    webhookEvents = webhook.ListEvents();
                    Utilities.Log($"Found {webhookEvents.Count()} webhook events for: {webhook.Name} with container service: {azureRegistry.Name}/n");
                    foreach (var webhookEventInfo in webhookEvents)
                    {
                        Utilities.Log($"\t{webhookEventInfo.EventResponseMessage.Content}");
                    }
                }
            }
            finally
            {
                try
                {
                    Utilities.Log("Deleting Resource Group: " + rgName);
                    azure.ResourceGroups.BeginDeleteByName(rgName);
                    Utilities.Log("Deleted Resource Group: " + rgName);
                }
                catch (Exception)
                {
                    Utilities.Log("Did not create any resources in Azure. No clean up is necessary");
                }
            }
        }