Skip to content

Commit

Permalink
Merge pull request #2147 from novilabs/docker-force-pull
Browse files Browse the repository at this point in the history
add force_pull to docker driver
  • Loading branch information
schmichael committed Jan 11, 2017
2 parents 9323ce7 + d4b8fc9 commit 2855090
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type DockerDriverConfig struct {
WorkDir string `mapstructure:"work_dir"` // Working directory inside the container
Logging []DockerLoggingOpts `mapstructure:"logging"` // Logging options for syslog server
Volumes []string `mapstructure:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container
ForcePull bool `mapstructure:"force_pull"` // Always force pull before running image, useful if your tags are mutable
}

// Validate validates a docker driver config
Expand Down Expand Up @@ -331,6 +332,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"volumes": &fields.FieldSchema{
Type: fields.TypeArray,
},
"force_pull": &fields.FieldSchema{
Type: fields.TypeBool,
},
},
}

Expand Down Expand Up @@ -890,9 +894,11 @@ func (d *DockerDriver) createImage(driverConfig *DockerDriverConfig, client *doc
var dockerImage *docker.Image
var err error
// We're going to check whether the image is already downloaded. If the tag
// is "latest" we have to check for a new version every time so we don't
// is "latest", or ForcePull is set, we have to check for a new version every time so we don't
// bother to check and cache the id here. We'll download first, then cache.
if tag != "latest" {
if driverConfig.ForcePull {
d.logger.Printf("[DEBUG] driver.docker: force pull image '%s:%s' instead of inspecting local", repo, tag)
} else if tag != "latest" {
dockerImage, err = client.InspectImage(image)
}

Expand Down
29 changes: 29 additions & 0 deletions client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,35 @@ func TestDockerDriver_Labels(t *testing.T) {
}
}

func TestDockerDriver_ForcePull_IsInvalidConfig(t *testing.T) {
task, _, _ := dockerTask()
task.Config["force_pull"] = "nothing"

ctx := testDriverContexts(t, task)
defer ctx.AllocDir.Destroy()
ctx.DriverCtx.config.Options = map[string]string{"docker.cleanup.image": "false"}
driver := NewDockerDriver(ctx.DriverCtx)

if err := driver.Prestart(ctx.ExecCtx, task); err == nil {
t.Fatalf("error expected in prestart")
}
}

func TestDockerDriver_ForcePull(t *testing.T) {
task, _, _ := dockerTask()
task.Config["force_pull"] = "true"

client, handle, cleanup := dockerSetup(t, task)
defer cleanup()

waitForExist(t, client, handle.(*DockerHandle))

_, err := client.InspectContainer(handle.(*DockerHandle).ContainerID())
if err != nil {
t.Fatalf("err: %v", err)
}
}

func TestDockerDriver_DNS(t *testing.T) {
task, _, _ := dockerTask()
task.Config["dns_servers"] = []string{"8.8.8.8", "8.8.4.4"}
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ The `docker` driver supports the following configuration in the job spec:
* `interactive` - (Optional) `true` or `false` (default). Keep STDIN open on
the container.

* `force_pull` - (Optional) `true` or `false` (default). Always pull latest image
instead of using existing local image. Should be set to `true` if repository tags
are mutable.

* `shm_size` - (Optional) The size (bytes) of /dev/shm for the container.

* `logging` - (Optional) A key-value map of Docker logging options. The default
Expand Down

0 comments on commit 2855090

Please sign in to comment.