github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/builder/builder.go (about) 1 // Package builder defines interfaces for any Docker builder to implement. 2 // 3 // Historically, only server-side Dockerfile interpreters existed. 4 // This package allows for other implementations of Docker builders. 5 package builder 6 7 import ( 8 "io" 9 10 "github.com/docker/docker/api/types" 11 "github.com/docker/docker/api/types/backend" 12 "github.com/docker/docker/api/types/container" 13 containerpkg "github.com/docker/docker/container" 14 "github.com/docker/docker/layer" 15 "github.com/docker/docker/pkg/containerfs" 16 "golang.org/x/net/context" 17 ) 18 19 const ( 20 // DefaultDockerfileName is the Default filename with Docker commands, read by docker build 21 DefaultDockerfileName string = "Dockerfile" 22 ) 23 24 // Source defines a location that can be used as a source for the ADD/COPY 25 // instructions in the builder. 26 type Source interface { 27 // Root returns root path for accessing source 28 Root() containerfs.ContainerFS 29 // Close allows to signal that the filesystem tree won't be used anymore. 30 // For Context implementations using a temporary directory, it is recommended to 31 // delete the temporary directory in Close(). 32 Close() error 33 // Hash returns a checksum for a file 34 Hash(path string) (string, error) 35 } 36 37 // Backend abstracts calls to a Docker Daemon. 38 type Backend interface { 39 ImageBackend 40 ExecBackend 41 42 // Commit creates a new Docker image from an existing Docker container. 43 Commit(string, *backend.ContainerCommitConfig) (string, error) 44 // ContainerCreateWorkdir creates the workdir 45 ContainerCreateWorkdir(containerID string) error 46 47 CreateImage(config []byte, parent string, platform string) (Image, error) 48 49 ImageCacheBuilder 50 } 51 52 // ImageBackend are the interface methods required from an image component 53 type ImageBackend interface { 54 GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ReleaseableLayer, error) 55 } 56 57 // ExecBackend contains the interface methods required for executing containers 58 type ExecBackend interface { 59 // ContainerAttachRaw attaches to container. 60 ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error 61 // ContainerCreate creates a new Docker container and returns potential warnings 62 ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) 63 // ContainerRm removes a container specified by `id`. 64 ContainerRm(name string, config *types.ContainerRmConfig) error 65 // ContainerKill stops the container execution abruptly. 66 ContainerKill(containerID string, sig uint64) error 67 // ContainerStart starts a new container 68 ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error 69 // ContainerWait stops processing until the given container is stopped. 70 ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error) 71 } 72 73 // Result is the output produced by a Builder 74 type Result struct { 75 ImageID string 76 FromImage Image 77 } 78 79 // ImageCacheBuilder represents a generator for stateful image cache. 80 type ImageCacheBuilder interface { 81 // MakeImageCache creates a stateful image cache. 82 MakeImageCache(cacheFrom []string, platform string) ImageCache 83 } 84 85 // ImageCache abstracts an image cache. 86 // (parent image, child runconfig) -> child image 87 type ImageCache interface { 88 // GetCache returns a reference to a cached image whose parent equals `parent` 89 // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error. 90 GetCache(parentID string, cfg *container.Config) (imageID string, err error) 91 } 92 93 // Image represents a Docker image used by the builder. 94 type Image interface { 95 ImageID() string 96 RunConfig() *container.Config 97 MarshalJSON() ([]byte, error) 98 OperatingSystem() string 99 } 100 101 // ReleaseableLayer is an image layer that can be mounted and released 102 type ReleaseableLayer interface { 103 Release() error 104 Mount() (containerfs.ContainerFS, error) 105 Commit(platform string) (ReleaseableLayer, error) 106 DiffID() layer.DiffID 107 }