Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DockerResourceConfiguration" /> class.
 /// </summary>
 /// <param name="dockerEndpointAuthenticationConfiguration">The Docker endpoint authentication configuration.</param>
 /// <param name="labels">A list of labels.</param>
 public DockerResourceConfiguration(
     IDockerEndpointAuthenticationConfiguration dockerEndpointAuthenticationConfiguration = null,
     IReadOnlyDictionary <string, string> labels = null)
 {
     this.DockerEndpointAuthConfig = dockerEndpointAuthenticationConfiguration;
     this.Labels = labels;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestcontainersVolumeConfiguration" /> class.
 /// </summary>
 /// <param name="dockerEndpointAuthenticationConfiguration">The Docker endpoint authentication configuration.</param>
 /// <param name="name">The name.</param>
 /// <param name="labels">A list of labels.</param>
 public TestcontainersVolumeConfiguration(
     IDockerEndpointAuthenticationConfiguration dockerEndpointAuthenticationConfiguration = null,
     string name = null,
     IReadOnlyDictionary <string, string> labels = null)
     : base(dockerEndpointAuthenticationConfiguration, labels)
 {
     this.Name = name;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestcontainersClient" /> class.
 /// </summary>
 /// <param name="dockerEndpointAuthConfig">The Docker endpoint authentication configuration.</param>
 /// <param name="logger">The logger.</param>
 public TestcontainersClient(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger)
     : this(
         new DockerContainerOperations(dockerEndpointAuthConfig, logger),
         new DockerImageOperations(dockerEndpointAuthConfig, logger),
         new DockerSystemOperations(dockerEndpointAuthConfig, logger),
         new DockerRegistryAuthenticationProvider(logger))
 {
 }
Ejemplo n.º 4
0
 protected DockerApiClient(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig)
 {
     this.Docker = Clients.GetOrAdd(dockerEndpointAuthConfig.Endpoint, _ =>
     {
         using (var dockerClientConfiguration = dockerEndpointAuthConfig.GetDockerClientConfiguration())
         {
             return(dockerClientConfiguration.CreateClient());
         }
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestcontainersNetworkConfiguration" /> class.
 /// </summary>
 /// <param name="dockerEndpointAuthenticationConfiguration">The Docker endpoint authentication configuration.</param>
 /// <param name="name">The name.</param>
 /// <param name="driver">The driver.</param>
 /// <param name="labels">A list of labels.</param>
 public TestcontainersNetworkConfiguration(
     IDockerEndpointAuthenticationConfiguration dockerEndpointAuthenticationConfiguration = null,
     string name          = null,
     NetworkDriver driver = default,
     IReadOnlyDictionary <string, string> labels = null)
     : base(dockerEndpointAuthenticationConfiguration, labels)
 {
     this.Name   = name;
     this.Driver = driver;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageFromDockerfileConfiguration" /> class.
 /// </summary>
 /// <param name="dockerEndpointAuthenticationConfiguration">The Docker endpoint authentication configuration.</param>
 /// <param name="image">The Docker image.</param>
 /// <param name="dockerfile">The Dockerfile.</param>
 /// <param name="dockerfileDirectory">The Dockerfile directory.</param>
 /// <param name="deleteIfExists">A value indicating whether an existing image is removed or not.</param>
 /// <param name="labels">A list of labels.</param>
 public ImageFromDockerfileConfiguration(
     IDockerEndpointAuthenticationConfiguration dockerEndpointAuthenticationConfiguration = null,
     IDockerImage image         = null,
     string dockerfile          = null,
     string dockerfileDirectory = null,
     bool deleteIfExists        = true,
     IReadOnlyDictionary <string, string> labels = null)
     : base(dockerEndpointAuthenticationConfiguration, labels)
 {
     this.Image               = image;
     this.Dockerfile          = dockerfile;
     this.DockerfileDirectory = dockerfileDirectory;
     this.DeleteIfExists      = deleteIfExists;
 }
        private ResourceReaper(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, string ryukImage)
        {
            this.resourceReaperContainer = new TestcontainersBuilder <TestcontainersContainer>()
                                           .WithDockerEndpoint(dockerEndpointAuthConfig ?? TestcontainersSettings.OS.DockerEndpointAuthConfig)
                                           .WithName($"testcontainers-ryuk-{sessionId:D}")
                                           .WithImage(ryukImage)
                                           .WithAutoRemove(true)
                                           .WithCleanUp(false)
                                           .WithExposedPort(RyukPort)
                                           .WithPortBinding(RyukPort, true)
                                           .WithBindMount("/var/run/docker.sock", "/var/run/docker.sock", AccessMode.ReadOnly)
                                           .Build();

            this.SessionId = sessionId;
        }
        public static async Task <ResourceReaper> GetAndStartDefaultAsync(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig = null, CancellationToken ct = default)
        {
            if (defaultInstance != null && !defaultInstance.disposed)
            {
                return(defaultInstance);
            }

            await DefaultLock.WaitAsync(ct)
            .ConfigureAwait(false);

            if (defaultInstance != null && !defaultInstance.disposed)
            {
                DefaultLock.Release();
                return(defaultInstance);
            }

            try
            {
                defaultInstance = await GetAndStartNewAsync(DefaultSessionId, dockerEndpointAuthConfig, RyukImage, default, ct)
#pragma warning disable S107

        /// <summary>
        /// Initializes a new instance of the <see cref="TestcontainersConfiguration" /> class.
        /// </summary>
        /// <param name="dockerEndpointAuthenticationConfiguration">The Docker endpoint authentication configuration.</param>
        /// <param name="dockerRegistryAuthenticationConfiguration">The Docker registry authentication configuration.</param>
        /// <param name="image">The Docker image.</param>
        /// <param name="name">The name.</param>
        /// <param name="hostname">The hostname.</param>
        /// <param name="workingDirectory">The working directory.</param>
        /// <param name="entrypoint">The entrypoint.</param>
        /// <param name="command">The command.</param>
        /// <param name="environments">The environment variables.</param>
        /// <param name="labels">The labels.</param>
        /// <param name="exposedPorts">The exposed ports.</param>
        /// <param name="portBindings">The port bindings.</param>
        /// <param name="mounts">The volumes.</param>
        /// <param name="networks">The networks.</param>
        /// <param name="networkAliases">The container network aliases.</param>
        /// <param name="outputConsumer">The output consumer.</param>
        /// <param name="waitStrategies">The wait strategies.</param>
        /// <param name="startupCallback">The startup callback.</param>
        /// <param name="autoRemove">A value indicating whether the Testcontainer is removed by the Docker daemon or not.</param>
        /// <param name="privileged">A value indicating whether the Testcontainer has extended privileges or not.</param>
        public TestcontainersConfiguration(
            IDockerEndpointAuthenticationConfiguration dockerEndpointAuthenticationConfiguration = null,
            IDockerRegistryAuthenticationConfiguration dockerRegistryAuthenticationConfiguration = null,
            IDockerImage image              = null,
            string name                     = null,
            string hostname                 = null,
            string workingDirectory         = null,
            IEnumerable <string> entrypoint = null,
            IEnumerable <string> command    = null,
            IReadOnlyDictionary <string, string> environments = null,
            IReadOnlyDictionary <string, string> labels       = null,
            IReadOnlyDictionary <string, string> exposedPorts = null,
            IReadOnlyDictionary <string, string> portBindings = null,
            IEnumerable <IMount> mounts             = null,
            IEnumerable <IDockerNetwork> networks   = null,
            IEnumerable <string> networkAliases     = null,
            IOutputConsumer outputConsumer          = null,
            IEnumerable <IWaitUntil> waitStrategies = null,
            Func <ITestcontainersContainer, CancellationToken, Task> startupCallback = null,
            bool?autoRemove = null,
            bool?privileged = null)
            : base(dockerEndpointAuthenticationConfiguration, labels)
        {
            this.AutoRemove = autoRemove;
            this.Privileged = privileged;
            this.DockerRegistryAuthConfig = dockerRegistryAuthenticationConfiguration;
            this.Image            = image;
            this.Name             = name;
            this.Hostname         = hostname;
            this.WorkingDirectory = workingDirectory;
            this.Entrypoint       = entrypoint;
            this.Command          = command;
            this.Environments     = environments;
            this.ExposedPorts     = exposedPorts;
            this.PortBindings     = portBindings;
            this.Mounts           = mounts;
            this.Networks         = networks;
            this.NetworkAliases   = networkAliases;
            this.OutputConsumer   = outputConsumer;
            this.WaitStrategies   = waitStrategies;
            this.StartupCallback  = startupCallback;
        }
Ejemplo n.º 10
0
 public DockerContainerOperations(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger)
     : base(dockerEndpointAuthConfig)
 {
     this.logger = logger;
 }
Ejemplo n.º 11
0
 public Windows(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig)
 {
     this.DockerEndpointAuthConfig = dockerEndpointAuthConfig;
 }
 /// <inheritdoc cref="IAbstractBuilder{TBuilderEntity}" />
 public TBuilderEntity WithDockerEndpoint(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig)
 {
     return(this.MergeNewConfiguration(new DockerResourceConfiguration(dockerEndpointAuthenticationConfiguration: dockerEndpointAuthConfig)));
 }
 public DockerSystemOperations(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger)
     : base(dockerEndpointAuthConfig)
 {
     _ = logger;
 }
Ejemplo n.º 14
0
 public DockerImageOperations(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger)
     : base(dockerEndpointAuthConfig)
 {
     this.logger        = logger;
     this.traceProgress = new TraceProgress(logger);
 }