mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 08:31:57 +00:00
Add option to set default volumes for docker backend (#1203)
This commit is contained in:
@@ -23,6 +23,7 @@ type docker struct {
|
||||
client client.APIClient
|
||||
enableIPv6 bool
|
||||
network string
|
||||
volumes []string
|
||||
}
|
||||
|
||||
// make sure docker implements Engine
|
||||
@@ -59,6 +60,18 @@ func (e *docker) Load() error {
|
||||
|
||||
e.network = os.Getenv("WOODPECKER_BACKEND_DOCKER_NETWORK")
|
||||
|
||||
volumes := strings.Split(os.Getenv("WOODPECKER_BACKEND_DOCKER_VOLUMES"), ",")
|
||||
e.volumes = make([]string, 0, len(volumes))
|
||||
// Validate provided volume definitions
|
||||
for _, v := range volumes {
|
||||
parts, err := splitVolumeParts(v)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("invalid volume '%s' provided in WOODPECKER_BACKEND_DOCKER_VOLUMES", v)
|
||||
continue
|
||||
}
|
||||
e.volumes = append(e.volumes, strings.Join(parts, ":"))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -117,6 +130,9 @@ func (e *docker) Exec(ctx context.Context, proc *backend.Step) error {
|
||||
}
|
||||
}
|
||||
|
||||
// add default volumes to the host configuration
|
||||
hostConfig.Binds = append(hostConfig.Binds, e.volumes...)
|
||||
|
||||
_, err := e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, proc.Name)
|
||||
if client.IsErrNotFound(err) {
|
||||
// automatically pull and try to re-create the image if the
|
||||
|
Reference in New Issue
Block a user