コード例 #1
0
        public void TestGetters_default()
        {
            DockerDaemonImage dockerDaemonImage = DockerDaemonImage.Named("docker/daemon/image");

            Assert.AreEqual("docker/daemon/image", dockerDaemonImage.GetImageReference().ToString());
            Assert.AreEqual(Maybe.Empty <SystemPath>(), dockerDaemonImage.GetDockerExecutable());
            Assert.AreEqual(0, dockerDaemonImage.GetDockerEnvironment().Count);
        }
コード例 #2
0
        public void TestGetImageConfiguration_dockerDaemonImage()
        {
            Containerizer containerizer = Containerizer.To(DockerDaemonImage.Named("docker/daemon/image"));

            ImageConfiguration imageConfiguration = containerizer.GetImageConfiguration();

            Assert.AreEqual("docker/daemon/image", imageConfiguration.GetImage().ToString());
            Assert.AreEqual(0, imageConfiguration.GetCredentialRetrievers().Length);
        }
コード例 #3
0
        protected override IContainerizer CreateContainerizer(FibCliConfiguration configuration)
        {
            var dockerImage = DockerDaemonImage.Named(configuration.GetTargetImageReference());

            // if(configuration.TargetImageCredential!=null && !string.IsNullOrEmpty(configuration.TargetImageCredential.UserName)
            //                                              && !string.IsNullOrEmpty(configuration.TargetImageCredential.Password))
            // {
            //     dockerImage.AddCredential(configuration.TargetImageCredential.UserName, configuration.TargetImageCredential.Password);
            // }
            return(Containerizer.To(dockerImage));
        }
コード例 #4
0
        public void TestTo()
        {
            RegistryImage     registryImage     = RegistryImage.Named(ImageReference.Of(null, "repository", null));
            DockerDaemonImage dockerDaemonImage =
                DockerDaemonImage.Named(ImageReference.Of(null, "repository", null));
            TarImage tarImage =
                TarImage.Named(ImageReference.Of(null, "repository", null)).SaveTo(Paths.Get("ignored"));

            VerifyTo(Containerizer.To(registryImage));
            VerifyTo(Containerizer.To(dockerDaemonImage));
            VerifyTo(Containerizer.To(tarImage));
        }
コード例 #5
0
        public void TestGetContainerBuilder_BaseImage()
        {
            LayerConfiguration[] layerConfigurations = new[] { new LayerConfiguration("appLayer", ImmutableArray <LayerEntry> .Empty) };
            var cliConfiguration = new FibCliConfiguration
            {
                ImageFormat = ImageFormat.OCI,
                ImageLayers = layerConfigurations,
                BaseImage   = "reg.io/base-image:tag",
                Entrypoint  = new[] { "Entrypoint" },
                Cmd         = new[] { "Program", "Arguments" },
                Environment = new Dictionary <string, string> {
                    ["Var"] = "Value"
                },
                ImageWorkingDirectory = AbsoluteUnixPath.Get("/working/dir"),
                ImageUser             = "******",
                Ports   = new[] { Port.Tcp(5000) },
                Volumes = new[] { AbsoluteUnixPath.Get("/volume") },
                Labels  = new Dictionary <string, string> {
                    ["Label"] = "data"
                },
                ReproducableBuild = true
            };

            var builder = cliConfiguration.GetContainerBuilder();

            var configuration = builder.ToBuildConfiguration(Containerizer.To(DockerDaemonImage.Named("target-image")));

            Assert.AreEqual(ManifestFormat.OCI, configuration.GetTargetFormat());
            Assert.AreEqual(layerConfigurations, configuration.GetLayerConfigurations());

            ImageConfiguration imageConfiguration = configuration.GetBaseImageConfiguration();

            Assert.AreEqual("reg.io", imageConfiguration.GetImageRegistry());
            Assert.AreEqual("base-image", imageConfiguration.GetImageRepository());
            Assert.AreEqual("tag", imageConfiguration.GetImageTag());

            IContainerConfiguration containerConfiguration = configuration.GetContainerConfiguration();

            Assert.AreEqual(new[] { "Entrypoint" }, containerConfiguration.GetEntrypoint());
            Assert.AreEqual(new[] { "Program", "Arguments" }, containerConfiguration.GetProgramArguments());
            Assert.AreEqual(new Dictionary <string, string> {
                ["Var"] = "Value"
            }, containerConfiguration.GetEnvironmentMap());
            Assert.AreEqual(AbsoluteUnixPath.Get("/working/dir"), containerConfiguration.GetWorkingDirectory());
            Assert.AreEqual("user", containerConfiguration.GetUser());
            Assert.AreEqual(new[] { Port.Tcp(5000) }, containerConfiguration.GetExposedPorts());
            Assert.AreEqual(new[] { AbsoluteUnixPath.Get("/volume") }, containerConfiguration.GetVolumes());
            Assert.AreEqual(new Dictionary <string, string> {
                ["Label"] = "data"
            }, containerConfiguration.GetLabels());
            Assert.AreEqual(ContainerConfiguration.DefaultCreationTime, containerConfiguration.GetCreationTime());
        }
コード例 #6
0
        public void TestConfigureContainerizer_WithAdditonalTags_HandlesNull()
        {
            var config = new FibCliConfiguration
            {
                TargetTags = null
            };

            var containerizer = Containerizer.To(DockerDaemonImage.Named("target-image:tag3"));

            config.ConfigureContainerizer(containerizer);

            Assert.AreEqual(Array.Empty <string>(), containerizer.GetAdditionalTags());
        }
