builder.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 // import "github.com/docker/docker/builder"
  6. import (
  7. "context"
  8. "io"
  9. "github.com/docker/docker/api/types/backend"
  10. "github.com/docker/docker/api/types/container"
  11. containerpkg "github.com/docker/docker/container"
  12. "github.com/docker/docker/image"
  13. "github.com/docker/docker/layer"
  14. "github.com/opencontainers/go-digest"
  15. )
  16. const (
  17. // DefaultDockerfileName is the Default filename with Docker commands, read by docker build
  18. DefaultDockerfileName = "Dockerfile"
  19. )
  20. // Source defines a location that can be used as a source for the ADD/COPY
  21. // instructions in the builder.
  22. type Source interface {
  23. // Root returns root path for accessing source
  24. Root() string
  25. // Close allows to signal that the filesystem tree won't be used anymore.
  26. // For Context implementations using a temporary directory, it is recommended to
  27. // delete the temporary directory in Close().
  28. Close() error
  29. // Hash returns a checksum for a file
  30. Hash(path string) (string, error)
  31. }
  32. // Backend abstracts calls to a Docker Daemon.
  33. type Backend interface {
  34. ImageBackend
  35. ExecBackend
  36. // CommitBuildStep creates a new Docker image from the config generated by
  37. // a build step.
  38. CommitBuildStep(context.Context, backend.CommitConfig) (image.ID, error)
  39. // ContainerCreateWorkdir creates the workdir
  40. ContainerCreateWorkdir(containerID string) error
  41. CreateImage(ctx context.Context, config []byte, parent string, contentStoreDigest digest.Digest) (Image, error)
  42. ImageCacheBuilder
  43. }
  44. // ImageBackend are the interface methods required from an image component
  45. type ImageBackend interface {
  46. GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ROLayer, error)
  47. }
  48. // ExecBackend contains the interface methods required for executing containers
  49. type ExecBackend interface {
  50. // ContainerAttachRaw attaches to container.
  51. ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error
  52. // ContainerCreateIgnoreImagesArgsEscaped creates a new Docker container and returns potential warnings
  53. ContainerCreateIgnoreImagesArgsEscaped(ctx context.Context, config backend.ContainerCreateConfig) (container.CreateResponse, error)
  54. // ContainerRm removes a container specified by `id`.
  55. ContainerRm(name string, config *backend.ContainerRmConfig) error
  56. // ContainerStart starts a new container
  57. ContainerStart(ctx context.Context, containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
  58. // ContainerWait stops processing until the given container is stopped.
  59. ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error)
  60. }
  61. // Result is the output produced by a Builder
  62. type Result struct {
  63. ImageID string
  64. FromImage Image
  65. }
  66. // ImageCacheBuilder represents a generator for stateful image cache.
  67. type ImageCacheBuilder interface {
  68. // MakeImageCache creates a stateful image cache.
  69. MakeImageCache(ctx context.Context, cacheFrom []string) (ImageCache, error)
  70. }
  71. // ImageCache abstracts an image cache.
  72. // (parent image, child runconfig) -> child image
  73. type ImageCache interface {
  74. // GetCache returns a reference to a cached image whose parent equals `parent`
  75. // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
  76. GetCache(parentID string, cfg *container.Config) (imageID string, err error)
  77. }
  78. // Image represents a Docker image used by the builder.
  79. type Image interface {
  80. ImageID() string
  81. RunConfig() *container.Config
  82. MarshalJSON() ([]byte, error)
  83. OperatingSystem() string
  84. }
  85. // ROLayer is a reference to image rootfs layer
  86. type ROLayer interface {
  87. Release() error
  88. NewRWLayer() (RWLayer, error)
  89. DiffID() layer.DiffID
  90. ContentStoreDigest() digest.Digest
  91. }
  92. // RWLayer is active layer that can be read/modified
  93. type RWLayer interface {
  94. Release() error
  95. Root() string
  96. Commit() (ROLayer, error)
  97. }