builder.go 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. "time"
  9. "github.com/docker/docker/api/types"
  10. "github.com/docker/docker/api/types/backend"
  11. "github.com/docker/docker/api/types/container"
  12. "golang.org/x/net/context"
  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. // TODO: use digest reference instead of name
  33. // GetImageOnBuild looks up a Docker image referenced by `name`.
  34. GetImageOnBuild(name string) (Image, error)
  35. // PullOnBuild tells Docker to pull image referenced by `name`.
  36. PullOnBuild(ctx context.Context, name string, authConfigs map[string]types.AuthConfig, output io.Writer) (Image, error)
  37. // ContainerAttachRaw attaches to container.
  38. ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error
  39. // ContainerCreate creates a new Docker container and returns potential warnings
  40. ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
  41. // ContainerRm removes a container specified by `id`.
  42. ContainerRm(name string, config *types.ContainerRmConfig) error
  43. // Commit creates a new Docker image from an existing Docker container.
  44. Commit(string, *backend.ContainerCommitConfig) (string, error)
  45. // ContainerKill stops the container execution abruptly.
  46. ContainerKill(containerID string, sig uint64) error
  47. // ContainerStart starts a new container
  48. ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
  49. // ContainerWait stops processing until the given container is stopped.
  50. ContainerWait(containerID string, timeout time.Duration) (int, error)
  51. // ContainerCreateWorkdir creates the workdir
  52. ContainerCreateWorkdir(containerID string) error
  53. // ContainerCopy copies/extracts a source FileInfo to a destination path inside a container
  54. // specified by a container object.
  55. // TODO: extract in the builder instead of passing `decompress`
  56. // TODO: use containerd/fs.changestream instead as a source
  57. CopyOnBuild(containerID string, destPath string, srcRoot string, srcPath string, decompress bool) error
  58. // MountImage returns mounted path with rootfs of an image.
  59. MountImage(name string) (string, func() error, error)
  60. }
  61. // Image represents a Docker image used by the builder.
  62. type Image interface {
  63. ImageID() string
  64. RunConfig() *container.Config
  65. }
  66. // Result is the output produced by a Builder
  67. type Result struct {
  68. ImageID string
  69. FromImage Image
  70. }
  71. // ImageCacheBuilder represents a generator for stateful image cache.
  72. type ImageCacheBuilder interface {
  73. // MakeImageCache creates a stateful image cache.
  74. MakeImageCache(cacheFrom []string) ImageCache
  75. }
  76. // ImageCache abstracts an image cache.
  77. // (parent image, child runconfig) -> child image
  78. type ImageCache interface {
  79. // GetCache returns a reference to a cached image whose parent equals `parent`
  80. // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
  81. GetCache(parentID string, cfg *container.Config) (imageID string, err error)
  82. }