history

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Copyright © 2022 Johnson Shi <Johnson.Shi@microsoft.com>

Copyright © 2022 Johnson Shi <Johnson.Shi@microsoft.com>

Copyright © 2022 Johnson Shi <Johnson.Shi@microsoft.com>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMultistageBuildStage

func FindMultistageBuildStage(dockerfileCommands []dockerfile.Command, stage string) (int, int, error)

FindMultistageBuildStage finds the start and end indexes of the Dockerfile commands that correspond to the multistage build stage. The stage is the `<multistage-build-stage>` value within the `COPY --from=<multistage-build-stage>` flag. The stage can be a stage name string or a stage number.

Note: The specified build stage name can be a stage number as well, such as `--from=0`. See example at https://docs.docker.com/develop/develop-images/multistage-build/#:~:text=How%20does%20it,the%20final%20image.

Types

type ImageHistory

type ImageHistory struct {
	// ImageLayerHistory MUST be sorted from top layers (most recent layers) to bottom layers (base image layers).
	ImageLayerHistory []image.HistoryResponseItem `json:"ImageLayerHistory"`
	// OCI image manifest. See https://github.com/opencontainers/image-spec/blob/main/manifest.md.
	ImageManifest ocispec.Manifest `json:"ImageManifest"`
	// DockerfileCommands MUST be sorted based on the original order of commands in the Dockerfile.
	// E.g. if the Dockerfile contains the following commands:
	// 		FROM ubuntu:22.04
	// 		RUN apt-get update
	// 		RUN apt-get install -y vim
	// then dockerfileCommands should be:
	// 		[]dockerfile.Command{
	// 			dockerfile.Command{Original: "FROM ubuntu:22.04", Cmd: "FROM", Value: []string{"ubuntu:22.04"}},
	// 			dockerfile.Command{Original: "RUN apt-get update", Cmd: "RUN", Value: []string{"apt-get", "update"}},
	// 			dockerfile.Command{Original: "RUN apt-get install -y vim", Cmd: "RUN", Value: []string{"apt-get", "install", "-y", "vim"}},
	// 		}
	DockerfileCommands []dockerfile.Command `json:"DockerfileCommands"`
}

ImageHistory describes the overall history of an image. It contains: - the image's non-detailed layer history,

  • This is the non-detailed layer history from Docker Engine API's ImageHistory operation (`docker image history`).

- the image's OCI image manifest, - the image's Dockerfile.

func (*ImageHistory) GetImageManifestLayerDockerfileCommandsHistory

func (h *ImageHistory) GetImageManifestLayerDockerfileCommandsHistory(attributionAnnotations map[string]string) ([]ImageManifestLayerDockerfileCommandsHistory, error)

GetImageManifestLayerDockerfileCommandsHistory returns the exact Dockerfile commands that contributed to the creation of each image manifest layer. Layers returned are sorted from bottom layers (base image layers) to top layers. attributionAnnotations is only added to the layer history if the layer is not a primary base image layer (i.e. only added for layers not 'FROM <primary-base-image>')

type ImageManifestLayerDockerfileCommandsHistory

type ImageManifestLayerDockerfileCommandsHistory struct {
	LayerDescriptor         ocispec.Descriptor      `json:"LayerDescriptor"`
	LayerCreationParameters LayerCreationParameters `json:"LayerCreationParameters"`
	AttributedEntity        map[string]string       `json:"AttributedEntity"`
}

ImageManifestLayerDockerfileCommandsHistory describes the exact Dockerfile history of an image manifest layer.

type LayerCreationParameters added in v0.0.3

type LayerCreationParameters struct {
	DockerfileLayerCreationType LayerCreationType    `json:"DockerfileLayerCreationType"`
	DockerfileCommands          []dockerfile.Command `json:"DockerfileCommands"`
	BaseImageRef                string               `json:"BaseImage"`
}

LayerCreationParameters describes the exact Dockerfile parameters used to create the image manifest layer.

type LayerCreationType

type LayerCreationType string

LayerCreationType describes the type of layer creation.

const (
	// FROMPrimaryBaseImageLayer is the layer creation type for
	// primary base image layers (layers created by `FROM <primary-base-image>`).
	FROMPrimaryBaseImageLayer LayerCreationType = "FROM-PrimaryBaseImageLayer"

	// COPYFromMultistageBuildStageLayer is the layer creation type for
	// COPY from multistage build stage layers (layers created by `COPY --from=<multistage-build-stage> <src> <dst>`).
	COPYFromMultistageBuildStageLayer LayerCreationType = "COPY-FromMultistageBuildStageLayer"

	// COPYCommandLayer is the layer creation type for
	// for non-multistage COPY commands (layers created by `COPY <src> <dst>`).
	COPYCommandLayer LayerCreationType = "COPY-CommandLayer"

	// ADDCommandLayer is the layer creation type for
	// for layers created by `ADD`.
	ADDCommandLayer LayerCreationType = "ADD-CommandLayer"

	// RUNCommandLayer is the layer creation type for
	// for layers created by `RUN`.
	RUNCommandLayer LayerCreationType = "RUN-CommandLayer"

	// UNKNOWNDockerfileCommandLayer is the layer creation type for
	// for layers created by unknown Dockerfile commands.
	// This should not happen as this would imply that commands other than
	// {FROM, COPY, ADD, RUN} created a layer, which is impossible.
	UNKNOWNDockerfileCommandLayer LayerCreationType = "UNKNOWN-DockerfileCommandLayer"
)

type SimplifiedImageManifestLayerDockerfileCommandsHistory

type SimplifiedImageManifestLayerDockerfileCommandsHistory struct {
	LayerDigest                 digest.Digest     `json:"LayerDigest"`
	DockerfileLayerCreationType LayerCreationType `json:"DockerfileLayerCreationType"`
	DockerfileCommands          []string          `json:"DockerfileCommands"`
	BaseImageRef                string            `json:"BaseImage"`
	AttributedEntity            map[string]string `json:"AttributedEntity"`
}

SimplifiedImageManifestLayerDockerfileCommandsHistory describes the exact Dockerfile history of an image manifest layer (simplified format).

func GetSimplifiedImageManifestLayerDockerfileCommandsHistory

func GetSimplifiedImageManifestLayerDockerfileCommandsHistory(manifestLayerHistory []ImageManifestLayerDockerfileCommandsHistory) []SimplifiedImageManifestLayerDockerfileCommandsHistory

GetSimplifiedImageManifestLayerDockerfileCommandsHistory returns the exact Dockerfile commands that contributed to the creation of each image manifest layer (simplified format). attributionAnnotations is only added to the layer history if the layer is not a primary base image layer (i.e. only added for layers not 'FROM <primary-base-image>')

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL