예제 #1
0
        public async Task TestPullAsync()
        {
            // Pulls the busybox image.
            localRegistry.PullAndPushToLocal("busybox", "busybox");
            RegistryClient registryClient =
                RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox")
                .SetAllowInsecureRegistries(true)
                .NewRegistryClient();
            V21ManifestTemplate manifestTemplate =
                await registryClient.PullManifestAsync <V21ManifestTemplate>("latest").ConfigureAwait(false);

            DescriptorDigest realDigest = manifestTemplate.GetLayerDigests().First();

            // Pulls a layer BLOB of the busybox image.
            LongAdder totalByteCount = new LongAdder();
            LongAdder expectedSize   = new LongAdder();
            IBlob     pulledBlob     =
                registryClient.PullBlob(
                    realDigest,
                    size =>
            {
                Assert.AreEqual(0, expectedSize.Sum());
                expectedSize.Add(size);
            },
                    totalByteCount.Add);
            BlobDescriptor blobDescriptor = await pulledBlob.WriteToAsync(Stream.Null).ConfigureAwait(false);

            Assert.AreEqual(realDigest, blobDescriptor.GetDigest());
            Assert.IsTrue(expectedSize.Sum() > 0);
            Assert.AreEqual(expectedSize.Sum(), totalByteCount.Sum());
        }
예제 #2
0
        /**
         * Writes a V2.1 manifest for a given image reference.
         *
         * @param imageReference the image reference to store the metadata for
         * @param manifestTemplate the manifest
         */
        public async Task WriteMetadataAsync(IImageReference imageReference, V21ManifestTemplate manifestTemplate)
        {
            SystemPath imageDirectory = cacheStorageFiles.GetImageDirectory(imageReference);

            Files.CreateDirectories(imageDirectory);

            using (LockFile ignored1 = LockFile.Create(imageDirectory.Resolve("lock")))
            {
                await WriteMetadataAsync(manifestTemplate, imageDirectory.Resolve("manifest.json")).ConfigureAwait(false);
            }
        }
        public async Task TestPull_v21Async()
        {
            localRegistry.PullAndPushToLocal("busybox", "busybox");
            RegistryClient registryClient =
                RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox")
                .SetAllowInsecureRegistries(true)
                .NewRegistryClient();
            V21ManifestTemplate manifestTemplate =
                await registryClient.PullManifestAsync <V21ManifestTemplate>("latest").ConfigureAwait(false);

            Assert.AreEqual(1, manifestTemplate.SchemaVersion);
            Assert.IsTrue(manifestTemplate.FsLayers.Count > 0);
        }
예제 #4
0
        public void TestRetrieveManifest_v21()
        {
            SystemPath cacheDirectory = temporaryFolder.NewFolder().ToPath();

            SetupCachedMetadataV21(cacheDirectory);

            CacheStorageFiles  cacheStorageFiles  = new CacheStorageFiles(cacheDirectory);
            CacheStorageReader cacheStorageReader = new CacheStorageReader(cacheStorageFiles);

            V21ManifestTemplate manifestTemplate =
                (V21ManifestTemplate)
                cacheStorageReader
                .RetrieveMetadata(ImageReference.Of("test", "image", "tag"))
                .Get()
                .GetManifest();

            Assert.AreEqual(1, manifestTemplate.SchemaVersion);
        }
예제 #5
0
        public async Task TestWriteMetadata_v21Async()
        {
            SystemPath manifestJsonFile =
                Paths.Get(TestResources.GetResource("core/json/v21manifest.json").ToURI());
            V21ManifestTemplate manifestTemplate =
                JsonTemplateMapper.ReadJsonFromFile <V21ManifestTemplate>(manifestJsonFile);
            ImageReference imageReference = ImageReference.Parse("image.reference/project/thing:tag");

            await new CacheStorageWriter(cacheStorageFiles).WriteMetadataAsync(imageReference, manifestTemplate).ConfigureAwait(false);

            SystemPath savedManifestPath =
                cacheRoot.Resolve("images/image.reference/project/thing!tag/manifest.json");

            Assert.IsTrue(Files.Exists(savedManifestPath));

            V21ManifestTemplate savedManifest =
                JsonTemplateMapper.ReadJsonFromFile <V21ManifestTemplate>(savedManifestPath);

            Assert.AreEqual("amd64", savedManifest.GetContainerConfiguration().Get().Architecture);
        }
