Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Add Docker Driver configuration options (#661)
Browse files Browse the repository at this point in the history
* Remove Docker socket from file mounts in driver

* Add docker driver configuration options

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
  • Loading branch information
simonferquel authored and jeremyrickard committed Mar 11, 2019
1 parent 3cf48ef commit f52e8da
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pkg/driver/docker_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/strslice"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
Expand All @@ -26,8 +25,9 @@ import (
type DockerDriver struct {
config map[string]string
// If true, this will not actually run Docker
Simulate bool
dockerCli command.Cli
Simulate bool
dockerCli command.Cli
dockerConfigurationOptions []DockerConfigurationOption
}

// Run executes the Docker driver
Expand All @@ -40,6 +40,11 @@ func (d *DockerDriver) Handles(dt string) bool {
return dt == ImageTypeDocker || dt == ImageTypeOCI
}

// AddConfigurationOptions adds configuration callbacks to the driver
func (d *DockerDriver) AddConfigurationOptions(opts ...DockerConfigurationOption) {
d.dockerConfigurationOptions = append(d.dockerConfigurationOptions, opts...)
}

// Config returns the Docker driver configuration options
func (d *DockerDriver) Config() map[string]string {
return map[string]string{
Expand Down Expand Up @@ -127,13 +132,6 @@ func (d *DockerDriver) exec(op *Operation) error {
env = append(env, fmt.Sprintf("%s=%v", k, v))
}

mounts := []mount.Mount{
{
Type: mount.TypeBind,
Source: "/var/run/docker.sock",
Target: "/var/run/docker.sock",
},
}
cfg := &container.Config{
Image: op.Image,
Env: env,
Expand All @@ -142,7 +140,13 @@ func (d *DockerDriver) exec(op *Operation) error {
AttachStdout: true,
}

hostCfg := &container.HostConfig{Mounts: mounts, AutoRemove: true}
hostCfg := &container.HostConfig{AutoRemove: true}

for _, opt := range d.dockerConfigurationOptions {
if err := opt(cfg, hostCfg); err != nil {
return err
}
}

resp, err := cli.Client().ContainerCreate(ctx, cfg, hostCfg, nil, "")
switch {
Expand Down Expand Up @@ -234,3 +238,6 @@ func generateTar(files map[string]string) (io.Reader, error) {
}()
return r, nil
}

// DockerConfigurationOption is an option used to customize docker driver container and host config
type DockerConfigurationOption func(*container.Config, *container.HostConfig) error

0 comments on commit f52e8da

Please sign in to comment.