From a9662be9bc040b0e8054f3214b13923bc4d2e87e Mon Sep 17 00:00:00 2001 From: Joonas Loppi Date: Sat, 20 May 2023 13:53:24 +0300 Subject: [PATCH] `turbobob.json`: add `description`, `website`, `documentation` and move `project_emoji_icon` these also get published as OCI-compliant metadata --- cmd/bob/bobfile.go | 14 +++++++++++++- cmd/bob/build.go | 30 ++++++++++++++++++++---------- cmd/bob/workspace.go | 4 ++-- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cmd/bob/bobfile.go b/cmd/bob/bobfile.go index 1bc005b..5f0f25b 100644 --- a/cmd/bob/bobfile.go +++ b/cmd/bob/bobfile.go @@ -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 diff --git a/cmd/bob/build.go b/cmd/bob/build.go index 71a6e5e..da1b239 100644 --- a/cmd/bob/build.go +++ b/cmd/bob/build.go @@ -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" diff --git a/cmd/bob/workspace.go b/cmd/bob/workspace.go index 813ea9c..8f489f1 100755 --- a/cmd/bob/workspace.go +++ b/cmd/bob/workspace.go @@ -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 }