support for defining docker network opts

This commit is contained in:
Brad Rydzewski
2020-08-11 09:03:07 -04:00
parent 1a896dcf10
commit 06b89a91b4
5 changed files with 31 additions and 22 deletions

View File

@@ -52,6 +52,7 @@ type Config struct {
Volumes map[string]string `envconfig:"DRONE_RUNNER_VOLUMES"`
Devices []string `envconfig:"DRONE_RUNNER_DEVICES"`
Networks []string `envconfig:"DRONE_RUNNER_NETWORKS"`
NetworkOpts map[string]string `envconfig:"DRONE_RUNNER_NETWORK_OPTS"`
Privileged []string `envconfig:"DRONE_RUNNER_PRIVILEGED_IMAGES"`
Clone string `envconfig:"DRONE_RUNNER_CLONE_IMAGE"`
}

View File

@@ -123,6 +123,7 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error {
Clone: config.Runner.Clone,
Privileged: append(config.Runner.Privileged, compiler.Privileged...),
Networks: config.Runner.Networks,
NetworkOpts: config.Runner.NetworkOpts,
Volumes: config.Runner.Volumes,
Resources: compiler.Resources{
Memory: config.Resources.Memory,

View File

@@ -73,6 +73,10 @@ type Compiler struct {
// attached to each pipeline container.
Networks []string
// NetworkOpts provides a set of network options that
// are used when creating the docker network.
NetworkOpts map[string]string
// Volumes provides a set of volumes that should be
// mounted to each pipeline container.
Volumes map[string]string
@@ -156,6 +160,7 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti
Network: engine.Network{
ID: random(),
Labels: labels,
Options: c.NetworkOpts,
},
Platform: engine.Platform{
OS: pipeline.Platform.OS,

View File

@@ -84,6 +84,7 @@ func (e *Docker) Setup(ctx context.Context, specv runtime.Spec) error {
}
_, err := e.client.NetworkCreate(ctx, spec.Network.ID, types.NetworkCreate{
Driver: driver,
Options: spec.Network.Options,
Labels: spec.Network.Labels,
})

View File

@@ -119,6 +119,7 @@ type (
Network struct {
ID string `json:"id,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Options map[string]string `json:"options,omitempty"`
}
// Auth defines dockerhub authentication credentials.