Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused cache properties #3567

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ func podSpec(step *types.Step, config *config, options BackendOptions) (v1.PodSp
func podContainer(step *types.Step, podName, goos string, options BackendOptions) (v1.Container, error) {
var err error
container := v1.Container{
Name: podName,
Image: step.Image,
WorkingDir: step.WorkingDir,
Name: podName,
Image: step.Image,
WorkingDir: step.WorkingDir,
Env: mapToEnvVars(step.Environment),
Ports: containerPorts(step.Ports),
SecurityContext: containerSecurityContext(options.SecurityContext, step.Privileged),
}

if step.Pull {
Expand All @@ -154,10 +157,6 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
maps.Copy(step.Environment, scriptEnv)
}

container.Env = mapToEnvVars(step.Environment)
container.Ports = containerPorts(step.Ports)
container.SecurityContext = containerSecurityContext(options.SecurityContext, step.Privileged)

container.Resources, err = resourceRequirements(options.Resources)
if err != nil {
return container, err
Expand Down
117 changes: 0 additions & 117 deletions pipeline/frontend/yaml/compiler/cacher.go

This file was deleted.

57 changes: 2 additions & 55 deletions pipeline/frontend/yaml/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package compiler

import (
"fmt"
"path"

backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/metadata"
Expand All @@ -34,7 +33,6 @@ type Registry struct {
Hostname string
Username string
Password string
Token string
}

type Secret struct {
Expand Down Expand Up @@ -68,7 +66,7 @@ func (s *Secret) Match(event string) bool {
if len(s.Events) == 0 {
return true
}
// tread all pull events the same way
// treat all pull events the same way
if event == "pull_request_closed" {
event = "pull_request"
}
Expand All @@ -82,8 +80,6 @@ func (s *Secret) Match(event string) bool {
return false
}

type secretMap map[string]Secret

type ResourceLimit struct {
MemSwapLimit int64
MemLimit int64
Expand All @@ -106,8 +102,7 @@ type Compiler struct {
path string
metadata metadata.Metadata
registries []Registry
secrets secretMap
cacher Cacher
secrets map[string]Secret
reslimit ResourceLimit
defaultCloneImage string
trustedPipeline bool
Expand Down Expand Up @@ -224,11 +219,6 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
}
}

err := c.setupCache(conf, config)
if err != nil {
return nil, err
}

// add services steps
if len(conf.Services.ContainerList) != 0 {
stage := new(backend_types.Stage)
Expand Down Expand Up @@ -297,48 +287,5 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er

config.Stages = append(config.Stages, stepStages...)

err = c.setupCacheRebuild(conf, config)
if err != nil {
return nil, err
}

return config, nil
}

func (c *Compiler) setupCache(conf *yaml_types.Workflow, ir *backend_types.Config) error {
if c.local || len(conf.Cache) == 0 || c.cacher == nil {
return nil
}

container := c.cacher.Restore(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)
step, err := c.createProcess(container, backend_types.StepTypeCache)
if err != nil {
return err
}

stage := new(backend_types.Stage)
stage.Steps = append(stage.Steps, step)

ir.Stages = append(ir.Stages, stage)

return nil
}

func (c *Compiler) setupCacheRebuild(conf *yaml_types.Workflow, ir *backend_types.Config) error {
if c.local || len(conf.Cache) == 0 || c.metadata.Curr.Event != metadata.EventPush || c.cacher == nil {
return nil
}
container := c.cacher.Rebuild(path.Join(c.metadata.Repo.Owner, c.metadata.Repo.Name), c.metadata.Curr.Commit.Branch, conf.Cache)

step, err := c.createProcess(container, backend_types.StepTypeCache)
if err != nil {
return err
}

stage := new(backend_types.Stage)
stage.Steps = append(stage.Steps, step)

ir.Stages = append(ir.Stages, stage)

return nil
}
28 changes: 0 additions & 28 deletions pipeline/frontend/yaml/compiler/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,6 @@ func WithEnviron(env map[string]string) Option {
}
}

// WithCacher configures the compiler with default cache settings.
func WithCacher(cacher Cacher) Option {
return func(compiler *Compiler) {
compiler.cacher = cacher
}
}

// WithVolumeCacher configures the compiler with default local volume
// caching enabled.
func WithVolumeCacher(base string) Option {
return func(compiler *Compiler) {
compiler.cacher = &volumeCacher{base: base}
}
}

// WithS3Cacher configures the compiler with default amazon s3
// caching enabled.
func WithS3Cacher(access, secret, region, bucket string) Option {
return func(compiler *Compiler) {
compiler.cacher = &s3Cacher{
access: access,
secret: secret,
bucket: bucket,
region: region,
}
}
}

// WithNetworks configures the compiler with additional networks
// to be connected to pipeline containers
func WithNetworks(networks ...string) Option {
Expand Down
21 changes: 0 additions & 21 deletions pipeline/frontend/yaml/compiler/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,9 @@ func TestWithEnviron(t *testing.T) {
assert.Equal(t, "true", compiler.env["SHOW"])
}

func TestWithVolumeCacher(t *testing.T) {
compiler := New(
WithVolumeCacher("/cache"),
)
cacher, ok := compiler.cacher.(*volumeCacher)
assert.True(t, ok)
assert.Equal(t, "/cache", cacher.base)
}

func TestWithDefaultCloneImage(t *testing.T) {
compiler := New(
WithDefaultCloneImage("not-an-image"),
)
assert.Equal(t, "not-an-image", compiler.defaultCloneImage)
}

func TestWithS3Cacher(t *testing.T) {
compiler := New(
WithS3Cacher("some-access-key", "some-secret-key", "some-region", "some-bucket"),
)
cacher, ok := compiler.cacher.(*s3Cacher)
assert.True(t, ok)
assert.Equal(t, "some-bucket", cacher.bucket)
assert.Equal(t, "some-access-key", cacher.access)
assert.Equal(t, "some-region", cacher.region)
assert.Equal(t, "some-secret-key", cacher.secret)
}
6 changes: 2 additions & 4 deletions pipeline/frontend/yaml/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package types

import (
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/constraint"
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types/base"
)

type (
Expand All @@ -33,9 +32,8 @@ type (
SkipClone bool `yaml:"skip_clone"`

// Undocumented
Cache base.StringOrSlice `yaml:"cache,omitempty"`
Networks WorkflowNetworks `yaml:"networks,omitempty"`
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`
Networks WorkflowNetworks `yaml:"networks,omitempty"`
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`

// Deprecated
PlatformDoNotUseIt string `yaml:"platform,omitempty"` // TODO: remove in next major version
Expand Down