mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-12 14:20:54 +00:00
Add support for default clone image environment variable (#769)
This allows for custom clone images for deployment in air-gap systems. Co-authored-by: Zav Shotan <zshotan@bloomberg.net>
This commit is contained in:
@@ -47,20 +47,21 @@ type ResourceLimit struct {
|
||||
|
||||
// Compiler compiles the yaml
|
||||
type Compiler struct {
|
||||
local bool
|
||||
escalated []string
|
||||
prefix string
|
||||
volumes []string
|
||||
networks []string
|
||||
env map[string]string
|
||||
cloneEnv map[string]string
|
||||
base string
|
||||
path string
|
||||
metadata frontend.Metadata
|
||||
registries []Registry
|
||||
secrets map[string]Secret
|
||||
cacher Cacher
|
||||
reslimit ResourceLimit
|
||||
local bool
|
||||
escalated []string
|
||||
prefix string
|
||||
volumes []string
|
||||
networks []string
|
||||
env map[string]string
|
||||
cloneEnv map[string]string
|
||||
base string
|
||||
path string
|
||||
metadata frontend.Metadata
|
||||
registries []Registry
|
||||
secrets map[string]Secret
|
||||
cacher Cacher
|
||||
reslimit ResourceLimit
|
||||
defaultCloneImage string
|
||||
}
|
||||
|
||||
// New creates a new Compiler with options.
|
||||
@@ -120,9 +121,13 @@ func (c *Compiler) Compile(conf *yaml.Config) *backend.Config {
|
||||
|
||||
// add default clone step
|
||||
if !c.local && len(conf.Clone.Containers) == 0 && !conf.SkipClone {
|
||||
cloneImage := defaultCloneImage
|
||||
if len(c.defaultCloneImage) > 0 {
|
||||
cloneImage = c.defaultCloneImage
|
||||
}
|
||||
container := &yaml.Container{
|
||||
Name: defaultCloneName,
|
||||
Image: defaultCloneImage,
|
||||
Image: cloneImage,
|
||||
Settings: map[string]interface{}{"depth": "0"},
|
||||
Environment: c.cloneEnv,
|
||||
}
|
||||
|
@@ -199,6 +199,12 @@ func WithResourceLimit(swap, mem, shmsize, cpuQuota, cpuShares int64, cpuSet str
|
||||
}
|
||||
}
|
||||
|
||||
func WithDefaultCloneImage(cloneImage string) Option {
|
||||
return func(compiler *Compiler) {
|
||||
compiler.defaultCloneImage = cloneImage
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(bradrydzewski) consider an alternate approach to
|
||||
// WithProxy where the proxy strings are passed directly
|
||||
// to the function as named parameters.
|
||||
|
@@ -240,6 +240,15 @@ func TestWithVolumeCacher(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithDefaultCloneImage(t *testing.T) {
|
||||
compiler := New(
|
||||
WithDefaultCloneImage("not-an-image"),
|
||||
)
|
||||
if compiler.defaultCloneImage != "not-an-image" {
|
||||
t.Errorf("Expected default clone image 'not-an-image' not found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithS3Cacher(t *testing.T) {
|
||||
compiler := New(
|
||||
WithS3Cacher("some-access-key", "some-secret-key", "some-region", "some-bucket"),
|
||||
|
Reference in New Issue
Block a user