Skip to content

Commit

Permalink
turbobob.json: add description, website, documentation and mo…
Browse files Browse the repository at this point in the history
…ve `project_emoji_icon`

these also get published as OCI-compliant metadata
  • Loading branch information
joonas-fi committed Aug 27, 2024
1 parent 34e6e23 commit 350f614
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
14 changes: 13 additions & 1 deletion cmd/bob/bobfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ type Bobfile struct {
FileDescriptionBoilerplate string `json:"for_description_of_this_file_see"`
VersionMajor int `json:"version_major"`
ProjectName string `json:"project_name"`
ProjectEmojiIcon string `json:"project_emoji_icon,omitempty"` // to quickly differentiate projects in e.g. workspace switcher
Meta ProjectMetadata `json:"meta,omitempty"`
Builders []BuilderSpec `json:"builders"`
DockerImages []DockerImageSpec `json:"docker_images,omitempty"`
Subrepos []SubrepoSpec `json:"subrepos,omitempty"`
OsArches *OsArchesSpec `json:"os_arches,omitempty"`
Experiments experiments `json:"experiments_i_consent_to_breakage,omitempty"`
Deprecated1 string `json:"project_emoji_icon,omitempty"` // moved to `ProjectMetadata`
}

func (b Bobfile) ProjectEmojiIcon() string {
return firstNonEmpty(b.Meta.ProjectEmojiIcon, b.Deprecated1)
}

type ProjectMetadata struct {
Description string `json:"description,omitempty"` // what this project is used for
Website string `json:"website,omitempty"` // URL of homepage or such
Documentation string `json:"documentation,omitempty"` // URL of documentation website
ProjectEmojiIcon string `json:"project_emoji_icon,omitempty"` // to quickly differentiate projects in e.g. workspace switcher
}

// when experiments are removed or graduated to production, they will be removed from here
Expand Down
30 changes: 20 additions & 10 deletions cmd/bob/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,29 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
// that non-default branch builds are dev/experimental builds.
shouldTagLatest := dockerImage.TagLatest && buildCtx.IsDefaultBranch

labelArgs := []string{
"--label=org.opencontainers.image.created=" + time.Now().UTC().Format(time.RFC3339),
"--label=org.opencontainers.image.revision=" + buildCtx.RevisionId.RevisionId,
"--label=org.opencontainers.image.version=" + buildCtx.RevisionId.FriendlyRevisionId,
}
labelArgs := []string{}

addLabel := func(key string, value string) {
if value == "" {
return
}

if buildCtx.RepositoryURL != "" {
// "URL to get source code for building the image"
labelArgs = append(labelArgs, "--label=org.opencontainers.image.source="+buildCtx.RepositoryURL)
// "URL to find more information on the image"
labelArgs = append(labelArgs, "--label=org.opencontainers.image.url="+buildCtx.RepositoryURL)
labelArgs = append(labelArgs, fmt.Sprintf("--label=%s=%s", key, value))
}

addLabel("org.opencontainers.image.title", buildCtx.Bobfile.ProjectName)
addLabel("org.opencontainers.image.created", time.Now().UTC().Format(time.RFC3339))
addLabel("org.opencontainers.image.revision", buildCtx.RevisionId.RevisionId)
addLabel("org.opencontainers.image.version", buildCtx.RevisionId.FriendlyRevisionId)
addLabel("org.opencontainers.image.description", buildCtx.Bobfile.Meta.Description)

// "URL to get source code for building the image"
addLabel("org.opencontainers.image.source", buildCtx.RepositoryURL)
// "URL to find more information on the image"
addLabel("org.opencontainers.image.url", firstNonEmpty(buildCtx.Bobfile.Meta.Website, buildCtx.RepositoryURL))
// "URL to get documentation on the image"
addLabel("org.opencontainers.image.documentation", firstNonEmpty(buildCtx.Bobfile.Meta.Documentation, buildCtx.RepositoryURL))

// "" => "."
// "Dockerfile" => "."
// "subdir/Dockerfile" => "subdir"
Expand Down
4 changes: 2 additions & 2 deletions cmd/bob/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func workspaceRenameToSelectedProject() error {
}

nameWithMaybeIcon := func() string {
if bobfile.ProjectEmojiIcon != "" && userConfig.WindowManagerShowProjectEmojiIcons {
return fmt.Sprintf("%s %s", bobfile.ProjectEmojiIcon, bobfile.ProjectName)
if projectEmojiIcon := bobfile.ProjectEmojiIcon(); projectEmojiIcon != "" && userConfig.WindowManagerShowProjectEmojiIcons {
return fmt.Sprintf("%s %s", projectEmojiIcon, bobfile.ProjectName)
} else {
return bobfile.ProjectName
}
Expand Down

0 comments on commit 350f614

Please sign in to comment.