Skip to content

Commit

Permalink
Add flag to skaffold.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Apr 27, 2020
1 parent 217056f commit 77bf521
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions docs/content/en/schemas/v2beta3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,12 @@
"description": "should images be pushed to a registry. If not specified, images are pushed only if the current Kubernetes context connects to a remote cluster.",
"x-intellij-html-description": "should images be pushed to a registry. If not specified, images are pushed only if the current Kubernetes context connects to a remote cluster."
},
"tryImportMissing": {
"type": "boolean",
"description": "should attempt to import this artifact from Docker (either locally or a remote registry) if not in cache.",
"x-intellij-html-description": "should attempt to import this artifact from Docker (either locally or a remote registry) if not in cache.",
"default": "false"
},
"useBuildkit": {
"type": "boolean",
"description": "use BuildKit to build Docker images.",
Expand All @@ -1649,6 +1655,7 @@
},
"preferredOrder": [
"push",
"tryImportMissing",
"useDockerCLI",
"useBuildkit",
"concurrency"
Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/build/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ type cache struct {
insecureRegistries map[string]bool
cacheFile string
imagesAreLocal bool
tryImportMissing bool
hashForArtifact func(ctx context.Context, a *latest.Artifact) (string, error)
}

// DependencyLister fetches a list of dependencies for an artifact
type DependencyLister func(ctx context.Context, artifact *latest.Artifact) ([]string, error)

// NewCache returns the current state of the cache
func NewCache(runCtx *runcontext.RunContext, imagesAreLocal bool, dependencies DependencyLister) (Cache, error) {
func NewCache(runCtx *runcontext.RunContext, imagesAreLocal bool, tryImportMissing bool, dependencies DependencyLister) (Cache, error) {
if !runCtx.Opts.CacheArtifacts {
return &noCache{}, nil
}
Expand Down Expand Up @@ -84,6 +85,7 @@ func NewCache(runCtx *runcontext.RunContext, imagesAreLocal bool, dependencies D
insecureRegistries: runCtx.InsecureRegistries,
cacheFile: cacheFile,
imagesAreLocal: imagesAreLocal,
tryImportMissing: tryImportMissing,
hashForArtifact: func(ctx context.Context, a *latest.Artifact) (string, error) {
return getHashForArtifact(ctx, dependencies, a, runCtx.IsDevMode())
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/build/cache/retrieve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestCacheBuildLocal(t *testing.T) {
})

// Create cache
artifactCache, err := NewCache(runCtx, true, deps)
artifactCache, err := NewCache(runCtx, true, false, deps)
t.CheckNoError(err)

// First build: Need to build both artifacts
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestCacheBuildRemote(t *testing.T) {
})

// Create cache
artifactCache, err := NewCache(runCtx, false, deps)
artifactCache, err := NewCache(runCtx, false, false, deps)
t.CheckNoError(err)

// First build: Need to build both artifacts
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/build/local/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Builder struct {
localDocker docker.LocalDaemon
localCluster bool
pushImages bool
tryImportMissing bool
prune bool
pruneChildren bool
skipTests bool
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewBuilder(runCtx *runcontext.RunContext) (*Builder, error) {
localDocker: localDocker,
localCluster: localCluster,
pushImages: pushImages,
tryImportMissing: runCtx.Cfg.Build.LocalBuild.TryImportMissing,
skipTests: runCtx.Opts.SkipTests,
devMode: runCtx.IsDevMode(),
prune: runCtx.Opts.Prune(),
Expand All @@ -93,6 +95,10 @@ func (b *Builder) PushImages() bool {
return b.pushImages
}

func (b *Builder) TryImportMissing() bool {
return b.tryImportMissing
}

// Labels are labels specific to local builder.
func (b *Builder) Labels() map[string]string {
labels := map[string]string{
Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/runner/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ func NewForConfig(runCtx *runcontext.RunContext) (*SkaffoldRunner, error) {
return nil, fmt.Errorf("parsing build config: %w", err)
}

tryImportMissing := false
imagesAreLocal := false
if localBuilder, ok := builder.(*local.Builder); ok {
imagesAreLocal = !localBuilder.PushImages()
tryImportMissing = localBuilder.TryImportMissing()
}

tester := getTester(runCtx, imagesAreLocal)
Expand All @@ -74,7 +76,7 @@ func NewForConfig(runCtx *runcontext.RunContext) (*SkaffoldRunner, error) {
return append(buildDependencies, testDependencies...), nil
}

artifactCache, err := cache.NewCache(runCtx, imagesAreLocal, depLister)
artifactCache, err := cache.NewCache(runCtx, imagesAreLocal, tryImportMissing, depLister)
if err != nil {
return nil, fmt.Errorf("initializing cache: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ type LocalBuild struct {
// connects to a remote cluster.
Push *bool `yaml:"push,omitempty"`

// TryImportMissing should attempt to import this artifact from
// Docker (either locally or a remote registry) if not in cache.
TryImportMissing bool `yaml:"tryImportMissing,omitempty"`

// UseDockerCLI use `docker` command-line interface instead of Docker Engine APIs.
UseDockerCLI bool `yaml:"useDockerCLI,omitempty"`

Expand Down

0 comments on commit 77bf521

Please sign in to comment.