public async Task <int> Handle(CreatePulumiCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var x = await Deployment.RunAsync(() =>
                {
                    var network = new Network(request.StackInfo.Network.Name);
                    var image   = new Pulumi.Docker.RemoteImage(request.OsInfo.Title, new Pulumi.Docker.RemoteImageArgs
                    {
                        Name = $"{request.OsInfo.ImageName}:{request.OsInfo.Version}"
                    });

                    var container = new Pulumi.Docker.Container(request.OsInfo.Title, new Pulumi.Docker.ContainerArgs
                    {
                        Image = image.Latest,
                    });
                    foreach (var item in request.StackInfo.Items)
                    {
                        var imageItem = new Pulumi.Docker.RemoteImage(item.Title, new Pulumi.Docker.RemoteImageArgs
                        {
                            Name = $"{item.ImageName}:latest",
                        });

                        var containerItem = new Pulumi.Docker.Container(request.OsInfo.Title, new Pulumi.Docker.ContainerArgs
                        {
                            Image = imageItem.Latest,
                            Envs  = item.Variables.Select(x => new InputList <string>
                            {
                                x.Name, x.Value
                            }).ToString() ?? string.Empty,
                        });
                    }
                });

                return(x);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #2
0
    public MyStack()
    {
        const int    RedisPort = 6379;
        const string RedisHost = "redisdb";

        var network = new Docker.Network("network");

        var redisImage = new Docker.RemoteImage("RedisImage", new Docker.RemoteImageArgs {
            Name        = "redis:6.2",
            KeepLocally = true
        });

        var redisContainer = new Docker.Container("RedisContainer", new Docker.ContainerArgs
        {
            Image = redisImage.Latest,
            Ports = new InputList <Docker.Inputs.ContainerPortArgs> {
                new Docker.Inputs.ContainerPortArgs
                {
                    Internal = RedisPort,
                    External = RedisPort
                }
            },
            NetworksAdvanced = new InputList <Docker.Inputs.ContainerNetworksAdvancedArgs> {
                new Docker.Inputs.ContainerNetworksAdvancedArgs
                {
                    Name    = network.Name,
                    Aliases = new InputList <string> {
                        RedisHost
                    }
                }
            }
        });

        var appImage = new Docker.Image("AppImage", new Docker.ImageArgs
        {
            Build = new Docker.DockerBuild
            {
                Context = "../App"
            },
            ImageName = "app",
            SkipPush  = true
        });

        var appContainer = new Docker.Container("AppContainer", new Docker.ContainerArgs
        {
            Image = appImage.BaseImageName,
            Ports = new InputList <Docker.Inputs.ContainerPortArgs> {
                new Docker.Inputs.ContainerPortArgs
                {
                    Internal = 80,
                    External = 8080
                }
            },
            Envs = new InputList <string> {
                $"REDIS_HOST={RedisHost}",
                $"REDIS_PORT={RedisPort}"
            },
            NetworksAdvanced = new InputList <Docker.Inputs.ContainerNetworksAdvancedArgs> {
                new Docker.Inputs.ContainerNetworksAdvancedArgs
                {
                    Name = network.Name
                }
            }
        }, new CustomResourceOptions
        {
            DependsOn = redisContainer
        });

        this.Url = Output.Create("http://localhost:8080/Cache");
    }