Skip to content

Commit

Permalink
Merge branch 'main' into qwerty287-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jan 9, 2024
2 parents c799dc5 + a631353 commit 273196a
Show file tree
Hide file tree
Showing 28 changed files with 333 additions and 401 deletions.
16 changes: 8 additions & 8 deletions .woodpecker/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ steps:
publish-next-cli:
depends_on:
- vendor
# we also depend on cross-compile-server as we would have to hight
# we also depend on publish-next-agent as we would have to hight
# ram usage otherwise
- cross-compile-server
- publish-next-agent
image: *buildx_plugin
settings:
repo: *publish_repos_cli
Expand All @@ -475,9 +475,9 @@ steps:
publish-next-cli-alpine:
depends_on:
- vendor
# we also depend on cross-compile-server as we would have to hight
# we also depend on publish-next-agent as we would have to hight
# ram usage otherwise
- cross-compile-server
- publish-next-agent
image: *buildx_plugin
settings:
repo: *publish_repos_cli
Expand Down Expand Up @@ -526,9 +526,9 @@ steps:
release-cli:
depends_on:
- vendor
# we also depend on cross-compile-server as we would have to hight
# we also depend on release-agent as we would have to hight
# ram usage otherwise
- cross-compile-server
- release-agent
image: *buildx_plugin
settings:
repo: *publish_repos_cli
Expand All @@ -544,9 +544,9 @@ steps:
release-cli-alpine:
depends_on:
- vendor
# we also depend on cross-compile-server as we would have to hight
# we also depend on release-agent as we would have to hight
# ram usage otherwise
- cross-compile-server
- release-agent
image: *buildx_plugin
settings:
repo: *publish_repos_cli
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ clean: ## Clean build artifacts
rm -rf build
@[ "1" != "$(shell docker image ls woodpecker/make:local -a | wc -l)" ] && docker image rm woodpecker/make:local || echo no docker image to clean

.PHONY: clean-all
clean-all: clean ## Clean all artifacts
rm -rf dist web/dist docs/build docs/node_modules web/node_modules
# delete generated
rm -rf docs/docs/40-cli.md docs/swagger.json

