Пример #1
0
        /**
         * Retrieves the cached base image.
         *
         * @return the cached image
         * @throws IOException when an I/O exception occurs
         * @throws CacheCorruptedException if the cache is corrupted
         * @throws LayerPropertyNotFoundException if adding image layers fails
         * @throws BadContainerConfigurationFormatException if the container configuration is in a bad
         *     format
         */
        private Image PullBaseImageOffline()
        {
            IImageReference           baseImage = buildConfiguration.GetBaseImageConfiguration().GetImage();
            Maybe <ManifestAndConfig> metadata  =
                buildConfiguration.GetBaseImageLayersCache().RetrieveMetadata(baseImage);

            if (!metadata.IsPresent())
            {
                throw new IOException(
                          "Cannot run Fib in offline mode; " + baseImage + " not found in local Fib cache");
            }

            IManifestTemplate manifestTemplate = metadata.Get().GetManifest();

            if (manifestTemplate is V21ManifestTemplate v21ManifestTemplate)
            {
                return(JsonToImageTranslator.ToImage(v21ManifestTemplate));
            }

            ContainerConfigurationTemplate configurationTemplate =
                metadata.Get().GetConfig().OrElseThrow(() => new InvalidOperationException());

            return(JsonToImageTranslator.ToImage(
                       (IBuildableManifestTemplate)manifestTemplate, configurationTemplate));
        }
Пример #2
0
 /**
  * Saves a manifest and container configuration for a V2.2 or OCI image.
  *
  * @param imageReference the image reference to save the manifest and container configuration for
  * @param manifestTemplate the V2.2 or OCI manifest
  * @param containerConfigurationTemplate the container configuration
  * @throws IOException if an I/O exception occurs
  */
 public async Task WriteMetadataAsync(
     IImageReference imageReference,
     IBuildableManifestTemplate manifestTemplate,
     ContainerConfigurationTemplate containerConfigurationTemplate)
 {
     await cacheStorageWriter.WriteMetadataAsync(
         imageReference, manifestTemplate, containerConfigurationTemplate).ConfigureAwait(false);
 }
Пример #3
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);
            }
        }
Пример #4
0
        public ImageDialog(EditorBindableCollapsiblePanel parent, IServerConnection conn, ISimpleSymbolDefinition ssd, IImageGraphic image)
        {
            InitializeComponent();
            _ed    = parent;
            _ssd   = ssd;
            _image = image;
            _conn  = conn;
            try
            {
                _init = true;
                if (_image.Item.Type == ImageType.Reference)
                {
                    _imageRef             = (IImageReference)_image.Item;
                    rdResourceRef.Checked = true;
                }
                else
                {
                    _imageInline     = (IInlineImage)_image.Item;
                    rdInline.Checked = true;
                }

                if (_imageRef == null)
                {
                    _imageRef = ssd.CreateImageReference(string.Empty, string.Empty);
                }
                else
                {
                    rdResourceRef.Checked = true;
                }

                if (_imageInline == null)
                {
                    _imageInline = ssd.CreateInlineImage(new byte[0]);
                }
                else
                {
                    rdInline.Checked = true;
                }

                txtResourceId.Text = _imageRef.ResourceId;
                txtResData.Text    = _imageRef.LibraryItemName;

                txtImageBase64.Text = Convert.ToBase64String(_imageInline.Content);
                txtImageBase64.Tag  = _imageInline.Content;

                imageType_CheckedChanged(this, null);
            }
            finally
            {
                _init = false;
            }
        }
Пример #5
0
        /**
         * Gets the directory corresponding to the given image reference.
         *
         * @param imageReference the image reference
         * @return a path in the form of {@code
         *     (fib-cache)/images/registry[!port]/repository!(tag|digest-type!digest)}
         */
        public SystemPath GetImageDirectory(IImageReference imageReference)
        {
            imageReference = imageReference ?? throw new ArgumentNullException(nameof(imageReference));
            // Replace ':' and '@' with '!' to avoid directory-naming restrictions
            string replacedReference = imageReference.ToStringWithTag().Replace(':', '!').Replace('@', '!');

            // Split image reference on '/' to build directory structure
            IEnumerable <string> directories = Splitter.On('/').Split(replacedReference);
            SystemPath           destination = GetImagesDirectory();

            foreach (string dir in directories)
            {
                destination = destination.Resolve(dir);
            }
            return(destination);
        }
