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:
Zav Shotan
2022-02-10 11:05:19 -05:00
committed by GitHub
parent 51904c9ee1
commit 905350fa15
8 changed files with 51 additions and 15 deletions

View File

@@ -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,
}

View File

@@ -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.

View File

@@ -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"),