Skip to content

Commit 90fdea1

Browse files
committed
turbobob.json: add description, website, documentation and move project_emoji_icon
these also get published as OCI-compliant metadata fix annotations for buildx
1 parent dd2ca4e commit 90fdea1

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

cmd/bob/bobfile.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ type Bobfile struct {
2525
FileDescriptionBoilerplate string `json:"for_description_of_this_file_see"`
2626
VersionMajor int `json:"version_major"`
2727
ProjectName string `json:"project_name"`
28-
ProjectEmojiIcon string `json:"project_emoji_icon,omitempty"` // to quickly differentiate projects in e.g. workspace switcher
28+
Meta ProjectMetadata `json:"meta,omitempty"`
2929
Builders []BuilderSpec `json:"builders"`
3030
DockerImages []DockerImageSpec `json:"docker_images,omitempty"`
3131
Subrepos []SubrepoSpec `json:"subrepos,omitempty"`
3232
OsArches *OsArchesSpec `json:"os_arches,omitempty"`
3333
Experiments experiments `json:"experiments_i_consent_to_breakage,omitempty"`
34+
Deprecated1 string `json:"project_emoji_icon,omitempty"` // moved to `ProjectMetadata`
35+
}
36+
37+
func (b Bobfile) ProjectEmojiIcon() string {
38+
return firstNonEmpty(b.Meta.ProjectEmojiIcon, b.Deprecated1)
39+
}
40+
41+
type ProjectMetadata struct {
42+
Description string `json:"description,omitempty"` // what this project is used for
43+
Website string `json:"website,omitempty"` // URL of homepage or such
44+
Documentation string `json:"documentation,omitempty"` // URL of documentation website
45+
ProjectEmojiIcon string `json:"project_emoji_icon,omitempty"` // to quickly differentiate projects in e.g. workspace switcher
3446
}
3547

3648
// when experiments are removed or graduated to production, they will be removed from here

cmd/bob/build.go

+32-11
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,39 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
135135
// that non-default branch builds are dev/experimental builds.
136136
shouldTagLatest := dockerImage.TagLatest && buildCtx.IsDefaultBranch
137137

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
142148
}
143149

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))
149156
}
150157

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+
151171
// "" => "."
152172
// "Dockerfile" => "."
153173
// "subdir/Dockerfile" => "subdir"
@@ -170,7 +190,7 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
170190
"--tag=" + tag,
171191
}
172192

173-
args = append(args, labelArgs...)
193+
args = append(args, annotationsAs("--annotation=")...)
174194

175195
if shouldTagLatest {
176196
args = append(args, "--tag="+tagLatest)
@@ -192,7 +212,8 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
192212
"build",
193213
"--file", dockerfilePath,
194214
"--tag", tag}
195-
dockerBuildArgs = append(dockerBuildArgs, labelArgs...)
215+
// `$ docker build ...` doesn't have annotation support
216+
dockerBuildArgs = append(dockerBuildArgs, annotationsAs("--label=")...)
196217
dockerBuildArgs = append(dockerBuildArgs, buildContextDir)
197218

198219
//nolint:gosec // ok

cmd/bob/workspace.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func workspaceRenameToSelectedProject() error {
108108
}
109109

110110
nameWithMaybeIcon := func() string {
111-
if bobfile.ProjectEmojiIcon != "" && userConfig.WindowManagerShowProjectEmojiIcons {
112-
return fmt.Sprintf("%s %s", bobfile.ProjectEmojiIcon, bobfile.ProjectName)
111+
if projectEmojiIcon := bobfile.ProjectEmojiIcon(); projectEmojiIcon != "" && userConfig.WindowManagerShowProjectEmojiIcons {
112+
return fmt.Sprintf("%s %s", projectEmojiIcon, bobfile.ProjectName)
113113
} else {
114114
return bobfile.ProjectName
115115
}

0 commit comments

Comments
 (0)