public void ProcessKillOnCloseWithKillCannotHang() { var command = "powershell -c sleep 10000"; var cs = new ContainerSettings { SandboxPath = sandbox.path, Layers = sandbox.layers, KillOnClose = true, NetworkId = HostComputeService.FindNatNetwork(), }; using (var container = HostComputeService.CreateContainer(id.ToString(), cs)) { container.Start(); var si = new ProcessStartInfo { CommandLine = command, KillOnClose = true, }; var process = container.CreateProcess(si); process.Kill(); Assert.True(Task.Factory.StartNew(() => { process.Dispose(); }).Wait(10000)); container.Shutdown(); } }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public override void Validate() { base.Validate(); if (AzCliVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "AzCliVersion"); } if (ContainerSettings != null) { ContainerSettings.Validate(); } if (ScriptContent != null) { if (ScriptContent.Length > 32000) { throw new ValidationException(ValidationRules.MaxLength, "ScriptContent", 32000); } } if (EnvironmentVariables != null) { foreach (var element in EnvironmentVariables) { if (element != null) { element.Validate(); } } } }
public void RunContainerExit0() { var command = "cmd /c exit"; var cs = new ContainerSettings { SandboxPath = sandbox.path, Layers = sandbox.layers, KillOnClose = true, NetworkId = HostComputeService.FindNatNetwork(), }; using (var container = HostComputeService.CreateContainer(id.ToString(), cs)) { container.Start(); var si = new ProcessStartInfo { CommandLine = command, KillOnClose = false, }; using (var process = container.CreateProcess(si)) { Assert.True(process.WaitForExit(10000), "Process did not exit after 10 seconds"); Assert.Equal(0, process.ExitCode); } container.Shutdown(); } }
public EventStoreContainerConfiguration() { Image = new ImageSettings { Registry = "", // "mcr.microsoft.com", Name = "eventstore/eventstore" }; Container = new ContainerSettings { Name = "es-integrationtest", PortBindings = new[] { new PortBinding { HostPort = 2113, GuestPort = 2113 }, new PortBinding { HostPort = 1113, GuestPort = 1113 } } }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { var endpoint = new Uri("tcp://127.0.0.1:1113"); var settings = ConnectionSettings .Create() .KeepReconnecting() .KeepRetrying() .SetDefaultUserCredentials(new UserCredentials(Username, Password)); var connectionName = $"M={Environment.MachineName},P={Process.GetCurrentProcess().Id},T={DateTimeOffset.UtcNow.Ticks}"; var connection = EventStoreConnection.Create(settings, endpoint, connectionName); await connection.ConnectAsync(); connection.Close(); return(TimeSpan.Zero); } catch (Exception ex) { Console.WriteLine(ex.Message); } //await Task.CompletedTask; return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public MySqlServerContainerConfiguration(MySqlConnectionStringBuilder builder, string password, int hostPort) { Image = new ImageSettings { Registry = "", Name = "mysql", Tag = "5.7" }; Container = new ContainerSettings { Name = "mysql-integrationtest", PortBindings = new[] { new PortBinding { HostPort = hostPort, GuestPort = 3306 } }, EnvironmentVariables = new[] { $"MYSQL_ROOT_PASSWORD={password}", } }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { //await Task.Delay(3000).ConfigureAwait(false); using (var connection = new MySqlConnection(builder.ConnectionString)) { await connection.OpenAsync(); connection.Close(); } return(TimeSpan.Zero); } catch (Exception ex) { Console.WriteLine(ex.Message); } //await Task.CompletedTask; return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public PostgreSqlContainerConfiguration(string connectionString, string username, string password, int hostPort) { Image = new ImageSettings { Registry = "", Name = "postgres", //Tag = "11-alpine" }; Container = new ContainerSettings { Name = "postgres-integrationtest", PortBindings = new[] { new PortBinding { HostPort = hostPort, GuestPort = 5432 } }, EnvironmentVariables = new[] { $"POSTGRES_USER={username}", $"POSTGRES_PASSWORD={password}", } }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { using (var conn = new NpgsqlConnection(connectionString)) { await conn.OpenAsync(); } return(TimeSpan.Zero); } catch (Exception ex) { Console.WriteLine(ex.Message); } //await Task.CompletedTask; return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public SqlServerContainerConfiguration(SqlConnectionStringBuilder builder) { Image = new ImageSettings { Registry = "mcr.microsoft.com", Name = "mssql/server" }; Container = new ContainerSettings { Name = "blobstore-db", PortBindings = new[] { new PortBinding { HostPort = HostPort, GuestPort = 1433 } }, EnvironmentVariables = new[] { "ACCEPT_EULA=Y", $"SA_PASSWORD={Password}" } }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { using (var connection = new SqlConnection(builder.ConnectionString)) { await connection.OpenAsync(); connection.Close(); } return(TimeSpan.Zero); } catch { } return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public MongoDbContainerConfiguration() { Image = new ImageSettings { Registry = "", Name = "mongo" }; Container = new ContainerSettings { Name = "mongo-integrationtest", PortBindings = new[] { new PortBinding { HostPort = 27014, GuestPort = 27017 } }, EnvironmentVariables = new List <string>() { "MONGO_INITDB_ROOT_USERNAME=test", "MONGO_INITDB_ROOT_PASSWORD=test" }.ToArray() }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { var _connectionString = "mongodb://127.0.0.1"; MongoClient dbClient = new MongoClient(_connectionString); return(TimeSpan.Zero); } catch (Exception ex) { Console.WriteLine(ex.Message); } await Task.CompletedTask; return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public MinioContainerConfiguration() { Image = new ImageSettings { Name = "minio/minio" }; Container = new ContainerSettings { Name = "blobstore-s3-minio", Command = new [] { "server", "/data" }, PortBindings = new[] { new PortBinding { HostPort = HostPort, GuestPort = 9000 } }, EnvironmentVariables = new [] { "MINIO_ACCESS_KEY=" + ACCESS_KEY, "MINIO_SECRET_KEY=" + SECRET_KEY } }; WaitUntilAvailable = async attempt => { if (attempt <= 30) { try { using (var client = new AmazonS3Client(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY), S3Config)) { await client.ListBucketsAsync(); } return(TimeSpan.Zero); } catch { } return(TimeSpan.FromSeconds(1)); } throw new TimeoutException( $"The container {Container.Name} did not become available in a timely fashion."); }; }
public void ContainerKillOnCloseCannotHang() { var cs = new ContainerSettings { SandboxPath = sandbox.path, Layers = sandbox.layers, KillOnClose = true, NetworkId = HostComputeService.FindNatNetwork(), }; var container = HostComputeService.CreateContainer(id.ToString(), cs); container.Start(); Assert.True(Task.Factory.StartNew(() => { container.Dispose(); }).Wait(10000)); Assert.ThrowsAny <Exception>(() => { HostComputeService.GetComputeSystem(id.ToString()); }); }
public ContainerOptions() { Container = new ContainerSettings(); Logging = new LogSettings(); Database = new DatabaseSettings(); }
static void Main(string[] args) { try { var parent = args[0]; var path = args[1]; var command = args[2]; var id = Guid.NewGuid(); var layers = new Layer[] { new Layer { Id = id, Path = parent } }; ContainerStorage.CreateSandbox(path, layers); try { Console.Out.WriteLine("creating container"); var cs = new ContainerSettings { SandboxPath = path, Layers = layers, KillOnClose = true, NetworkId = HostComputeService.FindNatNetwork(), }; using (var container = HostComputeService.CreateContainer(id.ToString(), cs)) { Console.Out.WriteLine("starting container"); Console.Out.Flush(); container.Start(); try { var si = new ProcessStartInfo { CommandLine = command, RedirectStandardOutput = true, KillOnClose = true, }; using (var process = container.CreateProcess(si)) { Console.Out.Write(process.StandardOutput.ReadToEnd()); process.WaitForExit(5000); Console.Out.WriteLine("process exited with {0}", process.ExitCode); } } finally { Console.Out.WriteLine("shutting down container"); container.Shutdown(Timeout.Infinite); } } } finally { ContainerStorage.DestroyLayer(path); } } catch (Exception e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); Environment.Exit(1); } }
public DockerService(IDockerClient dockerClient, ILogger <DockerService> logger, IOptions <ContainerSettings> settings) { this.dockerClient = dockerClient; this.logger = logger; this.settings = settings.Value ?? throw new ArgumentNullException(); }
public ContainerAdapter(IServiceProviderFactory <TContainerBuilder> serviceProviderFactory, ContainerSettings <TContainerBuilder> containerSettings) { serviceCollectionAdapter = new ServiceCollectionAdapter(containerSettings.ServiceCollection); serviceProviderAdapter = new Lazy <ServiceProviderAdapter>(() => { locked = true; var containerBuilder = serviceProviderFactory.CreateBuilder(containerSettings.ServiceCollection); foreach (var customConfiguration in containerSettings.ContainerConfigurations) { customConfiguration(containerBuilder); } var serviceProvider = serviceProviderFactory.CreateServiceProvider(containerBuilder); return(new ServiceProviderAdapter(serviceProvider)); }, LazyThreadSafetyMode.ExecutionAndPublication); }
///GENMHASH:E69EAFBE5FEE03FDD5408C54C9FE8D17:CA53B7BE62B1D1854755EDD010D28892 internal ContainerImageSettingsImpl(ContainerSettings inner, BatchAIJobImpl parent) : base(inner) { this.parent = parent; }