mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-01 18:24:03 +00:00
Move docker resource limit settings from server to agent (#3174)
so you can set it per agent and not per server
This commit is contained in:
@@ -40,11 +40,9 @@ import (
|
||||
)
|
||||
|
||||
type docker struct {
|
||||
client client.APIClient
|
||||
enableIPv6 bool
|
||||
network string
|
||||
volumes []string
|
||||
info system.Info
|
||||
client client.APIClient
|
||||
info system.Info
|
||||
config config
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -132,22 +130,9 @@ func (e *docker) Load(ctx context.Context) (*backend.BackendInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
e.enableIPv6 = c.Bool("backend-docker-ipv6")
|
||||
e.network = c.String("backend-docker-network")
|
||||
|
||||
volumes := strings.Split(c.String("backend-docker-volumes"), ",")
|
||||
e.volumes = make([]string, 0, len(volumes))
|
||||
// Validate provided volume definitions
|
||||
for _, v := range volumes {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
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, ":"))
|
||||
e.config, err = configFromCli(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &backend.BackendInfo{
|
||||
@@ -175,7 +160,7 @@ func (e *docker) SetupWorkflow(ctx context.Context, conf *backend.Config, taskUU
|
||||
for _, n := range conf.Networks {
|
||||
_, err := e.client.NetworkCreate(ctx, n.Name, network.CreateOptions{
|
||||
Driver: networkDriver,
|
||||
EnableIPv6: &e.enableIPv6,
|
||||
EnableIPv6: &e.config.enableIPv6,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -188,7 +173,7 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
|
||||
log.Trace().Str("taskUUID", taskUUID).Msgf("start step %s", step.Name)
|
||||
|
||||
config := e.toConfig(step)
|
||||
hostConfig := toHostConfig(step)
|
||||
hostConfig := toHostConfig(step, &e.config)
|
||||
containerName := toContainerName(step)
|
||||
|
||||
// create pull options with encoded authorization credentials.
|
||||
@@ -217,7 +202,7 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
|
||||
}
|
||||
|
||||
// add default volumes to the host configuration
|
||||
hostConfig.Binds = utils.DeduplicateStrings(append(hostConfig.Binds, e.volumes...))
|
||||
hostConfig.Binds = utils.DeduplicateStrings(append(hostConfig.Binds, e.config.volumes...))
|
||||
|
||||
_, err := e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, containerName)
|
||||
if client.IsErrNotFound(err) {
|
||||
@@ -251,8 +236,8 @@ func (e *docker) StartStep(ctx context.Context, step *backend.Step, taskUUID str
|
||||
}
|
||||
|
||||
// join the container to an existing network
|
||||
if e.network != "" {
|
||||
err = e.client.NetworkConnect(ctx, e.network, containerName, &network.EndpointSettings{})
|
||||
if e.config.network != "" {
|
||||
err = e.client.NetworkConnect(ctx, e.config.network, containerName, &network.EndpointSettings{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user