builder.go 4.1 KB

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