예제 #1
0
        public void TestBuild()
        {
            DockerHealthCheck healthCheck =
                DockerHealthCheck.FromCommand(ImmutableArray.Create("echo", "hi"))
                .SetInterval(Duration.FromNanoseconds(123))
                .SetTimeout(Duration.FromNanoseconds(456))
                .SetStartPeriod(Duration.FromNanoseconds(789))
                .SetRetries(10)
                .Build();

            Assert.IsTrue(healthCheck.GetInterval().IsPresent());
            Assert.AreEqual(Duration.FromNanoseconds(123), healthCheck.GetInterval().Get());
            Assert.IsTrue(healthCheck.GetTimeout().IsPresent());
            Assert.AreEqual(Duration.FromNanoseconds(456), healthCheck.GetTimeout().Get());
            Assert.IsTrue(healthCheck.GetStartPeriod().IsPresent());
            Assert.AreEqual(Duration.FromNanoseconds(789), healthCheck.GetStartPeriod().Get());
            Assert.IsTrue(healthCheck.GetRetries().IsPresent());
            Assert.AreEqual(10, healthCheck.GetRetries().Get());
        }
예제 #2
0
        /**
         * Gets the container configuration as a {@link Blob}.
         *
         * @return the container configuration {@link Blob}
         */
        public ContainerConfigurationTemplate GetContainerConfiguration()
        {
            // ISet up the JSON template.
            ContainerConfigurationTemplate template = new ContainerConfigurationTemplate();

            // Adds the layer diff IDs.
            foreach (ILayer layer in image.GetLayers())
            {
                template.AddLayerDiffId(layer.GetDiffId());
            }

            // Adds the history.
            foreach (HistoryEntry historyObject in image.GetHistory())
            {
                template.AddHistoryEntry(historyObject);
            }

            template.Created      = image.GetCreated()?.ToString();
            template.Architecture = image.GetArchitecture();
            template.Os           = image.GetOs();
            template.SetContainerEnvironment(EnvironmentMapToList(image.GetEnvironment()));
            template.SetContainerEntrypoint(image.GetEntrypoint());
            template.SetContainerCmd(image.GetProgramArguments());
            template.SetContainerExposedPorts(PortSetToMap(image.GetExposedPorts()));
            template.SetContainerVolumes(VolumesSetToMap(image.GetVolumes()));
            template.SetContainerLabels(image.GetLabels());
            template.SetContainerWorkingDir(image.GetWorkingDirectory());
            template.SetContainerUser(image.GetUser());

            // Ignore healthcheck if not Docker/command is empty
            DockerHealthCheck healthCheck = image.GetHealthCheck();

            if (image.GetImageFormat() == ManifestFormat.V22 && healthCheck != null)
            {
                template.SetContainerHealthCheckTest(healthCheck.GetCommand());
                healthCheck
                .GetInterval()
                .IfPresent(interval => template.SetContainerHealthCheckInterval((long)interval.TotalNanoseconds));
                healthCheck
                .GetTimeout()
                .IfPresent(timeout => template.SetContainerHealthCheckTimeout((long)timeout.TotalNanoseconds));
                healthCheck
                .GetStartPeriod()
                .IfPresent(
                    startPeriod => template.SetContainerHealthCheckStartPeriod((long)startPeriod.TotalNanoseconds));
                template.SetContainerHealthCheckRetries(healthCheck.GetRetries().AsNullable());
            }

            return(template);
        }