@@ -19,6 +19,7 @@ package gcb
19
19
import (
20
20
"fmt"
21
21
22
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
22
23
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
23
24
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults"
24
25
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -28,7 +29,12 @@ import (
28
29
)
29
30
30
31
func (b * Builder ) buildDescription (artifact * latest.Artifact , tag , bucket , object string ) (* cloudbuild.Build , error ) {
31
- steps , err := b .buildSteps (artifact , tag )
32
+ tags := []string {tag }
33
+ if artifact .WorkspaceHash != "" {
34
+ tags = append (tags , build .HashTag (artifact ))
35
+ }
36
+
37
+ steps , err := b .buildSteps (artifact , tags )
32
38
if err != nil {
33
39
return nil , err
34
40
}
@@ -42,7 +48,7 @@ func (b *Builder) buildDescription(artifact *latest.Artifact, tag, bucket, objec
42
48
},
43
49
},
44
50
Steps : steps ,
45
- Images : [] string { tag } ,
51
+ Images : tags ,
46
52
Options : & cloudbuild.BuildOptions {
47
53
DiskSizeGb : b .DiskSizeGb ,
48
54
MachineType : b .MachineType ,
@@ -51,28 +57,29 @@ func (b *Builder) buildDescription(artifact *latest.Artifact, tag, bucket, objec
51
57
}, nil
52
58
}
53
59
54
- func (b * Builder ) buildSteps (artifact * latest.Artifact , tag string ) ([]* cloudbuild.BuildStep , error ) {
60
+ func (b * Builder ) buildSteps (artifact * latest.Artifact , tags [] string ) ([]* cloudbuild.BuildStep , error ) {
55
61
switch {
56
62
case artifact .BuilderPlugin != nil :
57
- return b .pluginBuildSteps (artifact , tag )
63
+ return b .pluginBuildSteps (artifact , tags )
58
64
case artifact .DockerArtifact != nil :
59
- return b .dockerBuildSteps (artifact .DockerArtifact , tag ), nil
65
+ return b .dockerBuildSteps (artifact .DockerArtifact , tags ), nil
60
66
61
67
case artifact .BazelArtifact != nil :
62
68
return nil , errors .New ("skaffold can't build a bazel artifact with Google Cloud Build" )
63
69
70
+ // TODO: build multiple tagged images with jib in GCB (priyawadhwa@)
64
71
case artifact .JibMavenArtifact != nil :
65
- return b .jibMavenBuildSteps (artifact .JibMavenArtifact , tag ), nil
72
+ return b .jibMavenBuildSteps (artifact .JibMavenArtifact , tags [ 0 ] ), nil
66
73
67
74
case artifact .JibGradleArtifact != nil :
68
- return b .jibGradleBuildSteps (artifact .JibGradleArtifact , tag ), nil
75
+ return b .jibGradleBuildSteps (artifact .JibGradleArtifact , tags [ 0 ] ), nil
69
76
70
77
default :
71
78
return nil , fmt .Errorf ("undefined artifact type: %+v" , artifact .ArtifactType )
72
79
}
73
80
}
74
81
75
- func (b * Builder ) pluginBuildSteps (artifact * latest.Artifact , tag string ) ([]* cloudbuild.BuildStep , error ) {
82
+ func (b * Builder ) pluginBuildSteps (artifact * latest.Artifact , tags [] string ) ([]* cloudbuild.BuildStep , error ) {
76
83
switch artifact .BuilderPlugin .Name {
77
84
case constants .DockerBuilderPluginName :
78
85
var da * latest.DockerArtifact
@@ -83,7 +90,7 @@ func (b *Builder) pluginBuildSteps(artifact *latest.Artifact, tag string) ([]*cl
83
90
da = & latest.DockerArtifact {}
84
91
}
85
92
defaults .SetDefaultDockerArtifact (da )
86
- return b .dockerBuildSteps (da , tag ), nil
93
+ return b .dockerBuildSteps (da , tags ), nil
87
94
default :
88
95
return nil , errors .Errorf ("the '%s' builder is not supported" , artifact .BuilderPlugin .Name )
89
96
}
0 commit comments