@@ -130,19 +130,29 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
130130 tagLatest := tagWithoutVersion + ":latest"
131131 dockerfilePath := dockerImage .DockerfilePath
132132
133- labelArgs := []string {
134- "--label=org.opencontainers.image.created=" + time .Now ().UTC ().Format (time .RFC3339 ),
135- "--label=org.opencontainers.image.revision=" + buildCtx .RevisionId .RevisionId ,
136- "--label=org.opencontainers.image.version=" + buildCtx .RevisionId .FriendlyRevisionId ,
137- }
133+ labelArgs := []string {}
134+
135+ addLabel := func (key string , value string ) {
136+ if value == "" {
137+ return
138+ }
138139
139- if buildCtx .RepositoryURL != "" {
140- // "URL to get source code for building the image"
141- labelArgs = append (labelArgs , "--label=org.opencontainers.image.source=" + buildCtx .RepositoryURL )
142- // "URL to find more information on the image"
143- labelArgs = append (labelArgs , "--label=org.opencontainers.image.url=" + buildCtx .RepositoryURL )
140+ labelArgs = append (labelArgs , fmt .Sprintf ("--label=%s=%s" , key , value ))
144141 }
145142
143+ addLabel ("org.opencontainers.image.title" , buildCtx .Bobfile .ProjectName )
144+ addLabel ("org.opencontainers.image.created" , time .Now ().UTC ().Format (time .RFC3339 ))
145+ addLabel ("org.opencontainers.image.revision" , buildCtx .RevisionId .RevisionId )
146+ addLabel ("org.opencontainers.image.version" , buildCtx .RevisionId .FriendlyRevisionId )
147+ addLabel ("org.opencontainers.image.description" , buildCtx .Bobfile .Meta .Description )
148+
149+ // "URL to get source code for building the image"
150+ addLabel ("org.opencontainers.image.source" , buildCtx .RepositoryURL )
151+ // "URL to find more information on the image"
152+ addLabel ("org.opencontainers.image.url" , firstNonEmpty (buildCtx .Bobfile .Meta .Website , buildCtx .RepositoryURL ))
153+ // "URL to get documentation on the image"
154+ addLabel ("org.opencontainers.image.documentation" , firstNonEmpty (buildCtx .Bobfile .Meta .Documentation , buildCtx .RepositoryURL ))
155+
146156 // "" => "."
147157 // "Dockerfile" => "."
148158 // "subdir/Dockerfile" => "subdir"
@@ -575,3 +585,12 @@ func buildInside(fastBuild bool) error {
575585
576586 return buildCmd .Run ()
577587}
588+
589+ // FIXME: when get to use generics, use `gokit`
590+ func firstNonEmpty (a string , b string ) string {
591+ if a != "" {
592+ return a
593+ } else {
594+ return b
595+ }
596+ }
0 commit comments