builder: remove container package dependency
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
2a2d1f57b5
commit
c70f8b3c9c
|
@ -7,9 +7,10 @@ package builder
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
@ -106,30 +107,40 @@ func (fi *HashedFileInfo) SetHash(h string) {
|
||||||
fi.FileHash = h
|
fi.FileHash = h
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker abstracts calls to a Docker Daemon.
|
// Backend abstracts calls to a Docker Daemon.
|
||||||
type Docker interface {
|
type Backend interface {
|
||||||
// TODO: use digest reference instead of name
|
// TODO: use digest reference instead of name
|
||||||
|
|
||||||
// LookupImage looks up a Docker image referenced by `name`.
|
// LookupImage looks up a Docker image referenced by `name`.
|
||||||
LookupImage(name string) (*image.Image, error)
|
GetImage(name string) (*image.Image, error)
|
||||||
// Pull tells Docker to pull image referenced by `name`.
|
// Pull tells Docker to pull image referenced by `name`.
|
||||||
Pull(name string) (*image.Image, error)
|
Pull(name string) (*image.Image, error)
|
||||||
|
// ContainerWsAttachWithLogs attaches to container.
|
||||||
// Container looks up a Docker container referenced by `id`.
|
ContainerWsAttachWithLogs(name string, cfg *daemon.ContainerWsAttachWithLogsConfig) error
|
||||||
Container(id string) (*container.Container, error)
|
// ContainerCreate creates a new Docker container and returns potential warnings
|
||||||
// Create creates a new Docker container and returns potential warnings
|
ContainerCreate(params *daemon.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
||||||
// TODO: put warnings in the error
|
// ContainerRm removes a container specified by `id`.
|
||||||
Create(*runconfig.Config, *runconfig.HostConfig) (*container.Container, []string, error)
|
ContainerRm(name string, config *types.ContainerRmConfig) error
|
||||||
// Remove removes a container specified by `id`.
|
|
||||||
Remove(id string, cfg *types.ContainerRmConfig) error
|
|
||||||
// Commit creates a new Docker image from an existing Docker container.
|
// Commit creates a new Docker image from an existing Docker container.
|
||||||
Commit(string, *types.ContainerCommitConfig) (string, error)
|
Commit(string, *types.ContainerCommitConfig) (string, error)
|
||||||
// Copy copies/extracts a source FileInfo to a destination path inside a container
|
// Kill stops the container execution abruptly.
|
||||||
|
ContainerKill(containerID string, sig uint64) error
|
||||||
|
// Start starts a new container
|
||||||
|
ContainerStart(containerID string, hostConfig *runconfig.HostConfig) error
|
||||||
|
// ContainerWait stops processing until the given container is stopped.
|
||||||
|
ContainerWait(containerID string, timeout time.Duration) (int, error)
|
||||||
|
|
||||||
|
// ContainerUpdateCmd updates container.Path and container.Args
|
||||||
|
ContainerUpdateCmd(containerID string, cmd []string) error
|
||||||
|
|
||||||
|
// ContainerCopy copies/extracts a source FileInfo to a destination path inside a container
|
||||||
// specified by a container object.
|
// specified by a container object.
|
||||||
// TODO: make an Extract method instead of passing `decompress`
|
// TODO: make an Extract method instead of passing `decompress`
|
||||||
// TODO: do not pass a FileInfo, instead refactor the archive package to export a Walk function that can be used
|
// TODO: do not pass a FileInfo, instead refactor the archive package to export a Walk function that can be used
|
||||||
// with Context.Walk
|
// with Context.Walk
|
||||||
Copy(c *container.Container, destPath string, src FileInfo, decompress bool) error
|
//ContainerCopy(name string, res string) (io.ReadCloser, error)
|
||||||
|
// TODO: use copyBackend api
|
||||||
|
BuilderCopy(containerID string, destPath string, src FileInfo, decompress bool) error
|
||||||
|
|
||||||
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
|
@ -137,14 +148,6 @@ type Docker interface {
|
||||||
// Release releases a list of images that were retained for the time of a build.
|
// Release releases a list of images that were retained for the time of a build.
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
Release(sessionID string, activeImages []string)
|
Release(sessionID string, activeImages []string)
|
||||||
// Kill stops the container execution abruptly.
|
|
||||||
Kill(c *container.Container) error
|
|
||||||
// Mount mounts the root filesystem for the container.
|
|
||||||
Mount(c *container.Container) error
|
|
||||||
// Unmount unmounts the root filesystem for the container.
|
|
||||||
Unmount(c *container.Container) error
|
|
||||||
// Start starts a new container
|
|
||||||
Start(c *container.Container) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageCache abstracts an image cache store.
|
// ImageCache abstracts an image cache store.
|
||||||
|
|
|
@ -77,7 +77,7 @@ type Builder struct {
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
Stderr io.Writer
|
Stderr io.Writer
|
||||||
|
|
||||||
docker builder.Docker
|
docker builder.Backend
|
||||||
context builder.Context
|
context builder.Context
|
||||||
|
|
||||||
dockerfile *parser.Node
|
dockerfile *parser.Node
|
||||||
|
@ -102,7 +102,7 @@ type Builder struct {
|
||||||
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config.
|
// NewBuilder creates a new Dockerfile builder from an optional dockerfile and a Config.
|
||||||
// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName,
|
// If dockerfile is nil, the Dockerfile specified by Config.DockerfileName,
|
||||||
// will be read from the Context passed to Build().
|
// will be read from the Context passed to Build().
|
||||||
func NewBuilder(config *Config, docker builder.Docker, context builder.Context, dockerfile io.ReadCloser) (b *Builder, err error) {
|
func NewBuilder(config *Config, docker builder.Backend, context builder.Context, dockerfile io.ReadCloser) (b *Builder, err error) {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = new(Config)
|
config = new(Config)
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
|
||||||
)
|
)
|
||||||
// TODO: don't use `name`, instead resolve it to a digest
|
// TODO: don't use `name`, instead resolve it to a digest
|
||||||
if !b.Pull {
|
if !b.Pull {
|
||||||
image, err = b.docker.LookupImage(name)
|
image, err = b.docker.GetImage(name)
|
||||||
// TODO: shouldn't we error out if error is different from "not found" ?
|
// TODO: shouldn't we error out if error is different from "not found" ?
|
||||||
}
|
}
|
||||||
if image == nil {
|
if image == nil {
|
||||||
|
@ -394,18 +394,12 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
|
||||||
|
|
||||||
logrus.Debugf("[BUILDER] Command to be executed: %v", b.runConfig.Cmd)
|
logrus.Debugf("[BUILDER] Command to be executed: %v", b.runConfig.Cmd)
|
||||||
|
|
||||||
c, err := b.create()
|
cID, err := b.create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that we keep the container mounted until the commit
|
if err := b.run(cID); err != nil {
|
||||||
// to avoid unmounting and then mounting directly again
|
|
||||||
b.docker.Mount(c)
|
|
||||||
defer b.docker.Unmount(c)
|
|
||||||
|
|
||||||
err = b.run(c)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,11 +408,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
|
||||||
// properly match it.
|
// properly match it.
|
||||||
b.runConfig.Env = env
|
b.runConfig.Env = env
|
||||||
b.runConfig.Cmd = saveCmd
|
b.runConfig.Cmd = saveCmd
|
||||||
if err := b.commit(c.ID, cmd, "run"); err != nil {
|
return b.commit(cID, cmd, "run")
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CMD foo
|
// CMD foo
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/builder"
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/builder/dockerfile/parser"
|
"github.com/docker/docker/builder/dockerfile/parser"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/httputils"
|
"github.com/docker/docker/pkg/httputils"
|
||||||
|
@ -56,21 +56,16 @@ func (b *Builder) commit(id string, autoCmd *stringutils.StrSlice, comment strin
|
||||||
}
|
}
|
||||||
defer func(cmd *stringutils.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
|
defer func(cmd *stringutils.StrSlice) { b.runConfig.Cmd = cmd }(cmd)
|
||||||
|
|
||||||
if hit, err := b.probeCache(); err != nil {
|
hit, err := b.probeCache()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if hit {
|
} else if hit {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
container, err := b.create()
|
id, err = b.create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
id = container.ID
|
|
||||||
|
|
||||||
if err := b.docker.Mount(container); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer b.docker.Unmount(container)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Actually copy the struct
|
// Note: Actually copy the struct
|
||||||
|
@ -192,11 +187,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
container, _, err := b.docker.Create(b.runConfig, nil)
|
container, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{Config: b.runConfig})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer b.docker.Unmount(container)
|
|
||||||
b.tmpContainers[container.ID] = struct{}{}
|
b.tmpContainers[container.ID] = struct{}{}
|
||||||
|
|
||||||
comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest)
|
comment := fmt.Sprintf("%s %s in %s", cmdName, origPaths, dest)
|
||||||
|
@ -214,15 +208,12 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
if err := b.docker.Copy(container, dest, info.FileInfo, info.decompress); err != nil {
|
if err := b.docker.BuilderCopy(container.ID, dest, info.FileInfo, info.decompress); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := b.commit(container.ID, cmd, comment); err != nil {
|
return b.commit(container.ID, cmd, comment)
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) download(srcURL string) (fi builder.FileInfo, err error) {
|
func (b *Builder) download(srcURL string) (fi builder.FileInfo, err error) {
|
||||||
|
@ -414,8 +405,8 @@ func (b *Builder) processImageFrom(img *image.Image) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default path will be blank on Windows (set by HCS)
|
// The default path will be blank on Windows (set by HCS)
|
||||||
if len(b.runConfig.Env) == 0 && container.DefaultPathEnv != "" {
|
if len(b.runConfig.Env) == 0 && system.DefaultPathEnv != "" {
|
||||||
b.runConfig.Env = append(b.runConfig.Env, "PATH="+container.DefaultPathEnv)
|
b.runConfig.Env = append(b.runConfig.Env, "PATH="+system.DefaultPathEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process ONBUILD triggers if they exist
|
// Process ONBUILD triggers if they exist
|
||||||
|
@ -487,9 +478,9 @@ func (b *Builder) probeCache() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) create() (*container.Container, error) {
|
func (b *Builder) create() (string, error) {
|
||||||
if b.image == "" && !b.noBaseImage {
|
if b.image == "" && !b.noBaseImage {
|
||||||
return nil, fmt.Errorf("Please provide a source image with `from` prior to run")
|
return "", fmt.Errorf("Please provide a source image with `from` prior to run")
|
||||||
}
|
}
|
||||||
b.runConfig.Image = b.image
|
b.runConfig.Image = b.image
|
||||||
|
|
||||||
|
@ -515,12 +506,14 @@ func (b *Builder) create() (*container.Container, error) {
|
||||||
config := *b.runConfig
|
config := *b.runConfig
|
||||||
|
|
||||||
// Create the container
|
// Create the container
|
||||||
c, warnings, err := b.docker.Create(b.runConfig, hostConfig)
|
c, err := b.docker.ContainerCreate(&daemon.ContainerCreateConfig{
|
||||||
|
Config: b.runConfig,
|
||||||
|
HostConfig: hostConfig,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
defer b.docker.Unmount(c)
|
for _, warning := range c.Warnings {
|
||||||
for _, warning := range warnings {
|
|
||||||
fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
|
fmt.Fprintf(b.Stdout, " ---> [Warning] %s\n", warning)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,23 +522,24 @@ func (b *Builder) create() (*container.Container, error) {
|
||||||
|
|
||||||
if config.Cmd.Len() > 0 {
|
if config.Cmd.Len() > 0 {
|
||||||
// override the entry point that may have been picked up from the base image
|
// override the entry point that may have been picked up from the base image
|
||||||
s := config.Cmd.Slice()
|
if err := b.docker.ContainerUpdateCmd(c.ID, config.Cmd.Slice()); err != nil {
|
||||||
c.Path = s[0]
|
return "", err
|
||||||
c.Args = s[1:]
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c, nil
|
return c.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) run(c *container.Container) error {
|
func (b *Builder) run(cID string) (err error) {
|
||||||
var errCh chan error
|
errCh := make(chan error)
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
errCh = c.Attach(nil, b.Stdout, b.Stderr)
|
go func() {
|
||||||
}
|
errCh <- b.docker.ContainerWsAttachWithLogs(cID, &daemon.ContainerWsAttachWithLogsConfig{
|
||||||
|
OutStream: b.Stdout,
|
||||||
//start the container
|
ErrStream: b.Stderr,
|
||||||
if err := b.docker.Start(c); err != nil {
|
Stream: true,
|
||||||
return err
|
})
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
finished := make(chan struct{})
|
finished := make(chan struct{})
|
||||||
|
@ -553,13 +547,17 @@ func (b *Builder) run(c *container.Container) error {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-b.cancelled:
|
case <-b.cancelled:
|
||||||
logrus.Debugln("Build cancelled, killing and removing container:", c.ID)
|
logrus.Debugln("Build cancelled, killing and removing container:", cID)
|
||||||
b.docker.Kill(c)
|
b.docker.ContainerKill(cID, 0)
|
||||||
b.removeContainer(c.ID)
|
b.removeContainer(cID)
|
||||||
case <-finished:
|
case <-finished:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := b.docker.ContainerStart(cID, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
// Block on reading output from container, stop on err or chan closed
|
// Block on reading output from container, stop on err or chan closed
|
||||||
if err := <-errCh; err != nil {
|
if err := <-errCh; err != nil {
|
||||||
|
@ -567,8 +565,7 @@ func (b *Builder) run(c *container.Container) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for it to finish
|
if ret, _ := b.docker.ContainerWait(cID, -1); ret != 0 {
|
||||||
if ret, _ := c.WaitStop(-1 * time.Second); ret != 0 {
|
|
||||||
// TODO: change error type, because jsonmessage.JSONError assumes HTTP
|
// TODO: change error type, because jsonmessage.JSONError assumes HTTP
|
||||||
return &jsonmessage.JSONError{
|
return &jsonmessage.JSONError{
|
||||||
Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", b.runConfig.Cmd.ToString(), ret),
|
Message: fmt.Sprintf("The command '%s' returned a non-zero code: %d", b.runConfig.Cmd.ToString(), ret),
|
||||||
|
@ -584,7 +581,7 @@ func (b *Builder) removeContainer(c string) error {
|
||||||
ForceRemove: true,
|
ForceRemove: true,
|
||||||
RemoveVolume: true,
|
RemoveVolume: true,
|
||||||
}
|
}
|
||||||
if err := b.docker.Remove(c, rmConfig); err != nil {
|
if err := b.docker.ContainerRm(c, rmConfig); err != nil {
|
||||||
fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
|
fmt.Fprintf(b.Stdout, "Error removing intermediate container %s: %v\n", stringid.TruncateID(c), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,8 @@ import (
|
||||||
"github.com/opencontainers/runc/libcontainer/label"
|
"github.com/opencontainers/runc/libcontainer/label"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container
|
||||||
// DefaultPathEnv is unix style list of directories to search for
|
const DefaultSHMSize int64 = 67108864
|
||||||
// executables. Each directory is separated from the next by a colon
|
|
||||||
// ':' character .
|
|
||||||
DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
||||||
|
|
||||||
// DefaultSHMSize is the default size (64MB) of the SHM which will be mounted in the container
|
|
||||||
DefaultSHMSize int64 = 67108864
|
|
||||||
)
|
|
||||||
|
|
||||||
// Container holds the fields specific to unixen implementations. See
|
// Container holds the fields specific to unixen implementations. See
|
||||||
// CommonContainer for standard fields common to all containers.
|
// CommonContainer for standard fields common to all containers.
|
||||||
|
@ -66,7 +59,7 @@ func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string
|
||||||
}
|
}
|
||||||
// Setup environment
|
// Setup environment
|
||||||
env := []string{
|
env := []string{
|
||||||
"PATH=" + DefaultPathEnv,
|
"PATH=" + system.DefaultPathEnv,
|
||||||
"HOSTNAME=" + fullHostname,
|
"HOSTNAME=" + fullHostname,
|
||||||
// Note: we don't set HOME here because it'll get autoset intelligently
|
// Note: we don't set HOME here because it'll get autoset intelligently
|
||||||
// based on the value of USER inside dockerinit, but only if it isn't
|
// based on the value of USER inside dockerinit, but only if it isn't
|
||||||
|
|
|
@ -7,10 +7,6 @@ import (
|
||||||
"github.com/docker/docker/volume"
|
"github.com/docker/docker/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultPathEnv is deliberately empty on Windows as the default path will be set by
|
|
||||||
// the container. Docker has no context of what the default path should be.
|
|
||||||
const DefaultPathEnv = ""
|
|
||||||
|
|
||||||
// Container holds fields specific to the Windows implementation. See
|
// Container holds fields specific to the Windows implementation. See
|
||||||
// CommonContainer for standard fields common to all containers.
|
// CommonContainer for standard fields common to all containers.
|
||||||
type Container struct {
|
type Container struct {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/builder"
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/container"
|
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
@ -25,21 +24,16 @@ import (
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Docker implements builder.Docker for the docker Daemon object.
|
// Docker implements builder.Backend for the docker Daemon object.
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
Daemon *daemon.Daemon
|
*daemon.Daemon
|
||||||
OutOld io.Writer
|
OutOld io.Writer
|
||||||
AuthConfigs map[string]types.AuthConfig
|
AuthConfigs map[string]types.AuthConfig
|
||||||
Archiver *archive.Archiver
|
Archiver *archive.Archiver
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure Docker implements builder.Docker
|
// ensure Docker implements builder.Backend
|
||||||
var _ builder.Docker = Docker{}
|
var _ builder.Backend = Docker{}
|
||||||
|
|
||||||
// LookupImage looks up a Docker image referenced by `name`.
|
|
||||||
func (d Docker) LookupImage(name string) (*image.Image, error) {
|
|
||||||
return d.Daemon.GetImage(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pull tells Docker to pull image referenced by `name`.
|
// Pull tells Docker to pull image referenced by `name`.
|
||||||
func (d Docker) Pull(name string) (*image.Image, error) {
|
func (d Docker) Pull(name string) (*image.Image, error) {
|
||||||
|
@ -79,38 +73,15 @@ func (d Docker) Pull(name string) (*image.Image, error) {
|
||||||
return d.Daemon.GetImage(name)
|
return d.Daemon.GetImage(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container looks up a Docker container referenced by `id`.
|
// ContainerUpdateCmd updates Path and Args for the container with ID cID.
|
||||||
func (d Docker) Container(id string) (*container.Container, error) {
|
func (d Docker) ContainerUpdateCmd(cID string, cmd []string) error {
|
||||||
return d.Daemon.GetContainer(id)
|
c, err := d.Daemon.GetContainer(cID)
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates a new Docker container and returns potential warnings
|
|
||||||
func (d Docker) Create(cfg *runconfig.Config, hostCfg *runconfig.HostConfig) (*container.Container, []string, error) {
|
|
||||||
ccr, err := d.Daemon.ContainerCreate(&daemon.ContainerCreateConfig{
|
|
||||||
Name: "",
|
|
||||||
Config: cfg,
|
|
||||||
HostConfig: hostCfg,
|
|
||||||
AdjustCPUShares: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return err
|
||||||
}
|
}
|
||||||
container, err := d.Container(ccr.ID)
|
c.Path = cmd[0]
|
||||||
if err != nil {
|
c.Args = cmd[1:]
|
||||||
return nil, ccr.Warnings, err
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
return container, ccr.Warnings, d.Mount(container)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove removes a container specified by `id`.
|
|
||||||
func (d Docker) Remove(id string, cfg *types.ContainerRmConfig) error {
|
|
||||||
return d.Daemon.ContainerRm(id, cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commit creates a new Docker image from an existing Docker container.
|
|
||||||
func (d Docker) Commit(name string, cfg *types.ContainerCommitConfig) (string, error) {
|
|
||||||
return d.Daemon.Commit(name, cfg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
// Retain retains an image avoiding it to be removed or overwritten until a corresponding Release() call.
|
||||||
|
@ -125,11 +96,11 @@ func (d Docker) Release(sessionID string, activeImages []string) {
|
||||||
//d.Daemon.Graph().Release(sessionID, activeImages...)
|
//d.Daemon.Graph().Release(sessionID, activeImages...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy copies/extracts a source FileInfo to a destination path inside a container
|
// BuilderCopy copies/extracts a source FileInfo to a destination path inside a container
|
||||||
// specified by a container object.
|
// specified by a container object.
|
||||||
// TODO: make sure callers don't unnecessarily convert destPath with filepath.FromSlash (Copy does it already).
|
// TODO: make sure callers don't unnecessarily convert destPath with filepath.FromSlash (Copy does it already).
|
||||||
// Copy should take in abstract paths (with slashes) and the implementation should convert it to OS-specific paths.
|
// BuilderCopy should take in abstract paths (with slashes) and the implementation should convert it to OS-specific paths.
|
||||||
func (d Docker) Copy(c *container.Container, destPath string, src builder.FileInfo, decompress bool) error {
|
func (d Docker) BuilderCopy(cID string, destPath string, src builder.FileInfo, decompress bool) error {
|
||||||
srcPath := src.Path()
|
srcPath := src.Path()
|
||||||
destExists := true
|
destExists := true
|
||||||
rootUID, rootGID := d.Daemon.GetRemappedUIDGID()
|
rootUID, rootGID := d.Daemon.GetRemappedUIDGID()
|
||||||
|
@ -137,6 +108,10 @@ func (d Docker) Copy(c *container.Container, destPath string, src builder.FileIn
|
||||||
// Work in daemon-local OS specific file paths
|
// Work in daemon-local OS specific file paths
|
||||||
destPath = filepath.FromSlash(destPath)
|
destPath = filepath.FromSlash(destPath)
|
||||||
|
|
||||||
|
c, err := d.Daemon.GetContainer(cID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
dest, err := c.GetResourcePath(destPath)
|
dest, err := c.GetResourcePath(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -211,27 +186,6 @@ func (d Docker) GetCachedImage(imgID string, cfg *runconfig.Config) (string, err
|
||||||
return cache.ID().String(), nil
|
return cache.ID().String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill stops the container execution abruptly.
|
|
||||||
func (d Docker) Kill(container *container.Container) error {
|
|
||||||
return d.Daemon.Kill(container)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount mounts the root filesystem for the container.
|
|
||||||
func (d Docker) Mount(c *container.Container) error {
|
|
||||||
return d.Daemon.Mount(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmount unmounts the root filesystem for the container.
|
|
||||||
func (d Docker) Unmount(c *container.Container) error {
|
|
||||||
d.Daemon.Unmount(c)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts a container
|
|
||||||
func (d Docker) Start(c *container.Container) error {
|
|
||||||
return d.Daemon.Start(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Following is specific to builder contexts
|
// Following is specific to builder contexts
|
||||||
|
|
||||||
// DetectContextFromRemoteURL returns a context and in certain cases the name of the dockerfile to be used
|
// DetectContextFromRemoteURL returns a context and in certain cases the name of the dockerfile to be used
|
||||||
|
|
|
@ -50,11 +50,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := daemon.containerStart(container); err != nil {
|
return daemon.containerStart(container)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts a container
|
// Start starts a container
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
// DefaultPathEnv is unix style list of directories to search for
|
||||||
|
// executables. Each directory is separated from the next by a colon
|
||||||
|
// ':' character .
|
||||||
|
const DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
@ -0,0 +1,7 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package system
|
||||||
|
|
||||||
|
// DefaultPathEnv is deliberately empty on Windows as the default path will be set by
|
||||||
|
// the container. Docker has no context of what the default path should be.
|
||||||
|
const DefaultPathEnv = ""
|
Loading…
Reference in New Issue