mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
Add support to define a custom docker network and enable docker ipv6 (#893)
- Add support to define a custom docker network and enable docker ipv6 - Adjust docs
This commit is contained in:
parent
9c6c4559a7
commit
62a1fd8dcb
4 changed files with 68 additions and 43 deletions
|
@ -155,6 +155,10 @@ Configures if the gRPC server certificate should be verified, only valid when `W
|
||||||
|
|
||||||
Configures the backend engine to run pipelines on. Possible values are `auto-detect`, `docker`, `local` or `ssh`.
|
Configures the backend engine to run pipelines on. Possible values are `auto-detect`, `docker`, `local` or `ssh`.
|
||||||
|
|
||||||
|
### `WOODPECKER_BACKEND_DOCKER_*`
|
||||||
|
|
||||||
|
See [Docker backend configuration](backends/docker/#configuration)
|
||||||
|
|
||||||
### `WOODPECKER_BACKEND_SSH_*`
|
### `WOODPECKER_BACKEND_SSH_*`
|
||||||
|
|
||||||
See [SSH backend configuration](backends/ssh/#configuration)
|
See [SSH backend configuration](backends/ssh/#configuration)
|
||||||
|
|
|
@ -1 +1,15 @@
|
||||||
# Docker backend
|
# Docker backend
|
||||||
|
|
||||||
|
This is the original backend used with Woodpecker. The docker backend executes each step inside a separate container started on the agent.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### `WOODPECKER_BACKEND_DOCKER_NETWORK`
|
||||||
|
> Default: empty
|
||||||
|
|
||||||
|
Set to the name of an existing network which will be attached to all your pipeline containers (steps). Please be careful as this allows the containers of different piplines to access each other!
|
||||||
|
|
||||||
|
### `WOODPECKER_BACKEND_DOCKER_ENABLE_IPV6`
|
||||||
|
> Default: `false`
|
||||||
|
|
||||||
|
Enable IPv6 for the networks used by pipeline containers (steps). Make sure you configured your docker daemon to support IPv6.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -19,7 +20,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type docker struct {
|
type docker struct {
|
||||||
client client.APIClient
|
client client.APIClient
|
||||||
|
enableIPv6 bool
|
||||||
|
network string
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure docker implements Engine
|
// make sure docker implements Engine
|
||||||
|
@ -52,6 +55,10 @@ func (e *docker) Load() error {
|
||||||
}
|
}
|
||||||
e.client = cli
|
e.client = cli
|
||||||
|
|
||||||
|
e.enableIPv6, _ = strconv.ParseBool(os.Getenv("WOODPECKER_BACKEND_DOCKER_ENABLE_IPV6"))
|
||||||
|
|
||||||
|
e.network = os.Getenv("WOODPECKER_BACKEND_DOCKER_NETWORK")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +76,9 @@ func (e *docker) Setup(_ context.Context, conf *backend.Config) error {
|
||||||
}
|
}
|
||||||
for _, n := range conf.Networks {
|
for _, n := range conf.Networks {
|
||||||
_, err := e.client.NetworkCreate(noContext, n.Name, types.NetworkCreate{
|
_, err := e.client.NetworkCreate(noContext, n.Name, types.NetworkCreate{
|
||||||
Driver: n.Driver,
|
Driver: n.Driver,
|
||||||
Options: n.DriverOpts,
|
Options: n.DriverOpts,
|
||||||
|
EnableIPv6: e.enableIPv6,
|
||||||
// Labels: defaultLabels,
|
// Labels: defaultLabels,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -137,16 +145,15 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if proc.Network != "host" { // or bridge, overlay, none, internal, container:<name> ....
|
// join the container to an existing network
|
||||||
// err = e.client.NetworkConnect(ctx, proc.Network, proc.Name, &network.EndpointSettings{
|
if e.network != "" {
|
||||||
// Aliases: proc.NetworkAliases,
|
err = e.client.NetworkConnect(ctx, e.network, proc.Name, &network.EndpointSettings{})
|
||||||
// })
|
if err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
return e.client.ContainerStart(ctx, proc.Name, startOpts)
|
return e.client.ContainerStart(ctx, proc.Name, startOpts)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue