Example #1
0
        public AciExecutor(RuntimeConfig runtimeConfig)
        {
            if (!(runtimeConfig is AciConfig))
            {
                throw new ArgumentException("AciExecutor can only accept AciConfig as runtime config");
            }

            this.aciConfig = runtimeConfig as AciConfig;
            this.ValidateAciConfig(this.aciConfig);
        }
Example #2
0
        public string Run(string image, RuntimeConfig config)
        {
            var resourceGroup      = this.GetResourceGroup();
            var containerGroupName = $"metaparticle-exec-{DateTime.UtcNow.Ticks}";

            var containers = new Container[]
            {
                new Container(
                    name: containerGroupName,
                    image: image,
                    resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0)),
                    environmentVariables: new List <EnvironmentVariable>
                {
                    new EnvironmentVariable(name: "METAPARTICLE_IN_CONTAINER", value: "true")
                },
                    ports: config.Ports?.Select(p => new ContainerPort(p)).ToList())
            };

            var containerGroup = new ContainerGroup(
                name: containerGroupName,
                osType: OperatingSystemTypes.Linux,
                location: resourceGroup.Location,
                ipAddress: config.Public
                    ? new IpAddress(config.Ports?.Select(p => new Port(p, ContainerNetworkProtocol.TCP)).ToList())
                    : null,
                containers: containers
                );

            var containerInstanceClient = this.GetContainerInstanceClient();

            var createdContainerGroup = containerInstanceClient.ContainerGroups.CreateOrUpdate(
                resourceGroupName: this.aciConfig.AciResourceGroup,
                containerGroupName: containerGroupName,
                containerGroup: containerGroup);

            Console.WriteLine(createdContainerGroup.Id);
            return(containerGroupName);
        }