This commit is contained in:
pat-s 2024-04-16 22:07:54 +02:00
parent d494b6a959
commit 54de4e6515
No known key found for this signature in database
GPG key ID: 3C6318841EF78925
9 changed files with 43 additions and 200 deletions

View file

@ -96,7 +96,7 @@ steps:
- apt install -y tree
- make cross-compile-server
environment:
PLATFORMS: linux|amd64
PLATFORMS: linux|arm64
TAGS: bindata sqlite sqlite_unlock_notify netgo
XGO_VERSION: *xgo_version
when:
@ -135,24 +135,24 @@ steps:
settings:
repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server.multiarch
platforms: *platforms_preview
platforms: linux/arm64
tag: pull_${CI_COMMIT_PULL_REQUEST}
logins: *publish_logins
when: &when-preview
evaluate: 'CI_COMMIT_PULL_REQUEST_LABELS contains "build_pr_images"'
event: pull_request
publish-server-alpine-preview:
depends_on:
- cross-compile-server-preview
image: *buildx_plugin
settings:
repo: woodpeckerci/woodpecker-server
dockerfile: docker/Dockerfile.server.alpine.multiarch
platforms: *platforms_preview
tag: pull_${CI_COMMIT_PULL_REQUEST}-alpine
logins: *publish_logins
when: *when-preview
# publish-server-alpine-preview:
# depends_on:
# - cross-compile-server-preview
# image: *buildx_plugin
# settings:
# repo: woodpeckerci/woodpecker-server
# dockerfile: docker/Dockerfile.server.alpine.multiarch
# platforms: linux/arm64
# tag: pull_${CI_COMMIT_PULL_REQUEST}-alpine
# logins: *publish_logins
# when: *when-preview
build-server-dryrun:
depends_on:
@ -239,7 +239,7 @@ steps:
settings:
repo: woodpeckerci/woodpecker-agent
dockerfile: docker/Dockerfile.agent.multiarch
platforms: *platforms_preview
platforms: linux/arm64
tag: pull_${CI_COMMIT_PULL_REQUEST}
build_args: *build_args
logins: *publish_logins
@ -331,18 +331,18 @@ steps:
# C L I #
#########
publish-cli-preview:
depends_on:
- vendor
image: *buildx_plugin
settings:
repo: woodpeckerci/woodpecker-cli
dockerfile: docker/Dockerfile.cli.multiarch
platforms: *platforms_preview
tag: pull_${CI_COMMIT_PULL_REQUEST}
build_args: *build_args
logins: *publish_logins
when: *when-preview
# publish-cli-preview:
# depends_on:
# - vendor
# image: *buildx_plugin
# settings:
# repo: woodpeckerci/woodpecker-cli
# dockerfile: docker/Dockerfile.cli.multiarch
# platforms: *platforms_preview
# tag: pull_${CI_COMMIT_PULL_REQUEST}
# build_args: *build_args
# logins: *publish_logins
# when: *when-preview
build-cli-dryrun:
depends_on:

View file

