mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-18 13:35:43 +00:00
Remove unused cache properties (#3567)
This commit is contained in:
parent
afd457a534
commit
2029813fc2
6 changed files with 9 additions and 230 deletions
|
@ -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) {
|
func podContainer(step *types.Step, podName, goos string, options BackendOptions) (v1.Container, error) {
|
||||||
var err error
|
var err error
|
||||||
container := v1.Container{
|
container := v1.Container{
|
||||||
Name: podName,
|
Name: podName,
|
||||||
Image: step.Image,
|
Image: step.Image,
|
||||||
WorkingDir: step.WorkingDir,
|
WorkingDir: step.WorkingDir,
|
||||||
|
Ports: containerPorts(step.Ports),
|
||||||
|
SecurityContext: containerSecurityContext(options.SecurityContext, step.Privileged),
|
||||||
}
|
}
|
||||||
|
|
||||||
if step.Pull {
|
if step.Pull {
|
||||||
|
@ -155,8 +157,6 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
container.Env = mapToEnvVars(step.Environment)
|
container.Env = mapToEnvVars(step.Environment)
|
||||||
container.Ports = containerPorts(step.Ports)
|
|
||||||
container.SecurityContext = containerSecurityContext(options.SecurityContext, step.Privileged)
|
|
||||||
|
|
||||||
container.Resources, err = resourceRequirements(options.Resources)
|
container.Resources, err = resourceRequirements(options.Resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,117 +0,0 @@
|
||||||
// Copyright 2023 Woodpecker Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package compiler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
yaml_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cacher defines a compiler transform that can be used
|
|
||||||
// to implement default caching for a repository.
|
|
||||||
type Cacher interface {
|
|
||||||
Restore(repo, branch string, mounts []string) *yaml_types.Container
|
|
||||||
Rebuild(repo, branch string, mounts []string) *yaml_types.Container
|
|
||||||
}
|
|
||||||
|
|
||||||
type volumeCacher struct {
|
|
||||||
base string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *volumeCacher) Restore(repo, branch string, mounts []string) *yaml_types.Container {
|
|
||||||
return &yaml_types.Container{
|
|
||||||
Name: "rebuild_cache",
|
|
||||||
Image: "plugins/volume-cache:1.0.0",
|
|
||||||
Settings: map[string]any{
|
|
||||||
"mount": mounts,
|
|
||||||
"path": "/cache",
|
|
||||||
"restore": true,
|
|
||||||
"file": strings.ReplaceAll(branch, "/", "_") + ".tar",
|
|
||||||
"fallback_to": "main.tar",
|
|
||||||
},
|
|
||||||
Volumes: yaml_types.Volumes{
|
|
||||||
Volumes: []*yaml_types.Volume{
|
|
||||||
{
|
|
||||||
Source: path.Join(c.base, repo),
|
|
||||||
Destination: "/cache",
|
|
||||||
// TODO add access mode
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *volumeCacher) Rebuild(repo, branch string, mounts []string) *yaml_types.Container {
|
|
||||||
return &yaml_types.Container{
|
|
||||||
Name: "rebuild_cache",
|
|
||||||
Image: "plugins/volume-cache:1.0.0",
|
|
||||||
Settings: map[string]any{
|
|
||||||
"mount": mounts,
|
|
||||||
"path": "/cache",
|
|
||||||
"rebuild": true,
|
|
||||||
"flush": true,
|
|
||||||
"file": strings.ReplaceAll(branch, "/", "_") + ".tar",
|
|
||||||
},
|
|
||||||
Volumes: yaml_types.Volumes{
|
|
||||||
Volumes: []*yaml_types.Volume{
|
|
||||||
{
|
|
||||||
Source: path.Join(c.base, repo),
|
|
||||||
Destination: "/cache",
|
|
||||||
// TODO add access mode
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type s3Cacher struct {
|
|
||||||
bucket string
|
|
||||||
access string
|
|
||||||
secret string
|
|
||||||
region string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *s3Cacher) Restore(_, _ string, mounts []string) *yaml_types.Container {
|
|
||||||
return &yaml_types.Container{
|
|
||||||
Name: "rebuild_cache",
|
|
||||||
Image: "plugins/s3-cache:latest",
|
|
||||||
Settings: map[string]any{
|
|
||||||
"mount": mounts,
|
|
||||||
"access_key": c.access,
|
|
||||||
"secret_key": c.secret,
|
|
||||||
"bucket": c.bucket,
|
|
||||||
"region": c.region,
|
|
||||||
"rebuild": true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *s3Cacher) Rebuild(_, _ string, mounts []string) *yaml_types.Container {
|
|
||||||
return &yaml_types.Container{
|
|
||||||
Name: "rebuild_cache",
|
|
||||||
Image: "plugins/s3-cache:latest",
|
|
||||||
Settings: map[string]any{
|
|
||||||
"mount": mounts,
|
|
||||||
"access_key": c.access,
|
|
||||||
"secret_key": c.secret,
|
|
||||||
"bucket": c.bucket,
|
|
||||||
"region": c.region,
|
|
||||||
"rebuild": true,
|
|
||||||
"flush": true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,7 +16,6 @@ package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
|
|
||||||
backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/metadata"
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/metadata"
|
||||||
|
@ -34,7 +33,6 @@ type Registry struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
Token string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Secret struct {
|
type Secret struct {
|
||||||
|
@ -68,7 +66,7 @@ func (s *Secret) Match(event string) bool {
|
||||||
if len(s.Events) == 0 {
|
if len(s.Events) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// tread all pull events the same way
|
// treat all pull events the same way
|
||||||
if event == "pull_request_closed" {
|
if event == "pull_request_closed" {
|
||||||
event = "pull_request"
|
event = "pull_request"
|
||||||
}
|
}
|
||||||
|
@ -82,8 +80,6 @@ func (s *Secret) Match(event string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type secretMap map[string]Secret
|
|
||||||
|
|
||||||
type ResourceLimit struct {
|
type ResourceLimit struct {
|
||||||
MemSwapLimit int64
|
MemSwapLimit int64
|
||||||
MemLimit int64
|
MemLimit int64
|
||||||
|
@ -106,8 +102,7 @@ type Compiler struct {
|
||||||
path string
|
path string
|
||||||
metadata metadata.Metadata
|
metadata metadata.Metadata
|
||||||
registries []Registry
|
registries []Registry
|
||||||
secrets secretMap
|
secrets map[string]Secret
|
||||||
cacher Cacher
|
|
||||||
reslimit ResourceLimit
|
reslimit ResourceLimit
|
||||||
defaultCloneImage string
|
defaultCloneImage string
|
||||||
trustedPipeline bool
|
trustedPipeline bool
|
||||||
|
@ -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
|
// add services steps
|
||||||
if len(conf.Services.ContainerList) != 0 {
|
if len(conf.Services.ContainerList) != 0 {
|
||||||
stage := new(backend_types.Stage)
|
stage := new(backend_types.Stage)
|
||||||
|
@ -297,48 +287,5 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
|
||||||
|
|
||||||
config.Stages = append(config.Stages, stepStages...)
|
config.Stages = append(config.Stages, stepStages...)
|
||||||
|
|
||||||
err = c.setupCacheRebuild(conf, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
// WithNetworks configures the compiler with additional networks
|
||||||
// to be connected to pipeline containers
|
// to be connected to pipeline containers
|
||||||
func WithNetworks(networks ...string) Option {
|
func WithNetworks(networks ...string) Option {
|
||||||
|
|
|
@ -166,30 +166,9 @@ func TestWithEnviron(t *testing.T) {
|
||||||
assert.Equal(t, "true", compiler.env["SHOW"])
|
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) {
|
func TestWithDefaultCloneImage(t *testing.T) {
|
||||||
compiler := New(
|
compiler := New(
|
||||||
WithDefaultCloneImage("not-an-image"),
|
WithDefaultCloneImage("not-an-image"),
|
||||||
)
|
)
|
||||||
assert.Equal(t, "not-an-image", compiler.defaultCloneImage)
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/constraint"
|
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/constraint"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/types/base"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -33,9 +32,8 @@ type (
|
||||||
SkipClone bool `yaml:"skip_clone"`
|
SkipClone bool `yaml:"skip_clone"`
|
||||||
|
|
||||||
// Undocumented
|
// Undocumented
|
||||||
Cache base.StringOrSlice `yaml:"cache,omitempty"`
|
Networks WorkflowNetworks `yaml:"networks,omitempty"`
|
||||||
Networks WorkflowNetworks `yaml:"networks,omitempty"`
|
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`
|
||||||
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`
|
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
PlatformDoNotUseIt string `yaml:"platform,omitempty"` // TODO: remove in next major version
|
PlatformDoNotUseIt string `yaml:"platform,omitempty"` // TODO: remove in next major version
|
||||||
|
|
Loading…
Reference in a new issue