.PHONY: generate
generate: generate-swagger ## Run all code generations
go generate ./...
Expand Down
2 changes: 1 addition & 1 deletion agent/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *Runner) createLogger(logger zerolog.Logger, uploads *sync.WaitGroup, wo
return func(step *backend.Step, rc multipart.Reader) error {
loglogger := logger.With().
Str("image", step.Image).
Str("stage", step.Alias).
Str("workflowID", workflow.ID).
Logger()

part, rerr := rc.NextPart()
Expand Down
6 changes: 3 additions & 3 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *client) Init(ctx context.Context, id string, state rpc.State) (err erro
req.State.Exited = state.Exited
req.State.Finished = state.Finished
req.State.Started = state.Started
req.State.Name = state.Step
req.State.StepUuid = state.StepUUID
for {
_, err = c.client.Init(ctx, req)
if err == nil {
Expand Down Expand Up @@ -211,7 +211,7 @@ func (c *client) Done(ctx context.Context, id string, state rpc.State) (err erro
req.State.Exited = state.Exited
req.State.Finished = state.Finished
req.State.Started = state.Started
req.State.Name = state.Step
req.State.StepUuid = state.StepUUID
for {
_, err = c.client.Done(ctx, req)
if err == nil {
Expand Down Expand Up @@ -286,7 +286,7 @@ func (c *client) Update(ctx context.Context, id string, state rpc.State) (err er
req.State.Exited = state.Exited
req.State.Finished = state.Finished
req.State.Started = state.Started
req.State.Name = state.Step
req.State.StepUuid = state.StepUUID
for {
_, err = c.client.Update(ctx, req)
if err == nil {
Expand Down
4 changes: 2 additions & 2 deletions agent/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (r *Runner) createTracer(ctxmeta context.Context, logger zerolog.Logger, wo
return func(state *pipeline.State) error {
steplogger := logger.With().
Str("image", state.Pipeline.Step.Image).
Str("stage", state.Pipeline.Step.Alias).
Str("workflowID", workflow.ID).
Err(state.Process.Error).
Int("exit_code", state.Process.ExitCode).
Bool("exited", state.Process.Exited).
Logger()

stepState := rpc.State{
Step: state.Pipeline.Step.Alias,
StepUUID: state.Pipeline.Step.UUID,
Exited: state.Process.Exited,
ExitCode: state.Process.ExitCode,
Started: time.Now().Unix(), // TODO do not do this
Expand Down
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ var defaultLogger = pipeline.LogFunc(func(step *backendTypes.Step, rc multipart.
return err
}

logStream := NewLineWriter(step.Alias, step.UUID)
logStream := NewLineWriter(step.Name, step.UUID)
_, err = io.Copy(logStream, part)
return err
})
92 changes: 47 additions & 45 deletions docs/docs/30-administration/22-backends/40-kubernetes.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,11 @@
---
toc_max_heading_level: 3
toc_max_heading_level: 2
---

# Kubernetes backend

The kubernetes backend executes steps inside standalone pods. A temporary PVC is created for the lifetime of the pipeline to transfer files between steps.

## General Configuration

These env vars can be set in the `env:` sections of both `server` and `agent`.
They do not need to be set for both but only for the part to which it is relevant to.

```yaml
server:
env:
WOODPECKER_SESSION_EXPIRES: "300h"
[...]

agent:
env:
[...]
```
- `WOODPECKER_BACKEND_K8S_NAMESPACE` (default: `woodpecker`)

The namespace to create worker pods in.

- `WOODPECKER_BACKEND_K8S_VOLUME_SIZE` (default: `10G`)

The volume size of the pipeline volume.

- `WOODPECKER_BACKEND_K8S_STORAGE_CLASS` (default: empty)

The storage class to use for the pipeline volume.

- `WOODPECKER_BACKEND_K8S_STORAGE_RWX` (default: `true`)

Determines if `RWX` should be used for the pipeline volume's [access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes). If false, `RWO` is used instead.

- `WOODPECKER_BACKEND_K8S_POD_LABELS` (default: empty)

Additional labels to apply to worker pods. Must be a YAML object, e.g. `{"example.com/test-label":"test-value"}`.

- `WOODPECKER_BACKEND_K8S_POD_ANNOTATIONS` (default: empty)

Additional annotations to apply to worker pods. Must be a YAML object, e.g. `{"example.com/test-annotation":"test-value"}`.

- `WOODPECKER_BACKEND_K8S_SECCTX_NONROOT` (default: `false`)

Determines if containers must be required to run as non-root users.

## Job specific configuration

### Resources
Expand Down Expand Up @@ -213,3 +169,49 @@ workspace:
```

See [this issue](https://github.com/woodpecker-ci/woodpecker/issues/2510) for more details.

## Configuration

These env vars can be set in the `env:` sections of the agent.

### `WOODPECKER_BACKEND_K8S_NAMESPACE`

> Default: `woodpecker`

The namespace to create worker pods in.

### `WOODPECKER_BACKEND_K8S_VOLUME_SIZE`

> Default: `10G`

The volume size of the pipeline volume.

### `WOODPECKER_BACKEND_K8S_STORAGE_CLASS`

> Default: empty

The storage class to use for the pipeline volume.

### `WOODPECKER_BACKEND_K8S_STORAGE_RWX`

> Default: `true`

Determines if `RWX` should be used for the pipeline volume's [access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes). If false, `RWO` is used instead.

### `WOODPECKER_BACKEND_K8S_POD_LABELS`

> Default: empty

Additional labels to apply to worker pods. Must be a YAML object, e.g. `{"example.com/test-label":"test-value"}`.

### `WOODPECKER_BACKEND_K8S_POD_ANNOTATIONS`

> Default: empty

Additional annotations to apply to worker pods. Must be a YAML object, e.g. `{"example.com/test-annotation":"test-value"}`.

### `WOODPECKER_BACKEND_K8S_SECCTX_NONROOT`

> Default: `false`

Determines if containers must be required to run as non-root users.
10 changes: 5 additions & 5 deletions pipeline/backend/docker/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
AttachStdout: true,
AttachStderr: true,
}
env := make(map[string]string)
maps.Copy(env, step.Environment)
configEnv := make(map[string]string)
maps.Copy(configEnv, step.Environment)

if len(step.Commands) != 0 {
env, entry, cmd := common.GenerateContainerConf(step.Commands, e.info.OSType)
for k, v := range env {
env[k] = v
configEnv[k] = v
}
config.Entrypoint = entry
config.Cmd = cmd
}

if len(env) != 0 {
config.Env = toEnv(env)
if len(configEnv) != 0 {
config.Env = toEnv(configEnv)
}
if len(step.Volumes) != 0 {
config.Volumes = toVol(step.Volumes)
Expand Down
7 changes: 7 additions & 0 deletions pipeline/backend/docker/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package docker

import (
"reflect"
"sort"
"testing"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -102,6 +103,7 @@ func TestToConfigSmall(t *testing.T) {
})

assert.NotNil(t, conf)
sort.Strings(conf.Env)
assert.EqualValues(t, &container.Config{
AttachStdout: true,
AttachStderr: true,
Expand All @@ -111,5 +113,10 @@ func TestToConfigSmall(t *testing.T) {
"wp_step": "test",
"wp_uuid": "09238932",
},
Env: []string{
"CI_SCRIPT=CmlmIFsgLW4gIiRDSV9ORVRSQ19NQUNISU5FIiBdOyB0aGVuCmNhdCA8PEVPRiA+ICRIT01FLy5uZXRyYwptYWNoaW5lICRDSV9ORVRSQ19NQUNISU5FCmxvZ2luICRDSV9ORVRSQ19VU0VSTkFNRQpwYXNzd29yZCAkQ0lfTkVUUkNfUEFTU1dPUkQKRU9GCmNobW9kIDA2MDAgJEhPTUUvLm5ldHJjCmZpCnVuc2V0IENJX05FVFJDX1VTRVJOQU1FCnVuc2V0IENJX05FVFJDX1BBU1NXT1JECnVuc2V0IENJX1NDUklQVAoKZWNobyArICdnbyB0ZXN0JwpnbyB0ZXN0Cg==",
"HOME=/root",
"SHELL=/bin/sh",
},
}, conf)
}
2 changes: 0 additions & 2 deletions pipeline/backend/types/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ package types

// Stage denotes a collection of one or more steps.
type Stage struct {
Name string `json:"name,omitempty"`
Alias string `json:"alias,omitempty"`
Steps []*Step `json:"steps,omitempty"`
}
1 change: 0 additions & 1 deletion pipeline/backend/types/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Step struct {
Name string `json:"name"`
UUID string `json:"uuid"`
Type StepType `json:"type,omitempty"`
Alias string `json:"alias,omitempty"`
Image string `json:"image,omitempty"`
Pull bool `json:"pull,omitempty"`
Detached bool `json:"detach,omitempty"`
Expand Down
Loading

0 comments on commit 273196a

Please sign in to comment.