Beispiel #1
0
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .AddContainer("my-nginx", "nginx")
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
        }
Beispiel #2
0
        public static async Task Main(string[] args)
        {
            await using var dockerEnvironment = new DockerEnvironmentBuilder()
                                                .AddMongoContainer("mongo")
                                                .Build();

            await dockerEnvironment.Up();

            var mongoContainer = dockerEnvironment.GetContainer <MongoContainer>("mongo");

            var host = CreateHostBuilder(args, mongoContainer.GetConnectionString()).Build();

            await InitializeDatabaseWithData(host);

            await host.RunAsync();

            await dockerEnvironment.Down();
        }
Beispiel #3
0
        static async Task Execute()
        {
            using (var environment = new DockerEnvironmentBuilder()
                                     .AddContainer(
                       "postgres",
                       "postgres", "10.7",
                       environmentVariables: new Dictionary <string, string>
            {
                { "POSTGRES_USER", "otdev" },
                { "POSTGRES_PASSWORD", "letmein" },
                { "POSTGRES_DB", "offersdb" }
            })
                                     .Build())
            {
                await environment.Up();

                var container = environment.GetContainer("postgres");

                Console.WriteLine("Container Info");
                Console.WriteLine(JsonConvert.SerializeObject(container, Formatting.Indented));
                var connectionString = $"Database=offersdb; User Id=otdev; Password=letmein;Server=localhost; Port={container.Ports.First().Value};";
                Console.WriteLine(connectionString);

                using (var conn = new NpgsqlConnection(connectionString))
                {
                    conn.Execute("CREATE TABLE Data ( id integer primary key, name text );");
                    conn.Open();
                    using (var trx = conn.BeginTransaction())
                    {
                        conn.Execute("CREATE INDEX CONCURRENTLY ix_name ON Data (name)");
                    }
                    conn.Execute("INSERT INTO Data (id, name) VALUES (1, 'Test')");
                    var data = conn.Query <TestData>("select * from Test");
                    foreach (var item in data)
                    {
                        Console.WriteLine(JsonConvert.SerializeObject(item, Formatting.Indented));
                    }
                }

                await environment.Down();
            }
        }
Beispiel #4
0
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
                              .AddContainer("my-nginx", "nginx")
#if DEBUG
                              .AddElasticsearchContainer("my-elastic", reuseContainer: true)
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0", environmentVariables: new Dictionary <string, string> {
                ["MSSQL_COLLATION"] = "SQL_Latin1_General_CP1_CS_AS"
            }, reuseContainer: true)
#else
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
#endif
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

#if !DEBUG
            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
#endif
        }
        public async Task CreateDockerEnvironment()
        {
            // Create the environment using builder pattern
            var environment = new DockerEnvironmentBuilder()
                              .UseDefaultNetwork()
                              .SetName("test-env")
                              .AddContainer("my-nginx", "nginx")
#if DEBUG
                              .AddElasticsearchContainer("my-elastic", ports: new Dictionary <ushort, ushort> {
                [9200] = 9200
            }, reuseContainer: true)
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0", environmentVariables: new Dictionary <string, string> {
                ["MSSQL_COLLATION"] = "SQL_Latin1_General_CP1_CS_AS"
            }, reuseContainer: true)
                              .AddMariaDBContainer("my-maria", "my-secret-pw", reuseContainer: true)
                              .AddMongoContainer("my-mongo", reuseContainer: true)
                              .AddMailContainer("my-mail", reuseContainer: true)
                              .AddFtpContainer("my-ftp", "superuser", "test", ports: Enumerable.Range(30000, 10).ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort> {
                [21] = 21
            }), reuseContainer: true)
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080), reuseContainer: true)
                              .AddPostgresContainer("my-postgres", reuseContainer: true)
#else
                              .AddElasticsearchContainer("my-elastic")
                              .AddMssqlContainer("my-mssql", "HelloK11tt_0")
                              .AddMariaDBContainer("my-maria", "my-secret-pw")
                              .AddMongoContainer("my-mongo")
                              .AddMailContainer("my-mail")
                              .AddFromDockerfile("from-file", "Dockerfile", containerWaiter: new HttpContainerWaiter("/", httpPort: 8080))
                              .AddFtpContainer("my-ftp", "superuser", "test", ports: Enumerable.Range(30000, 10).ToDictionary(p => (ushort)p, p => (ushort)p).MergeDictionaries(new Dictionary <ushort, ushort> {
                [21] = 21
            }))
                              .AddPostgresContainer("my-postgres")
#endif
                              .Build();

            // Up it.
            await environment.Up();

            // Play with containers.
            var mssql = environment.GetContainer <MssqlContainer>("my-mssql");

            await PrintMssqlVersion(mssql);

            var elastic = environment.GetContainer <ElasticsearchContainer>("my-elastic");

            await PrintElasticsearchVersion(elastic);

            var mongo = environment.GetContainer <MongoContainer>("my-mongo");

            PrintMongoVersion(mongo);

            var staticFilesContainer = environment.GetContainer("from-file");

            await PrintReturnedHtml(staticFilesContainer);

            var maria = environment.GetContainer <MariaDBContainer>("my-maria");

            await PrintMariaDBVersion(maria);

            var ftp = environment.GetContainer <FtpContainer>("my-ftp");

            await PrintFtpServerType(ftp);

            var mail = environment.GetContainer <MailContainer>("my-mail");

            await PrintSmtpCapabilities(mail);

            var postgres = environment.GetContainer <PostgresContainer>("my-postgres");

            await PrintPostgresDbVersion(postgres);

#if !DEBUG
            // Down it.
            await environment.Down();

            // Dispose (remove).
            environment.Dispose();
#endif
        }