예제 #6
0
        public void TestFromJson()
        {
            // Loads the JSON string.
            SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/v21manifest.json").ToURI());

            // Deserializes into a manifest JSON object.
            V21ManifestTemplate manifestJson =
                JsonTemplateMapper.ReadJsonFromFile <V21ManifestTemplate>(jsonFile);

            Assert.AreEqual(
                DescriptorDigest.FromDigest(
                    "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
                manifestJson.FsLayers[0].GetDigest());

            ContainerConfigurationTemplate containerConfiguration =
                manifestJson.GetContainerConfiguration().OrElse(null);

            Assert.AreEqual(
                new[] { "JAVA_HOME=/opt/openjdk", "PATH=/opt/openjdk/bin" },
                containerConfiguration.GetContainerEnvironment());
            Assert.AreEqual(
                new[] { "/opt/openjdk/bin/java" }, containerConfiguration.GetContainerEntrypoint());
        }
예제 #7
0
        public void TestToImage_v21()
        {
            // Loads the JSON string.
            SystemPath jsonFile =
                Paths.Get(TestResources.GetResource("core/json/v21manifest.json").ToURI());

            // Deserializes into a manifest JSON object.
            V21ManifestTemplate manifestTemplate =
                JsonTemplateMapper.ReadJsonFromFile <V21ManifestTemplate>(jsonFile);

            Image image = JsonToImageTranslator.ToImage(manifestTemplate);

            IList <ILayer> layers = image.GetLayers();

            Assert.AreEqual(2, layers.Count);
            Assert.AreEqual(
                DescriptorDigest.FromDigest(
                    "sha256:5bd451067f9ab05e97cda8476c82f86d9b69c2dffb60a8ad2fe3723942544ab3"),
                layers[0].GetBlobDescriptor().GetDigest());
            Assert.AreEqual(
                DescriptorDigest.FromDigest(
                    "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
                layers[1].GetBlobDescriptor().GetDigest());
        }
예제 #8
0
        /**
         * Pulls the base image.
         *
         * @param registryAuthorization authentication credentials to possibly use
         * @param progressEventDispatcher the {@link ProgressEventDispatcher} for emitting {@link
         *     ProgressEvent}s
         * @return the pulled image
         * @throws IOException when an I/O exception occurs during the pulling
         * @throws RegistryException if communicating with the registry caused a known error
         * @throws LayerCountMismatchException if the manifest and configuration contain conflicting layer
         *     information
         * @throws LayerPropertyNotFoundException if adding image layers fails
         * @throws BadContainerConfigurationFormatException if the container configuration is in a bad
         *     format
         */
        private async Task <Image> PullBaseImageAsync(
            Authorization registryAuthorization,
            ProgressEventDispatcher progressEventDispatcher)
        {
            RegistryClient registryClient =
                buildConfiguration
                .NewBaseImageRegistryClientFactory()
                .SetAuthorization(registryAuthorization)
                .NewRegistryClient();

            IManifestTemplate manifestTemplate =
                await registryClient.PullManifestAsync(buildConfiguration.GetBaseImageConfiguration().GetImageTag()).ConfigureAwait(false);

            // TODO: Make schema version be enum.
            switch (manifestTemplate.SchemaVersion)
            {
            case 1:
                V21ManifestTemplate v21ManifestTemplate = (V21ManifestTemplate)manifestTemplate;
                await buildConfiguration
                .GetBaseImageLayersCache()
                .WriteMetadataAsync(
                    buildConfiguration.GetBaseImageConfiguration().GetImage(), v21ManifestTemplate).ConfigureAwait(false);

                return(JsonToImageTranslator.ToImage(v21ManifestTemplate));

            case 2:
                IBuildableManifestTemplate buildableManifestTemplate =
                    (IBuildableManifestTemplate)manifestTemplate;
                if (buildableManifestTemplate.GetContainerConfiguration() == null ||
                    buildableManifestTemplate.GetContainerConfiguration().Digest == null)
                {
                    throw new UnknownManifestFormatException(
                              "Invalid container configuration in Docker V2.2/OCI manifest: \n"
                              + JsonTemplateMapper.ToUtf8String(buildableManifestTemplate));
                }

                DescriptorDigest containerConfigurationDigest =
                    buildableManifestTemplate.GetContainerConfiguration().Digest;

                using (ThrottledProgressEventDispatcherWrapper progressEventDispatcherWrapper =
                           new ThrottledProgressEventDispatcherWrapper(
                               progressEventDispatcher.NewChildProducer(),
                               "pull container configuration " + containerConfigurationDigest))
                {
                    string containerConfigurationString =
                        await Blobs.WriteToStringAsync(
                            registryClient.PullBlob(
                                containerConfigurationDigest,
                                progressEventDispatcherWrapper.SetProgressTarget,
                                progressEventDispatcherWrapper.DispatchProgress)).ConfigureAwait(false);

                    ContainerConfigurationTemplate containerConfigurationTemplate =
                        JsonTemplateMapper.ReadJson <ContainerConfigurationTemplate>(
                            containerConfigurationString);
                    await buildConfiguration
                    .GetBaseImageLayersCache()
                    .WriteMetadataAsync(
                        buildConfiguration.GetBaseImageConfiguration().GetImage(),
                        buildableManifestTemplate,
                        containerConfigurationTemplate).ConfigureAwait(false);

                    return(JsonToImageTranslator.ToImage(
                               buildableManifestTemplate, containerConfigurationTemplate));
                }
            }

            throw new InvalidOperationException(Resources.PullBaseImageStepUnknownManifestErrorMessage);
        }
예제 #9
0
 /**
  * Saves a V2.1 image manifest.
  *
  * @param imageReference the image reference to save the manifest and container configuration for
  * @param manifestTemplate the V2.1 manifest
  * @throws IOException if an I/O exception occurs
  */
 public async Task WriteMetadataAsync(IImageReference imageReference, V21ManifestTemplate manifestTemplate)
 {
     await cacheStorageWriter.WriteMetadataAsync(imageReference, manifestTemplate).ConfigureAwait(false);
 }