Пример #6
0
        public ImageDialog(EditorBindableCollapsiblePanel parent, IResourceService resSvc, ISimpleSymbolDefinition ssd, IImageGraphic image)
        {
            InitializeComponent();
            _ed = parent;
            _ssd = ssd;
            _image = image;
            _resSvc = resSvc;
            try
            {
                _init = true;
                if (_image.Item.Type == ImageType.Reference)
                {
                    _imageRef = (IImageReference)_image.Item;
                    rdResourceRef.Checked = true;
                }
                else
                {
                    _imageInline = (IInlineImage)_image.Item;
                    rdInline.Checked = true;
                }

                if (_imageRef == null)
                    _imageRef = ssd.CreateImageReference("", "");
                else
                    rdResourceRef.Checked = true;

                if (_imageInline == null)
                    _imageInline = ssd.CreateInlineImage(new byte[0]);
                else
                    rdInline.Checked = true;

                txtResourceId.Text = _imageRef.ResourceId;
                txtResData.Text = _imageRef.LibraryItemName;

                txtImageBase64.Text = Convert.ToBase64String(_imageInline.Content);
                txtImageBase64.Tag = _imageInline.Content;

                imageType_CheckedChanged(this, null);
            }
            finally
            {
                _init = false;
            }
        }
Пример #7
0
        /**
         * Saves the manifest and container configuration for a V2.2 or OCI image.
         *
         * @param imageReference the image reference to store the metadata for
         * @param manifestTemplate the manifest
         * @param containerConfiguration the container configuration
         */
        public async Task WriteMetadataAsync(
            IImageReference imageReference,
            IBuildableManifestTemplate manifestTemplate,
            ContainerConfigurationTemplate containerConfiguration)
        {
            manifestTemplate = manifestTemplate ?? throw new ArgumentNullException(nameof(manifestTemplate));
            Preconditions.CheckNotNull(manifestTemplate.GetContainerConfiguration());
            Preconditions.CheckNotNull(manifestTemplate.GetContainerConfiguration().Digest);

            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);
                await WriteMetadataAsync(containerConfiguration, imageDirectory.Resolve("config.json")).ConfigureAwait(false);
            }
        }
Пример #8
0
        /**
         * Tags the image referenced by {@code originalImageReference} with a new image reference {@code
         * newImageReference}.
         *
         * @param originalImageReference the existing image reference on the Docker daemon
         * @param newImageReference the new image reference
         * @see <a
         *     href="https://docs.docker.com/engine/reference/commandline/tag/">https://docs.docker.com/engine/reference/commandline/tag/</a>
         * @throws InterruptedException if the 'docker tag' process is interrupted.
         * @throws IOException if an I/O exception occurs or {@code docker tag} failed
         */
        public async Task TagAsync(IImageReference originalImageReference, ImageReference newImageReference)
        {
            originalImageReference = originalImageReference ?? throw new ArgumentNullException(nameof(originalImageReference));

            newImageReference = newImageReference ?? throw new ArgumentNullException(nameof(newImageReference));
            // Runs 'docker tag'.
            IProcess dockerProcess =
                Docker("tag", originalImageReference.ToString(), newImageReference.ToString());

            if (dockerProcess.WaitFor() != 0)
            {
                using (StreamReader stderr =
                           new StreamReader(dockerProcess.GetErrorStream(), Encoding.UTF8))
                {
                    string errorMessage = await stderr.ReadToEndAsync().ConfigureAwait(false);

                    throw new IOException(
                              "'docker tag' command failed with error: " + errorMessage);
                }
            }
        }
Пример #9
0
        public async Task <BuildResult> CallAsync()
        {
            await pullAndCacheBaseImageLayersStep.GetFuture().ConfigureAwait(false);

            await buildAndCacheApplicationLayersStep.GetFuture().ConfigureAwait(false);

            await buildImageStep.GetFuture().ConfigureAwait(false);

            buildConfiguration
            .GetEventHandlers()
            .Dispatch(LogEvent.Progress(Resources.LoadDockerStepDescription));

            using (progressEventDispatcherFactory.Create(Resources.LoadDockerStepDescription, 1))
            {
                Image image = await buildImageStep.GetFuture().ConfigureAwait(false);

                IImageReference targetImageReference =
                    buildConfiguration.GetTargetImageConfiguration().GetImage();

                // Load the image to docker daemon.
                buildConfiguration
                .GetEventHandlers()
                .Dispatch(
                    LogEvent.Debug(await dockerClient.LoadAsync(new ImageTarball(image, targetImageReference)).ConfigureAwait(false)));

                // Tags the image with all the additional tags, skipping the one 'docker load' already loaded.
                foreach (string tag in buildConfiguration.GetAllTargetImageTags())
                {
                    if (tag.Equals(targetImageReference.GetTag(), StringComparison.Ordinal))
                    {
                        continue;
                    }

                    ImageReference taggedImageReference = targetImageReference.WithTag(tag);
                    await dockerClient.TagAsync(targetImageReference, taggedImageReference).ConfigureAwait(false);
                }

                return(await BuildResult.FromImageAsync(image, buildConfiguration.GetTargetFormat()).ConfigureAwait(false));
            }
        }
