@@ -135,19 +135,39 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
135
135
// that non-default branch builds are dev/experimental builds.
136
136
shouldTagLatest := dockerImage .TagLatest && buildCtx .IsDefaultBranch
137
137
138
- labelArgs := []string {
139
- "--label=org.opencontainers.image.created=" + time .Now ().UTC ().Format (time .RFC3339 ),
140
- "--label=org.opencontainers.image.revision=" + buildCtx .RevisionId .RevisionId ,
141
- "--label=org.opencontainers.image.version=" + buildCtx .RevisionId .FriendlyRevisionId ,
138
+ annotationsKeyValues := []string {} // items look like "title=foobar"
139
+
140
+ // annotationsAs("--annotation=") => ["--annotation=title=foobar"]
141
+ annotationsAs := func (argPrefix string ) []string {
142
+ argified := []string {}
143
+ for _ , annotation := range annotationsKeyValues {
144
+ // "title=foobar" => "--annotation=title=foobar"
145
+ argified = append (argified , argPrefix + annotation )
146
+ }
147
+ return argified
142
148
}
143
149
144
- if buildCtx .RepositoryURL != "" {
145
- // "URL to get source code for building the image"
146
- labelArgs = append (labelArgs , "--label=org.opencontainers.image.source=" + buildCtx .RepositoryURL )
147
- // "URL to find more information on the image"
148
- labelArgs = append (labelArgs , "--label=org.opencontainers.image.url=" + buildCtx .RepositoryURL )
150
+ annotate := func (key string , value string ) {
151
+ if value == "" {
152
+ return
153
+ }
154
+
155
+ annotationsKeyValues = append (annotationsKeyValues , fmt .Sprintf ("%s=%s" , key , value ))
149
156
}
150
157
158
+ annotate ("org.opencontainers.image.title" , buildCtx .Bobfile .ProjectName )
159
+ annotate ("org.opencontainers.image.created" , time .Now ().UTC ().Format (time .RFC3339 ))
160
+ annotate ("org.opencontainers.image.revision" , buildCtx .RevisionId .RevisionId )
161
+ annotate ("org.opencontainers.image.version" , buildCtx .RevisionId .FriendlyRevisionId )
162
+ annotate ("org.opencontainers.image.description" , buildCtx .Bobfile .Meta .Description )
163
+
164
+ // "URL to get source code for building the image"
165
+ annotate ("org.opencontainers.image.source" , buildCtx .RepositoryURL )
166
+ // "URL to find more information on the image"
167
+ annotate ("org.opencontainers.image.url" , firstNonEmpty (buildCtx .Bobfile .Meta .Website , buildCtx .RepositoryURL ))
168
+ // "URL to get documentation on the image"
169
+ annotate ("org.opencontainers.image.documentation" , firstNonEmpty (buildCtx .Bobfile .Meta .Documentation , buildCtx .RepositoryURL ))
170
+
151
171
// "" => "."
152
172
// "Dockerfile" => "."
153
173
// "subdir/Dockerfile" => "subdir"
@@ -170,7 +190,7 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
170
190
"--tag=" + tag ,
171
191
}
172
192
173
- args = append (args , labelArgs ... )
193
+ args = append (args , annotationsAs ( "--annotation=" ) ... )
174
194
175
195
if shouldTagLatest {
176
196
args = append (args , "--tag=" + tagLatest )
@@ -192,7 +212,8 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
192
212
"build" ,
193
213
"--file" , dockerfilePath ,
194
214
"--tag" , tag }
195
- dockerBuildArgs = append (dockerBuildArgs , labelArgs ... )
215
+ // `$ docker build ...` doesn't have annotation support
216
+ dockerBuildArgs = append (dockerBuildArgs , annotationsAs ("--label=" )... )
196
217
dockerBuildArgs = append (dockerBuildArgs , buildContextDir )
197
218
198
219
//nolint:gosec // ok
0 commit comments