@ -1,160 +0,0 @@
variables:
- &golang_image 'docker.io/golang:1.21.5'
- &when
- path: &when_path # related config files
- '.woodpecker/test.yaml'
- '.golangci.yaml'
# go source code
- '**/*.go'
- 'go.*'
# schema changes
- 'pipeline/schema/**'
event: pull_request
- event: push
branch: renovate/*
path: *when_path
when:
- event: pull_request
- event: push
branch: renovate/*
- event: push
branch: ${CI_REPO_DEFAULT_BRANCH}
path: *when_path
steps:
vendor:
image: *golang_image
commands:
- go mod vendor
when:
path:
- <<: *when_path
- '.woodpecker/**'
lint-pipeline:
depends_on:
- vendor
image: *golang_image
commands:
- go run go.woodpecker-ci.org/woodpecker/v2/cmd/cli lint
environment:
WOODPECKER_DISABLE_UPDATE_CHECK: true
when:
- event: pull_request
path:
- '.woodpecker/**'
dummy-web:
image: *golang_image
commands:
- mkdir -p web/dist/
- echo "test" > web/dist/index.html
when:
- path: *when_path
lint:
depends_on:
- vendor
image: *golang_image
commands:
- make lint
when: *when
check-swagger:
depends_on:
- vendor
image: *golang_image
commands:
- 'make generate-swagger'
- 'DIFF=$(git diff | head)'
- '[ -n "$DIFF" ] && { echo "swagger not up to date, exec `make generate-swagger` and commit"; exit 1; } || true'
when: *when
lint-license-header:
image: *golang_image
commands:
- go install github.com/google/addlicense@latest
- 'addlicense -check -ignore "vendor/**" **/*.go'
when: *when
test:
depends_on:
- vendor
image: *golang_image
commands:
- make test-agent
- make test-server
- make test-cli
- make test-lib
when:
- path: *when_path
sqlite:
depends_on:
- vendor
image: *golang_image
environment:
WOODPECKER_DATABASE_DRIVER: sqlite3
commands:
- make test-server-datastore-coverage
when:
- path: *when_path
postgres:
depends_on:
- vendor
image: *golang_image
environment:
WOODPECKER_DATABASE_DRIVER: postgres
WOODPECKER_DATABASE_DATASOURCE: 'host=postgres user=postgres dbname=postgres sslmode=disable'
commands:
- make test-server-datastore
when: *when
mysql:
depends_on:
- vendor
image: *golang_image
environment:
WOODPECKER_DATABASE_DRIVER: mysql
WOODPECKER_DATABASE_DATASOURCE: root@tcp(mysql:3306)/test?parseTime=true
commands:
- make test-server-datastore
when: *when
codecov:
depends_on:
- test
- sqlite
pull: true
image: docker.io/woodpeckerci/plugin-codecov:2.1.2
settings:
files:
- agent-coverage.out
- cli-coverage.out
- coverage.out
- server-coverage.out
- datastore-coverage.out
token:
from_secret: codecov_token
when:
- path: *when_path
failure: ignore
services:
postgres:
image: docker.io/postgres:16
ports: ['5432']
environment:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
when: *when
mysql:
image: docker.io/mysql:8.2.0
ports: ['3306']
environment:
MYSQL_DATABASE: test
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
when: *when

View file

@ -106,20 +106,11 @@ func toHostConfig(step *types.Step) *container.HostConfig {
if len(step.Devices) != 0 {
config.Devices = toDev(step.Devices)
}
if len(step.Volumes) != 0 {
if !step.UseTmpfs {
config.Binds = step.Volumes
}
config.Tmpfs = map[string]string{}
for _, path := range step.Tmpfs {
if !strings.Contains(path, ":") {
config.Tmpfs[path] = ""
continue
}
parts, err := splitVolumeParts(path)
if err != nil {
continue
}
config.Tmpfs[parts[0]] = parts[1]
} else {
config.Tmpfs = map[string]string{"/woodpecker": ""}
}
return config

View file

@ -154,6 +154,7 @@ func TestToConfigFull(t *testing.T) {
AuthConfig: backend.Auth{Username: "user", Password: "123456"},
NetworkMode: "bridge",
Ports: []backend.Port{{Number: 21}, {Number: 22}},
UseTmpfs: true,
})
assert.NotNil(t, conf)

View file

@ -213,7 +213,11 @@ 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...))
if step.UseTmpfs {
hostConfig.Binds = e.volumes
} else {
hostConfig.Binds = utils.DeduplicateStrings(append(hostConfig.Binds, e.volumes...))
}
_, err := e.client.ContainerCreate(ctx, config, hostConfig, nil, nil, containerName)
if client.IsErrNotFound(err) {

View file

@ -47,6 +47,7 @@ type Step struct {
NetworkMode string `json:"network_mode,omitempty"`
Ports []Port `json:"ports,omitempty"`
BackendOptions map[string]any `json:"backend_options,omitempty"`
UseTmpfs bool `json:"use_tmpfs,omitempty"`
}
// StepType identifies the type of step

View file

@ -215,6 +215,7 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
NetworkMode: networkMode,
Ports: ports,
BackendOptions: container.BackendOptions,
UseTmpfs: container.UseTmpfs,
}, nil
}

View file

@ -371,6 +371,10 @@
},
"backend_options": {
"$ref": "#/definitions/step_backend_options"
},
"use_tmpfs": {
"description": "Use a tmpfs volume instead of a local volume for the working directory mount",
"type": "boolean"
}
}
},

View file

@ -71,6 +71,7 @@ type (
Networks Networks `yaml:"networks,omitempty"`
ShmSize base.MemStringOrInt `yaml:"shm_size,omitempty"`
Tmpfs []string `yaml:"tmpfs,omitempty"`
UseTmpfs bool `yaml:"use_tmpfs,omitempty"`
}
)