Skip to content

Commit

Permalink
Allow for overriding the docker image
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Aug 6, 2018
1 parent 9aa6711 commit d735aea
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/gcb/cloud_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/config/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
DefaultKanikoTimeout = "20m"

UpdateCheckEnvironmentVariable = "SKAFFOLD_UPDATE_CHECK"

DefaultCloudBuildDockerImage = "gcr.io/cloud-builders/docker"
)

var DefaultKubectlManifests = []string{"k8s/*.yaml"}
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/schema/v1alpha2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions pkg/skaffold/schema/v1alpha2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

func (c *SkaffoldConfig) setDefaultValues() error {
c.defaultToLocalBuild()
c.setDefaultCloudBuildDockerImage()
c.setDefaultTagger()
c.setDefaultKustomizePath()
c.setDefaultKubectlManifests()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d735aea

Please sign in to comment.