Skip to content

Commit 486ec17

Browse files
committed
turbobob.json: add description, website, documentation and move project_emoji_icon
these also get published as OCI-compliant metadata
1 parent fc93cf3 commit 486ec17

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

cmd/bob/bobfile.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,27 @@ 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+
if b.Meta.ProjectEmojiIcon != "" {
39+
return b.Meta.ProjectEmojiIcon
40+
}
41+
return b.Deprecated1
42+
}
43+
44+
type ProjectMetadata struct {
45+
Description string `json:"description,omitempty"` // what this project is used for
46+
Website string `json:"website,omitempty"` // URL of homepage or such
47+
Documentation string `json:"documentation,omitempty"` // URL of documentation website
48+
ProjectEmojiIcon string `json:"project_emoji_icon,omitempty"` // to quickly differentiate projects in e.g. workspace switcher
3449
}
3550

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

cmd/bob/build.go

+29-10
Original file line numberDiff line numberDiff line change
@@ -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+
}

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)