Skip to content

Commit

Permalink
Remove unused cache properties (#3567)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 authored Mar 29, 2024
1 parent afd457a commit 2029813
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 230 deletions.
10 changes: 5 additions & 5 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ 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,
Ports: containerPorts(step.Ports),
SecurityContext: containerSecurityContext(options.SecurityContext, step.Privileged),
}

if step.Pull {
Expand All @@ -155,8 +157,6 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
}

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 {
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

0 comments on commit 2029813

Please sign in to comment.