builder.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. import (
  7. "io"
  8. "golang.org/x/net/context"
  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. )
  14. const (
  15. // DefaultDockerfileName is the Default filename with Docker commands, read by docker build
  16. DefaultDockerfileName string = "Dockerfile"
  17. )
  18. // Source defines a location that can be used as a source for the ADD/COPY
  19. // instructions in the builder.
  20. type Source interface {
  21. // Root returns root path for accessing source
  22. Root() string
  23. // Close allows to signal that the filesystem tree won't be used anymore.
  24. // For Context implementations using a temporary directory, it is recommended to
  25. // delete the temporary directory in Close().
  26. Close() error
  27. // Hash returns a checksum for a file
  28. Hash(path string) (string, error)
  29. }
  30. // Backend abstracts calls to a Docker Daemon.
  31. type Backend interface {
  32. ImageBackend
  33. // ContainerAttachRaw attaches to container.
  34. ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error
  35. // ContainerCreate creates a new Docker container and returns potential warnings
  36. ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
  37. // ContainerRm removes a container specified by `id`.
  38. ContainerRm(name string, config *types.ContainerRmConfig) error
  39. // Commit creates a new Docker image from an existing Docker container.
  40. Commit(string, *backend.ContainerCommitConfig) (string, error)
  41. // ContainerKill stops the container execution abruptly.
  42. ContainerKill(containerID string, sig uint64) error
  43. // ContainerStart starts a new container
  44. ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
  45. // ContainerWait stops processing until the given container is stopped.
  46. ContainerWait(ctx context.Context, name string, untilRemoved bool) (<-chan *containerpkg.StateStatus, error)
  47. // ContainerCreateWorkdir creates the workdir
  48. ContainerCreateWorkdir(containerID string) error
  49. // ContainerCopy copies/extracts a source FileInfo to a destination path inside a container
  50. // specified by a container object.
  51. // TODO: extract in the builder instead of passing `decompress`
  52. // TODO: use containerd/fs.changestream instead as a source
  53. CopyOnBuild(containerID string, destPath string, srcRoot string, srcPath string, decompress bool) error
  54. }
  55. // ImageBackend are the interface methods required from an image component
  56. type ImageBackend interface {
  57. GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ReleaseableLayer, error)
  58. }
  59. // Result is the output produced by a Builder
  60. type Result struct {
  61. ImageID string
  62. FromImage Image
  63. }
  64. // ImageCacheBuilder represents a generator for stateful image cache.
  65. type ImageCacheBuilder interface {
  66. // MakeImageCache creates a stateful image cache.
  67. MakeImageCache(cacheFrom []string) ImageCache
  68. }
  69. // ImageCache abstracts an image cache.
  70. // (parent image, child runconfig) -> child image
  71. type ImageCache interface {
  72. // GetCache returns a reference to a cached image whose parent equals `parent`
  73. // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
  74. GetCache(parentID string, cfg *container.Config) (imageID string, err error)
  75. }
  76. // Image represents a Docker image used by the builder.
  77. type Image interface {
  78. ImageID() string
  79. RunConfig() *container.Config
  80. }
  81. // ReleaseableLayer is an image layer that can be mounted and released
  82. type ReleaseableLayer interface {
  83. Release() error
  84. Mount() (string, error)
  85. }