From d735aea71b4ffa85d0b4a12157f9cff294c54e53 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Sat, 28 Jul 2018 16:23:08 -0700 Subject: [PATCH] Allow for overriding the docker image Signed-off-by: David Gageot --- examples/annotated-skaffold.yaml | 5 +++-- pkg/skaffold/build/gcb/cloud_build.go | 2 +- pkg/skaffold/config/config_test.go | 5 ++++- pkg/skaffold/config/profile_test.go | 4 +++- pkg/skaffold/constants/constants.go | 2 ++ pkg/skaffold/schema/v1alpha2/config.go | 1 + pkg/skaffold/schema/v1alpha2/defaults.go | 12 ++++++++++++ 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/annotated-skaffold.yaml b/examples/annotated-skaffold.yaml index 187c833b6f7..44cee4ddb9d 100644 --- a/examples/annotated-skaffold.yaml +++ b/examples/annotated-skaffold.yaml @@ -82,15 +82,16 @@ build: # Docker artifacts can be built on Google Cloud Build. The projectId then needs # to be provided and the currently logged user should be given permissions to trigger # new builds on Cloud Builder. - # If the projectId is not specified, Skaffold will try to guess it from the image names. + # If the projectId is not provided, Skaffold will try to guess it from the image name. # For eg. If the artifact image name is gcr.io/myproject/image, then Skaffold will use # the `myproject` GCP project. - # + # All the other parameters are also optional. The default values are listed here: # googleCloudBuild: # projectId: YOUR_PROJECT # diskSizeGb: 200 # machineType: "N1_HIGHCPU_8"|"N1_HIGHCPU_32" # timeout: 10000S + # dockerImage: gcr.io/cloud-builders/docker # Docker artifacts can be built on a Kubernetes cluster with Kaniko. # Sources will be sent to a GCS bucket whose name is provided. diff --git a/pkg/skaffold/build/gcb/cloud_build.go b/pkg/skaffold/build/gcb/cloud_build.go index 5209ebc2c8c..b732930521d 100644 --- a/pkg/skaffold/build/gcb/cloud_build.go +++ b/pkg/skaffold/build/gcb/cloud_build.go @@ -96,7 +96,7 @@ func (b *Builder) buildArtifact(ctx context.Context, out io.Writer, tagger tag.T }, }, Steps: []*cloudbuild.BuildStep{{ - Name: "gcr.io/cloud-builders/docker", + Name: b.DockerImage, Args: args, }}, Images: []string{artifact.ImageName}, diff --git a/pkg/skaffold/config/config_test.go b/pkg/skaffold/config/config_test.go index 1ee5d808616..97479fef951 100644 --- a/pkg/skaffold/config/config_test.go +++ b/pkg/skaffold/config/config_test.go @@ -181,7 +181,10 @@ func withLocalBuild(ops ...func(*v1alpha2.BuildConfig)) func(*SkaffoldConfig) { func withGoogleCloudBuild(id string, ops ...func(*v1alpha2.BuildConfig)) func(*SkaffoldConfig) { return func(cfg *SkaffoldConfig) { - b := v1alpha2.BuildConfig{BuildType: v1alpha2.BuildType{GoogleCloudBuild: &v1alpha2.GoogleCloudBuild{ProjectID: id}}} + b := v1alpha2.BuildConfig{BuildType: v1alpha2.BuildType{GoogleCloudBuild: &v1alpha2.GoogleCloudBuild{ + ProjectID: id, + DockerImage: "gcr.io/cloud-builders/docker", + }}} for _, op := range ops { op(&b) } diff --git a/pkg/skaffold/config/profile_test.go b/pkg/skaffold/config/profile_test.go index b125b692d84..512dad6fed6 100644 --- a/pkg/skaffold/config/profile_test.go +++ b/pkg/skaffold/config/profile_test.go @@ -75,7 +75,9 @@ func TestApplyProfiles(t *testing.T) { }, }, BuildType: v1alpha2.BuildType{ - GoogleCloudBuild: &v1alpha2.GoogleCloudBuild{}, + GoogleCloudBuild: &v1alpha2.GoogleCloudBuild{ + DockerImage: "gcr.io/cloud-builders/docker", + }, }, TagPolicy: v1alpha2.TagPolicy{ GitTagger: &v1alpha2.GitTagger{}, diff --git a/pkg/skaffold/constants/constants.go b/pkg/skaffold/constants/constants.go index 2a47f2f4198..30ad591c408 100644 --- a/pkg/skaffold/constants/constants.go +++ b/pkg/skaffold/constants/constants.go @@ -51,6 +51,8 @@ const ( DefaultKanikoTimeout = "20m" UpdateCheckEnvironmentVariable = "SKAFFOLD_UPDATE_CHECK" + + DefaultCloudBuildDockerImage = "gcr.io/cloud-builders/docker" ) var DefaultKubectlManifests = []string{"k8s/*.yaml"} diff --git a/pkg/skaffold/schema/v1alpha2/config.go b/pkg/skaffold/schema/v1alpha2/config.go index 010f18ce7e9..c2b2fea0b69 100644 --- a/pkg/skaffold/schema/v1alpha2/config.go +++ b/pkg/skaffold/schema/v1alpha2/config.go @@ -91,6 +91,7 @@ type GoogleCloudBuild struct { DiskSizeGb int64 `yaml:"diskSizeGb,omitempty"` MachineType string `yaml:"machineType,omitempty"` Timeout string `yaml:"timeout,omitempty"` + DockerImage string `yaml:"dockerImage,omitempty"` } // KanikoBuild contains the fields needed to do a on-cluster build using diff --git a/pkg/skaffold/schema/v1alpha2/defaults.go b/pkg/skaffold/schema/v1alpha2/defaults.go index e6dbdfb178a..5824b204249 100644 --- a/pkg/skaffold/schema/v1alpha2/defaults.go +++ b/pkg/skaffold/schema/v1alpha2/defaults.go @@ -28,6 +28,7 @@ import ( func (c *SkaffoldConfig) setDefaultValues() error { c.defaultToLocalBuild() + c.setDefaultCloudBuildDockerImage() c.setDefaultTagger() c.setDefaultKustomizePath() c.setDefaultKubectlManifests() @@ -57,6 +58,17 @@ func (c *SkaffoldConfig) defaultToLocalBuild() { c.Build.BuildType.LocalBuild = &LocalBuild{} } +func (c *SkaffoldConfig) setDefaultCloudBuildDockerImage() { + cloudBuild := c.Build.BuildType.GoogleCloudBuild + if cloudBuild == nil { + return + } + + if cloudBuild.DockerImage == "" { + cloudBuild.DockerImage = constants.DefaultCloudBuildDockerImage + } +} + func (c *SkaffoldConfig) setDefaultTagger() { if c.Build.TagPolicy != (TagPolicy{}) { return