public static async Task CreateImageAsync()
        {
            SystemPath root      = imageLocation.GetRoot().ToPath();
            SystemPath fileA     = Files.CreateFile(root.Resolve("fileA.txt"));
            SystemPath fileB     = Files.CreateFile(root.Resolve("fileB.txt"));
            SystemPath fileC     = Files.CreateFile(root.Resolve("fileC.txt"));
            SystemPath subdir    = Files.CreateDirectory(root.Resolve("dir"));
            SystemPath subsubdir = Files.CreateDirectory(subdir.Resolve("subdir"));

            Files.CreateFile(subdir.Resolve("fileD.txt"));
            Files.CreateFile(subsubdir.Resolve("fileE.txt"));

            imageTar = new FileInfo(Path.Combine(imageLocation.GetRoot().FullName, "image.tar"));
            Containerizer containerizer =
                Containerizer.To(TarImage.Named("fibdotnet-core/reproducible").SaveTo(imageTar.ToPath()));

            await FibContainerBuilder.FromScratch()
            .SetEntrypoint("echo", "Hello World")
            .AddLayer(ImmutableArray.Create(fileA), AbsoluteUnixPath.Get("/app"))
            // layer with out-of-order files
            .AddLayer(ImmutableArray.Create(fileC, fileB), "/app")
            .AddLayer(
                LayerConfiguration.CreateBuilder()
                .AddEntryRecursive(subdir, AbsoluteUnixPath.Get("/app"))
                .Build())
            .ContainerizeAsync(containerizer).ConfigureAwait(false);
        }
Esempio n. 2
0
        public virtual void StartMiniKdc()
        {
            // This setting below is required. If not enabled, UGI will abort
            // any attempt to loginUserFromKeytab.
            Configuration conf = new Configuration();

            conf.Set(CommonConfigurationKeys.HadoopSecurityAuthentication, "kerberos");
            UserGroupInformation.SetConfiguration(conf);
            workDir = folder.GetRoot();
            kdc     = new MiniKdc(MiniKdc.CreateConf(), workDir);
            kdc.Start();
        }
Esempio n. 3
0
        public async Task TestToBlob_reproducibilityAsync()
        {
            SystemPath testRoot = temporaryFolder.GetRoot().ToPath();
            SystemPath root1    = Files.CreateDirectories(testRoot.Resolve("files1"));
            SystemPath root2    = Files.CreateDirectories(testRoot.Resolve("files2"));

            // TODO: Currently this test only covers variation in order and modified time, even though
            // TODO: the code is designed to clean up userid/groupid, this test does not check that yet.
            const string contentA = "abcabc";
            SystemPath   fileA1   = CreateFile(root1, "fileA", contentA, 10000);
            SystemPath   fileA2   = CreateFile(root2, "fileA", contentA, 20000);
            const string contentB = "yumyum";
            SystemPath   fileB1   = CreateFile(root1, "fileB", contentB, 10000);
            SystemPath   fileB2   = CreateFile(root2, "fileB", contentB, 20000);

            // check if modified times are off
            Assert.AreNotEqual(Files.GetLastModifiedTime(fileA1), Files.GetLastModifiedTime(fileA2));
            Assert.AreNotEqual(Files.GetLastModifiedTime(fileB1), Files.GetLastModifiedTime(fileB2));

            // create layers of exact same content but ordered differently and with different timestamps
            IBlob layer =
                new ReproducibleLayerBuilder(
                    ImmutableArray.Create(
                        DefaultLayerEntry(fileA1, AbsoluteUnixPath.Get("/somewhere/fileA")),
                        DefaultLayerEntry(fileB1, AbsoluteUnixPath.Get("/somewhere/fileB"))))
                .Build();
            IBlob reproduced =
                new ReproducibleLayerBuilder(
                    ImmutableArray.Create(
                        DefaultLayerEntry(fileB2, AbsoluteUnixPath.Get("/somewhere/fileB")),
                        DefaultLayerEntry(fileA2, AbsoluteUnixPath.Get("/somewhere/fileA"))))
                .Build();

            byte[] layerContent = await Blobs.WriteToByteArrayAsync(layer).ConfigureAwait(false);

            byte[] reproducedLayerContent = await Blobs.WriteToByteArrayAsync(reproduced).ConfigureAwait(false);

            Assert.AreEqual(layerContent, reproducedLayerContent);
        }
Esempio n. 4
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());
        }