Пример #10
0
 /**
  * Retrieves the cached manifest and container configuration for an image reference.
  *
  * @param imageReference the image reference
  * @return the manifest and container configuration for the image reference, if found
  * @throws IOException if an I/O exception occurs
  * @throws CacheCorruptedException if the cache is corrupted
  */
 public Maybe <ManifestAndConfig> RetrieveMetadata(IImageReference imageReference)
 {
     return(cacheStorageReader.RetrieveMetadata(imageReference));
 }
Пример #11
0
        /**
         * Retrieves the cached manifest and container configuration for an image reference.
         *
         * @param imageReference the image reference
         * @return the manifest and container configuration for the image reference, if found
         * @throws IOException if an I/O exception occurs
         * @throws CacheCorruptedException if the cache is corrupted
         */
        public Maybe <ManifestAndConfig> RetrieveMetadata(IImageReference imageReference)
        {
            SystemPath imageDirectory = cacheStorageFiles.GetImageDirectory(imageReference);
            SystemPath manifestPath   = imageDirectory.Resolve("manifest.json");

            if (!Files.Exists(manifestPath))
            {
                return(Maybe.Empty <ManifestAndConfig>());
            }

            // TODO: Consolidate with ManifestPuller
            JToken token;

            using (JsonTextReader reader = new JsonTextReader(File.OpenText(manifestPath)))
            {
                token = JToken.ReadFrom(reader);
            }
            if (!(token is JObject node))
            {
                throw new CacheCorruptedException(
                          cacheStorageFiles.GetCacheDirectory(),
                          Resources.CacheStorageReaderNotJsonExecpetionMessage);
            }
            if (!node.ContainsKey("schemaVersion"))
            {
                throw new CacheCorruptedException(
                          cacheStorageFiles.GetCacheDirectory(),
                          Resources.CacheStorageReaderSchemaVersionMissingExecpetionMessage);
            }

            int schemaVersion = node["schemaVersion"].Value <int>();

            if (schemaVersion == -1)
            {
                throw new CacheCorruptedException(
                          cacheStorageFiles.GetCacheDirectory(),
                          Resources.CacheStorageReaderInvalidSchemaVersionExecpetionMessageFormat);
            }

            if (schemaVersion == 1)
            {
                return(Maybe.Of(
                           new ManifestAndConfig(
                               JsonTemplateMapper.ReadJsonFromFile <V21ManifestTemplate>(manifestPath),
                               null)));
            }
            if (schemaVersion == 2)
            {
                // 'schemaVersion' of 2 can be either Docker V2.2 or OCI.
                string mediaType = node["mediaType"].Value <string>();

                IManifestTemplate manifestTemplate;
                if (V22ManifestTemplate.ManifestMediaType == mediaType)
                {
                    manifestTemplate =
                        JsonTemplateMapper.ReadJsonFromFile <V22ManifestTemplate>(manifestPath);
                }
                else if (OCIManifestTemplate.ManifestMediaType == mediaType)
                {
                    manifestTemplate =
                        JsonTemplateMapper.ReadJsonFromFile <OCIManifestTemplate>(manifestPath);
                }
                else
                {
                    throw new CacheCorruptedException(
                              cacheStorageFiles.GetCacheDirectory(),
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  Resources.CacheStorageReaderUnknownMediaTypeExecpetionMessageFormat, mediaType));
                }

                SystemPath configPath = imageDirectory.Resolve("config.json");
                if (!Files.Exists(configPath))
                {
                    throw new CacheCorruptedException(
                              cacheStorageFiles.GetCacheDirectory(),
                              Resources.CacheStorageReaderContainerConfigurationMissingExecpetionMessage);
                }
                ContainerConfigurationTemplate config =
                    JsonTemplateMapper.ReadJsonFromFile <ContainerConfigurationTemplate>(configPath);

                return(Maybe.Of(new ManifestAndConfig(manifestTemplate, config)));
            }
            throw new CacheCorruptedException(
                      cacheStorageFiles.GetCacheDirectory(),
                      string.Format(
                          CultureInfo.CurrentCulture,
                          Resources.CacheStorageReaderInvalidSchemaVersionExecpetionMessageFormat, schemaVersion));
        }
        /// <summary>
        /// Validates the simple symbol definition.
        /// </summary>
        /// <param name="ssym">The ssym.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        protected IEnumerable <ValidationIssue> ValidateSimpleSymbolDefinition(ISimpleSymbolDefinition ssym, ResourceValidationContext context)
        {
            //Check that one geometry usage context has been specified
            if (ssym.AreaUsage == null &&
                ssym.LineUsage == null &&
                ssym.PointUsage == null)
            {
                yield return(new ValidationIssue(ssym, ValidationStatus.Error, ValidationStatusCode.Error_SymbolDefinition_NoGeometryUsageContexts, Strings.SSDF_NoGeometryUsageContext));
            }

            //Validate image graphics
            foreach (var graphic in ssym.Graphics)
            {
                if (graphic.Type == GraphicElementType.Image)
                {
                    IImageGraphic image = (IImageGraphic)graphic;
                    if (image.Item != null)
                    {
                        if (image.Item.Type == ImageType.Reference)
                        {
                            IImageReference imgRef = (IImageReference)image.Item;
                            if (!context.ResourceExists(imgRef.ResourceId))
                            {
                                yield return(new ValidationIssue(ssym, ValidationStatus.Error, ValidationStatusCode.Error_SymbolDefinition_ImageGraphicReferenceResourceIdNotFound, Strings.SSDF_ImageGraphicReferenceResourceIdNotFound));
                            }
                            else
                            {
                                var  res     = context.GetResource(imgRef.ResourceId);
                                var  resData = this.Connection.ResourceService.EnumerateResourceData(res.ResourceID);
                                bool found   = false;
                                foreach (var item in resData.ResourceData)
                                {
                                    if (item.Name == imgRef.LibraryItemName)
                                    {
                                        found = true;
                                    }
                                }

                                if (!found)
                                {
                                    yield return(new ValidationIssue(ssym,
                                                                     ValidationStatus.Error,
                                                                     ValidationStatusCode.Error_SymbolDefinition_ImageGraphicReferenceResourceDataNotFound,
                                                                     string.Format(Strings.SSDF_ImageGraphicReferenceResourceDataNotFound,
                                                                                   imgRef.ResourceId,
                                                                                   imgRef.LibraryItemName)));
                                }
                            }
                        }
                        else //inline
                        {
                            //TODO: Validate inline image content
                        }
                    }
                }
            }

            string xml = ObjectFactory.SerializeAsString(ssym);

            //Check non existent symbol parameters
            foreach (var paramDef in ssym.ParameterDefinition.Parameter)
            {
                string name = "%" + paramDef.Identifier + "%"; //NOXLATE
                if (!xml.Contains(name) && string.IsNullOrEmpty(paramDef.DefaultValue))
                {
                    yield return(new ValidationIssue(ssym, ValidationStatus.Warning, ValidationStatusCode.Warning_SymbolDefinition_SymbolParameterNotUsed,
                                                     string.Format(Strings.SSDF_SymbolParameterNotUsed, paramDef.Identifier)));
                }
            }

            //TODO: Do the reverse check. Placeholders not pointing to a symbol parameter
        }
Пример #13
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);
 }
Пример #14
0
 /**
  * Instantiate with an {@link Image}.
  *
  * @param image the image to convert into a tarball
  * @param imageReference image reference to set in the manifest
  */
 public ImageTarball(Image image, IImageReference imageReference)
 {
     this.image          = image;
     this.imageReference = imageReference;
 }
Пример #15
0
 private ImageConfiguration(
     IImageReference image, ImmutableArray <CredentialRetriever> credentialRetrievers)
 {
     this.image = image;
     this.credentialRetrievers = credentialRetrievers;
 }
Пример #16
0
 /**
  * Constructs a builder for an {@link ImageConfiguration}.
  *
  * @param imageReference the image reference, which is a required field
  * @return the builder
  */
 public static Builder CreateBuilder(IImageReference imageReference)
 {
     return(new Builder(imageReference));
 }
Пример #17
0
 public Builder(IImageReference imageReference)
 {
     this.imageReference = imageReference;
 }