Skip to content

Commit

Permalink
Deprecate detached
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Feb 18, 2024
1 parent 50ad97f commit a146500
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 38 deletions.
24 changes: 0 additions & 24 deletions docs/docs/20-usage/60-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@ Service containers generally expose environment variables to customize service s
image: redis
```
## Detachment
Service and long running containers can also be included in the pipeline section of the configuration using the detach parameter without blocking other steps. This should be used when explicit control over startup order is required.
```diff
steps:
- name: build
image: golang
commands:
- go build
- go test

- name: database
image: redis
+ detach: true

- name: test
image: golang
commands:
- go test
```
Containers from detached steps will terminate when the pipeline ends.
## Initialization
Service containers require time to initialize and begin to accept connections. If you are unable to connect to a service you may need to wait a few seconds or implement a backoff.
Expand Down
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Some versions need some changes to the server configuration or the pipeline conf
- Deprecated `includes` and `excludes` support from **event** filter
- Deprecated alternative names for secrets, use `environment` with `from_secret`
- Deprecated slice definition for labels and env vars
- Deprecated `detached` in favor of services

## 2.0.0

Expand Down
1 change: 0 additions & 1 deletion pipeline/backend/docker/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func TestToConfigFull(t *testing.T) {
Type: backend.StepTypeCommands,
Image: "golang:1.2.3",
Pull: true,
Detached: true,
Privileged: true,
WorkingDir: "/src/abc",
Environment: map[string]string{"TAGS": "sqlite"},
Expand Down
1 change: 0 additions & 1 deletion pipeline/backend/types/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Step struct {
Type StepType `json:"type,omitempty"`
Image string `json:"image,omitempty"`
Pull bool `json:"pull,omitempty"`
Detached bool `json:"detach,omitempty"`
Privileged bool `json:"privileged,omitempty"`
WorkingDir string `json:"working_dir,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
Expand Down
12 changes: 5 additions & 7 deletions pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
var (
uuid = ulid.Make()

detached bool
workingDir string

workspace = fmt.Sprintf("%s_default:%s", c.prefix, c.base)
Expand Down Expand Up @@ -80,11 +79,11 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe

environment["CI_WORKSPACE"] = path.Join(c.base, c.path)

if stepType == backend_types.StepTypeService || container.Detached {
detached = true
if container.Detached {
stepType = backend_types.StepTypeService
}

if !detached || len(container.Commands) != 0 {
if stepType != backend_types.StepTypeService || len(container.Commands) != 0 {
workingDir = c.stepWorkingDir(container)
}

Expand All @@ -104,8 +103,8 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
return secret.Value, nil
}

// TODO: why don't we pass secrets to detached steps?
if !detached {
// TODO: why don't we pass settings to services?
if stepType != backend_types.StepTypeService {
if err := settings.ParamsToEnv(container.Settings, environment, getSecretValue); err != nil {
return nil, err
}
Expand Down Expand Up @@ -187,7 +186,6 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
Type: stepType,
Image: container.Image,
Pull: container.Pull,
Detached: detached,
Privileged: privileged,
WorkingDir: workingDir,
Environment: environment,
Expand Down
17 changes: 16 additions & 1 deletion pipeline/frontend/yaml/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,29 @@ func (l *Linter) lintDeprecations(config *WorkflowConfig) (err error) {
Data: errors.DeprecationErrorData{
File: config.File,
Field: fmt.Sprintf("steps.%s.secrets[%d]", step.Name, i),
Docs: "https://woodpecker-ci.org/docs/usage/workflow-syntax#event",
Docs: "https://woodpecker-ci.org/docs/usage/secrets#use-secrets-in-settings-and-environment",
},
IsWarning: true,
})
}
}
}

for _, step := range parsed.Steps.ContainerList {
if step.Detached {
err = multierr.Append(err, &errors.PipelineError{
Type: errors.PipelineErrorTypeDeprecation,
Message: "Detached is deprecated, use services",
Data: errors.DeprecationErrorData{
File: config.File,
Field: fmt.Sprintf("steps.%s.detached", step.Name),
Docs: "https://woodpecker-ci.org/docs/usage/services",
},
IsWarning: true,
})
}
}

return err
}

Expand Down
1 change: 0 additions & 1 deletion pipeline/frontend/yaml/types/base/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ func TestStringOrIntYaml(t *testing.T) {
assert.Equal(t, StringOrInt(10), s2.Foo)
}
}

5 changes: 3 additions & 2 deletions pipeline/frontend/yaml/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type (
BackendOptions map[string]any `yaml:"backend_options,omitempty"`
Commands base.StringOrSlice `yaml:"commands,omitempty"`
Entrypoint base.StringOrSlice `yaml:"entrypoint,omitempty"`
Detached bool `yaml:"detach,omitempty"`
Directory string `yaml:"directory,omitempty"`
// Deprecated TODO remove in 3.x
Detached bool `yaml:"detach,omitempty"`
Directory string `yaml:"directory,omitempty"`
// TODO make map[string]string in 3.x
Environment base.SliceOrMap `yaml:"environment,omitempty"`
Failure string `yaml:"failure,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (r *Runtime) exec(step *backend.Step) (*backend.State, error) {
}

// nothing else to do, this is a detached process.
if step.Detached {
if step.Type == backend.StepTypeService {
return nil, nil
}

Expand Down

0 comments on commit a146500

Please sign in to comment.