コード例 #7
0
        public void TestConfigureContainerizer_WithAdditonalTags()
        {
            var config = new FibCliConfiguration
            {
                TargetTags = new string[] { "tag1", "tag2" }
            };

            var containerizer = Containerizer.To(DockerDaemonImage.Named("target-image:tag3"));

            config.ConfigureContainerizer(containerizer);

            Assert.AreEqual(new string[] { "tag1", "tag2" }, containerizer.GetAdditionalTags());
        }
コード例 #8
0
        public void TestConfigureContainerizer_SetsApplicationLayersCache()
        {
            var config = new FibCliConfiguration
            {
                ApplicationLayersCacheDirectory = "AppCacheDirectory"
            };

            var containerizer = Containerizer.To(DockerDaemonImage.Named("target-image:tag3"));

            config.ConfigureContainerizer(containerizer);

            Assert.AreEqual("AppCacheDirectory", containerizer.GetApplicationLayersCacheDirectory());
        }
コード例 #9
0
        public void TestConfigureContainerizer_SetsOfflineMode()
        {
            var config = new FibCliConfiguration
            {
                OfflineMode = true
            };

            var containerizer = Containerizer.To(DockerDaemonImage.Named("target-image:tag3"));

            config.ConfigureContainerizer(containerizer);

            Assert.AreEqual(true, containerizer.IsOfflineMode());
        }
コード例 #10
0
        public void TestConfigureContainerizer_SetsAllowInsecureRegistries()
        {
            var config = new FibCliConfiguration
            {
                AllowInsecureRegistries = true
            };

            var containerizer = Containerizer.To(DockerDaemonImage.Named("target-image:tag3"));

            config.ConfigureContainerizer(containerizer);

            Assert.AreEqual(true, containerizer.GetAllowInsecureRegistries());
        }
コード例 #11
0
        public void TestGetters()
        {
            DockerDaemonImage dockerDaemonImage =
                DockerDaemonImage.Named("docker/daemon/image")
                .SetDockerExecutable(Paths.Get("docker/binary"))
                .SetDockerEnvironment(ImmutableDictionary.CreateRange(new Dictionary <string, string> {
                ["key"] = "value"
            }));

            Assert.AreEqual(Paths.Get("docker/binary"), dockerDaemonImage.GetDockerExecutable().Get());
            Assert.AreEqual(ImmutableDictionary.CreateRange(new Dictionary <string, string> {
                ["key"] = "value"
            }), dockerDaemonImage.GetDockerEnvironment());
        }
コード例 #12
0
        public void TestWithAdditionalTag()
        {
            DockerDaemonImage dockerDaemonImage =
                DockerDaemonImage.Named(ImageReference.Of(null, "repository", null));
            Containerizer containerizer = Containerizer.To(dockerDaemonImage);

            containerizer.WithAdditionalTag("tag");
            try
            {
                containerizer.WithAdditionalTag("+invalid+");
                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("invalid tag '+invalid+'", ex.Message);
            }
        }
コード例 #13
0
 protected override IContainerizer CreateContainerizer(ImageReference imageReference)
 {
     return(Containerizer.To(DockerDaemonImage.Named(imageReference)));
 }
コード例 #14
0
        public async Task TestOfflineAsync()
        {
            SystemPath cacheDirectory = cacheFolder.GetRoot().ToPath();

            ImageReference targetImageReferenceOnline =
                ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-online");
            ImageReference targetImageReferenceOffline =
                ImageReference.Of("localhost:5001", "fibdotnet-core", "basic-offline");

            FibContainerBuilder fibContainerBuilder =
                FibContainerBuilder.From("localhost:5001/busybox").SetEntrypoint("echo", "Hello World");

            // Should fail since Fib can't build to registry offline
            try
            {
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(RegistryImage.Named(targetImageReferenceOffline)).SetOfflineMode(true)).ConfigureAwait(false);

                Assert.Fail();
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("Cannot build to a container registry in offline mode", ex.Message);
            }

            // Should fail since Fib hasn't cached the base image yet
            try
            {
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline))
                    .SetBaseImageLayersCache(cacheDirectory)
                    .SetOfflineMode(true)).ConfigureAwait(false);

                Assert.Fail();
            }
            catch (IOException ex)
            {
                Assert.AreEqual(
                    "Cannot run Fib in offline mode; localhost:5001/busybox not found in local Fib cache",
                    ex.Message);
            }
            using (LocalRegistry tempRegistry = new LocalRegistry(5001))
            {
                await tempRegistry.StartAsync().ConfigureAwait(false);

                tempRegistry.PullAndPushToLocal("busybox", "busybox");

                // Run online to cache the base image
                await fibContainerBuilder.ContainerizeAsync(
                    Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOnline))
                    .SetBaseImageLayersCache(cacheDirectory)
                    .SetAllowInsecureRegistries(true)).ConfigureAwait(false);
            }

            // Run again in offline mode, should succeed this time
            await fibContainerBuilder.ContainerizeAsync(
                Containerizer.To(DockerDaemonImage.Named(targetImageReferenceOffline))
                .SetBaseImageLayersCache(cacheDirectory)
                .SetOfflineMode(true)).ConfigureAwait(false);

            // Verify output
            Assert.AreEqual(
                "Hello World\n",
                new Command("docker", "run", "--rm", targetImageReferenceOffline.ToString()).Run());
        }
コード例 #15
0
 private async Task <FibContainer> BuildDockerDaemonImageAsync(
     ImageReference baseImage, ImageReference targetImage, IList <string> additionalTags)
 {
     return(await BuildImageAsync(
                baseImage, Containerizer.To(DockerDaemonImage.Named(targetImage)), additionalTags).ConfigureAwait(false));
 }