private async Task <IWithPrivateImageRegistryOrVolume> Setup() { if (withPublicOrPrivateImageRegistry == null) { var mgr = await Authenticate(); var a = mgr.ContainerGroups.Define(attribute.GroupName).WithRegion(Region.Create(this.attribute.AzureRegion)).WithExistingResourceGroup(attribute.AciResourceGroupName); IWithPublicOrPrivateImageRegistry o = null; if (attribute.OsType == "linux") { o = a.WithLinux(); } else { o = a.WithWindows(); } if (attribute is ContainerGroupWithPrivateRegistryAttribute) { var registry = attribute as ContainerGroupWithPrivateRegistryAttribute; withPublicOrPrivateImageRegistry = o.WithPrivateImageRegistry(registry.ImageRegistryServer, registry.ImageRegistryUser, registry.ImageRegistryPassword); } else { withPublicOrPrivateImageRegistry = o.WithPublicImageRegistryOnly(); } } return(withPublicOrPrivateImageRegistry); }
public async Task AddAsync(Container item, CancellationToken cancellationToken = default(CancellationToken)) { IWithPrivateImageRegistryOrVolume o = await Setup(); var image = o.WithoutVolume().DefineContainerInstance(item.Name).WithImage(item.Image); if (item.Ports.Count == 0) { this.containerInstances = image.WithoutPorts().WithCpuCoreCount(item.Cpu).WithMemorySizeInGB(item.Memory).Attach(); } else { IWithPortsOrContainerInstanceAttach <IWithNextContainerInstance> a = null; foreach (var p in item.Ports.GroupBy(s => new { s.Protocol, s.Public })) { if (p.Key.Public) { if (p.Key.Protocol == Protocol.Tcp) { a = (a ?? image as IWithPorts <IWithNextContainerInstance>).WithExternalTcpPorts(p.Select(s => s.PortNumber).ToArray()); } if (p.Key.Protocol == Protocol.Udp) { a = (a ?? image as IWithPorts <IWithNextContainerInstance>).WithExternalUdpPorts(p.Select(s => s.PortNumber).ToArray()); } } else { if (p.Key.Protocol == Protocol.Tcp) { a = (a ?? image as IWithPorts <IWithNextContainerInstance>).WithInternalTcpPorts(p.Select(s => s.PortNumber).ToArray()); } if (p.Key.Protocol == Protocol.Udp) { a = (a ?? image as IWithPorts <IWithNextContainerInstance>).WithInternalTcpPorts(p.Select(s => s.PortNumber).ToArray()); } } } this.containerInstances = a.WithCpuCoreCount(item.Cpu).WithMemorySizeInGB(item.Memory).WithEnvironmentVariables(item.EnvironmentVariables ?? new Dictionary <string, string>()).Attach(); } }