From 54de4e651558dbf83c74f76a00bee390e9f1b556 Mon Sep 17 00:00:00 2001 From: pat-s Date: Tue, 16 Apr 2024 22:07:54 +0200 Subject: [PATCH] test --- .woodpecker/docker.yaml | 52 +++--- .woodpecker/test.yaml | 160 ------------------ pipeline/backend/docker/convert.go | 17 +- pipeline/backend/docker/convert_test.go | 1 + pipeline/backend/docker/docker.go | 6 +- pipeline/backend/types/step.go | 1 + pipeline/frontend/yaml/compiler/convert.go | 1 + .../frontend/yaml/linter/schema/schema.json | 4 + pipeline/frontend/yaml/types/container.go | 1 + 9 files changed, 43 insertions(+), 200 deletions(-) delete mode 100644 .woodpecker/test.yaml diff --git a/.woodpecker/docker.yaml b/.woodpecker/docker.yaml index 592a2030a..d47368608 100644 --- a/.woodpecker/docker.yaml +++ b/.woodpecker/docker.yaml @@ -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: diff --git a/.woodpecker/test.yaml b/.woodpecker/test.yaml deleted file mode 100644 index 8c5e2b0cd..000000000 --- a/.woodpecker/test.yaml +++ /dev/null @@ -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 diff --git a/pipeline/backend/docker/convert.go b/pipeline/backend/docker/convert.go index 1e4ad589b..8459041eb 100644 --- a/pipeline/backend/docker/convert.go +++ b/pipeline/backend/docker/convert.go @@ -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 diff --git a/pipeline/backend/docker/convert_test.go b/pipeline/backend/docker/convert_test.go index 435d669b4..9aabed901 100644 --- a/pipeline/backend/docker/convert_test.go +++ b/pipeline/backend/docker/convert_test.go @@ -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) diff --git a/pipeline/backend/docker/docker.go b/pipeline/backend/docker/docker.go index 2c7a0e835..a9c264987 100644 --- a/pipeline/backend/docker/docker.go +++ b/pipeline/backend/docker/docker.go @@ -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) { diff --git a/pipeline/backend/types/step.go b/pipeline/backend/types/step.go index 9eb61fc06..62ebdacd1 100644 --- a/pipeline/backend/types/step.go +++ b/pipeline/backend/types/step.go @@ -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 diff --git a/pipeline/frontend/yaml/compiler/convert.go b/pipeline/frontend/yaml/compiler/convert.go index c36ef9734..c4686d4aa 100644 --- a/pipeline/frontend/yaml/compiler/convert.go +++ b/pipeline/frontend/yaml/compiler/convert.go @@ -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 } diff --git a/pipeline/frontend/yaml/linter/schema/schema.json b/pipeline/frontend/yaml/linter/schema/schema.json index 13d7af690..9f0614912 100644 --- a/pipeline/frontend/yaml/linter/schema/schema.json +++ b/pipeline/frontend/yaml/linter/schema/schema.json @@ -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" } } }, diff --git a/pipeline/frontend/yaml/types/container.go b/pipeline/frontend/yaml/types/container.go index 363ed189f..fa649dccd 100644 --- a/pipeline/frontend/yaml/types/container.go +++ b/pipeline/frontend/yaml/types/container.go @@ -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"` } )