mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 09:51:01 +00:00
Move docker specific volume & network settings into backend code (#1956)
... if we want to make them be changed ... it should be an agent-backend-option
This commit is contained in:
parent
89623471fb
commit
5393aa5d3b
4 changed files with 21 additions and 35 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
@ -41,6 +42,12 @@ type docker struct {
|
|||
volumes []string
|
||||
}
|
||||
|
||||
const (
|
||||
networkDriverNAT = "nat"
|
||||
networkDriverBridge = "bridge"
|
||||
volumeDriver = "local"
|
||||
)
|
||||
|
||||
// New returns a new Docker Engine.
|
||||
func New() backend.Engine {
|
||||
return &docker{
|
||||
|
@ -97,21 +104,22 @@ func (e *docker) Load(ctx context.Context) error {
|
|||
func (e *docker) Setup(_ context.Context, conf *backend.Config) error {
|
||||
for _, vol := range conf.Volumes {
|
||||
_, err := e.client.VolumeCreate(noContext, volume.VolumeCreateBody{
|
||||
Name: vol.Name,
|
||||
Driver: vol.Driver,
|
||||
DriverOpts: vol.DriverOpts,
|
||||
// Labels: defaultLabels,
|
||||
Name: vol.Name,
|
||||
Driver: volumeDriver,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
networkDriver := networkDriverBridge
|
||||
if runtime.GOOS == "windows" {
|
||||
networkDriver = networkDriverNAT
|
||||
}
|
||||
for _, n := range conf.Networks {
|
||||
_, err := e.client.NetworkCreate(noContext, n.Name, types.NetworkCreate{
|
||||
Driver: n.Driver,
|
||||
Options: n.DriverOpts,
|
||||
Driver: networkDriver,
|
||||
EnableIPv6: e.enableIPv6,
|
||||
// Labels: defaultLabels,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -2,7 +2,5 @@ package types
|
|||
|
||||
// Network defines a container network.
|
||||
type Network struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Driver string `json:"driver,omitempty"`
|
||||
DriverOpts map[string]string `json:"driver_opts,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
|
|
@ -2,7 +2,5 @@ package types
|
|||
|
||||
// Volume defines a container volume.
|
||||
type Volume struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Driver string `json:"driver,omitempty"`
|
||||
DriverOpts map[string]string `json:"driver_opts,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package compiler
|
|||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
backend_types "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
|
||||
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/metadata"
|
||||
|
@ -11,17 +10,9 @@ import (
|
|||
"github.com/woodpecker-ci/woodpecker/shared/constant"
|
||||
)
|
||||
|
||||
// TODO(bradrydzewski) compiler should handle user-defined volumes from YAML
|
||||
// TODO(bradrydzewski) compiler should handle user-defined networks from YAML
|
||||
|
||||
const (
|
||||
windowsPrefix = "windows/"
|
||||
|
||||
defaultCloneName = "clone"
|
||||
|
||||
networkDriverNAT = "nat"
|
||||
networkDriverBridge = "bridge"
|
||||
|
||||
nameServices = "services"
|
||||
namePipeline = "pipeline"
|
||||
)
|
||||
|
@ -114,22 +105,13 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
|||
|
||||
// create a default volume
|
||||
config.Volumes = append(config.Volumes, &backend_types.Volume{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
Driver: "local",
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
})
|
||||
|
||||
// create a default network
|
||||
if strings.HasPrefix(c.metadata.Sys.Platform, windowsPrefix) {
|
||||
config.Networks = append(config.Networks, &backend_types.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
Driver: networkDriverNAT,
|
||||
})
|
||||
} else {
|
||||
config.Networks = append(config.Networks, &backend_types.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
Driver: networkDriverBridge,
|
||||
})
|
||||
}
|
||||
config.Networks = append(config.Networks, &backend_types.Network{
|
||||
Name: fmt.Sprintf("%s_default", c.prefix),
|
||||
})
|
||||
|
||||
// create secrets for mask
|
||||
for _, sec := range c.secrets {
|
||||
|
|
Loading…
Reference in a new issue