private void AddLayerToConfigAndManifest(BuilderLayer layer, ManifestV2 manifest, ImageV1 image) { image.rootfs.diff_ids.Add(layer.DiffId); image.history.Add(ImageV1History.Create(layer.Description, null)); var(imageBytes, imageDigest) = ToJson(image); manifest.config.digest = imageDigest; manifest.config.size = imageBytes.Length; manifest.layers.Add(new ManifestV2Layer { digest = layer.Digest, size = layer.Size, }); }
private void UpdateImageConfig(ImageV1 image) { var config = image.config; var historyStrings = new List <string>(); // do git labels before other labels, to enable users to overwrite them if (GitLabels.HasValue()) { IDictionary <string, string> gitLabels = null; try { gitLabels = Utils.GitLabels.GetLabels(GitLabels.Value(), GitLabelsPrefix.Value()); } catch (Exception ex) { _logger.LogWarning($"Failed to read git labels: {ex.Message}"); } if (gitLabels != null) { foreach (var l in gitLabels) { config.Labels = config.Labels ?? new Dictionary <string, string>(); config.Labels[l.Key] = l.Value; historyStrings.Add($"--gitLabels {l.Key}={l.Value}"); } } } foreach (var label in Label.Values) { config.Labels = config.Labels ?? new Dictionary <string, string>(); var split = label.Split('=', 2); if (split.Length != 2) { throw new Exception($"Invalid label {label}"); } config.Labels[split[0]] = split[1]; historyStrings.Add($"--label {split[0]}={split[1]}"); } foreach (var var in Env.Values) { config.Env = config.Env ?? new List <string>(); config.Env.Add(var); historyStrings.Add($"--env {var}"); } if (WorkDir.HasValue()) { config.WorkingDir = WorkDir.Value(); historyStrings.Add($"--workdir {WorkDir.Value()}"); } if (User.HasValue()) { config.User = User.Value(); historyStrings.Add($"--user {User.Value()}"); } if (Cmd.HasValue()) { config.Cmd = SplitCmd(Cmd.Value()).ToList(); var cmdString = string.Join(", ", config.Cmd.Select(c => $"\"{c}\"")); historyStrings.Add($"--cmd {cmdString}"); } if (Entrypoint.HasValue()) { config.Entrypoint = SplitCmd(Entrypoint.Value()).ToList(); var epString = string.Join(", ", config.Entrypoint.Select(c => $"\"{c}\"")); historyStrings.Add($"--entrypoint {epString}"); } if (historyStrings.Any()) { image.history.Add(ImageV1History.Create(string.Join(", ", historyStrings), true)); } foreach (var h in historyStrings) { _logger.LogDebug(h); } }