Skip to content

Commit

Permalink
use "annotation" instead of "label"
Browse files Browse the repository at this point in the history
  • Loading branch information
dskiff committed Apr 27, 2024
1 parent 35d8238 commit f470246
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
- name: Publish (latest)
run: |
tko build \
-l "org.opencontainers.image.revision=${{ github.sha }}" \
-l "org.opencontainers.image.version=dev-${{ github.sha }}" \
-t "ghcr.io/dskiff/tko:latest" \
-e "/bin/bash" \
--annotation "org.opencontainers.image.revision=${{ github.sha }}" \
--annotation "org.opencontainers.image.version=dev-${{ github.sha }}" \
--target-repo "ghcr.io/dskiff/tko:latest" \
--entrypoint "/bin/bash" \
"./dist/tko_linux_amd64_v1"
env:
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
TKO_BASE_REF: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
GITHUB_TOKEN: ${{ github.token }}
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ jobs:
- name: Publish (bin)
run: |
tko build \
-b "scratch" \
-t "ghcr.io/dskiff/tko:bin" \
-l "org.opencontainers.image.revision=${{ github.sha }}" \
-l "org.opencontainers.image.version=${{ github.ref_name }}" \
--annotation "org.opencontainers.image.revision=${{ github.sha }}" \
--annotation "org.opencontainers.image.version=${{ github.ref_name }}" \
--base-ref "scratch" \
--target-repo "ghcr.io/dskiff/tko:bin" \
"./dist/tko_linux_amd64_v1"
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Publish (version)
run: |
tko build \
-l "org.opencontainers.image.revision=${{ github.sha }}" \
-l "org.opencontainers.image.version=${{ github.ref_name }}" \
-t "ghcr.io/dskiff/tko:${{ github.ref_name }}" \
-e "/bin/bash" \
--annotation "org.opencontainers.image.revision=${{ github.sha }}" \
--annotation "org.opencontainers.image.version=${{ github.ref_name }}" \
--target-repo "ghcr.io/dskiff/tko:${{ github.ref_name }}" \
--entrypoint "/bin/bash" \
"./dist/tko_linux_amd64_v1"
env:
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
TKO_BASE_REF: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
GITHUB_TOKEN: ${{ github.token }}
2 changes: 1 addition & 1 deletion .tko.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
destination-path: /usr/local/bin
entrypoint: /usr/local/bin/tko
default-labels:
default-annotations:
org.opencontainers.image.title: tko
org.opencontainers.image.url: github.com/dskiff/tko
org.opencontainers.image.source: github.com/dskiff/tko
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ You can also provide any of the supported parameters using a `.tko.yml` (or `.tk
build:
base-ref: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
author: my name
labels:
default-annotations:
org.opencontainers.image.source: github.com/my-org/my-project
```

Expand All @@ -70,7 +70,7 @@ build:
- run: tko build "./out"
env:
TKO_BASE_IMAGE: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
TKO_BASE_REF: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
GITHUB_TOKEN: ${{ github.token }}
```

Expand All @@ -87,7 +87,7 @@ build:
- run: tko build "./dist"
env:
TKO_BASE_IMAGE: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
TKO_BASE_REF: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
GITHUB_TOKEN: ${{ github.token }}
```

Expand Down
30 changes: 15 additions & 15 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ build:
target-repo: repo/target
author: me
default-labels:
default-annotations:
label1: value1
label2: value2
labels:
annotations:
label3: value3
label4: value4
Expand All @@ -50,10 +50,10 @@ build:
assert.Equal(t, "repo/target", cli.Build.TargetRepo)

assert.Equal(t, "me", cli.Build.Author)
assert.Equal(t, "value1", cli.Build.DefaultLabels["label1"])
assert.Equal(t, "value2", cli.Build.DefaultLabels["label2"])
assert.Equal(t, "value3", cli.Build.Labels["label3"])
assert.Equal(t, "value4", cli.Build.Labels["label4"])
assert.Equal(t, "value1", cli.Build.DefaultAnnotations["label1"])
assert.Equal(t, "value2", cli.Build.DefaultAnnotations["label2"])
assert.Equal(t, "value3", cli.Build.Annotations["label3"])
assert.Equal(t, "value4", cli.Build.Annotations["label4"])

assert.Equal(t, "/tmp-dir", cli.Build.Tmp)
assert.Equal(t, true, cli.Build.Verbose)
Expand All @@ -77,11 +77,11 @@ func TestBuildArgs(t *testing.T) {
"-e", "/entrypoint",
"-d", "/destination",
"-t", "repo/target",
"-a", "me",
"-L", "label1=value1",
"-L", "label2=value2",
"-l", "label3=value3",
"-l", "label4=value4",
"--author", "me",
"-A", "label1=value1",
"-A", "label2=value2",
"-a", "label3=value3",
"-a", "label4=value4",
"-T", "REMOTE",
"-v",
"--tmp", "/tmp-dir",
Expand All @@ -97,10 +97,10 @@ func TestBuildArgs(t *testing.T) {
assert.Equal(t, "repo/target", cli.Build.TargetRepo)

assert.Equal(t, "me", cli.Build.Author)
assert.Equal(t, "value1", cli.Build.DefaultLabels["label1"])
assert.Equal(t, "value2", cli.Build.DefaultLabels["label2"])
assert.Equal(t, "value3", cli.Build.Labels["label3"])
assert.Equal(t, "value4", cli.Build.Labels["label4"])
assert.Equal(t, "value1", cli.Build.DefaultAnnotations["label1"])
assert.Equal(t, "value2", cli.Build.DefaultAnnotations["label2"])
assert.Equal(t, "value3", cli.Build.Annotations["label3"])
assert.Equal(t, "value4", cli.Build.Annotations["label4"])

assert.Equal(t, "/tmp-dir", cli.Build.Tmp)
assert.Equal(t, true, cli.Build.Verbose)
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type BuildSpec struct {
InjectLayer BuildSpecInjectLayer
Target BuildSpecTarget

Author string
Labels map[string]string
Author string
Annotations map[string]string
}

type BuildContext struct {
Expand Down Expand Up @@ -118,7 +118,7 @@ func mutateConfig(img v1.Image, spec BuildSpec, metadata BaseImageMetadata) (v1.
imgCfg.Config.Labels["org.opencontainers.image.base.digest"] = metadata.imageDigest
}

for k, v := range spec.Labels {
for k, v := range spec.Annotations {
imgCfg.Config.Labels[k] = v
}

Expand Down
24 changes: 12 additions & 12 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type BuildCmd struct {
BaseRef string `short:"b" help:"Base image reference" env:"TKO_BASE_IMAGE" default:"ubuntu:jammy"`
BaseRef string `short:"b" help:"Base image reference" env:"TKO_BASE_REF" default:"ubuntu:jammy"`

Platform string `short:"p" help:"Platform to build for" env:"TKO_PLATFORM" default:"linux/amd64"`

Expand All @@ -25,9 +25,9 @@ type BuildCmd struct {
TargetRepo string `short:"t" help:"Target repository" env:"TKO_TARGET_REPO" required:"true"`
TargetType string `short:"T" help:"Target type" env:"TKO_TARGET_TYPE" default:"REMOTE" enum:"REMOTE,LOCAL_DAEMON,LOCAL_FILE"`

Author string `short:"a" help:"Author of the build" env:"TKO_AUTHOR" default:"github.com/dskiff/tko"`
DefaultLabels map[string]string `short:"L" help:"Default labels to apply to the image" env:"TKO_DEFAULT_LABELS" default:"" mapsep:"," sep:"="`
Labels map[string]string `short:"l" help:"Additional labels to apply to the image. Can override default-labels." env:"LABELS" default:"" mapsep:"," sep:"="`
Author string `help:"Author of the build" env:"TKO_AUTHOR" default:"github.com/dskiff/tko"`
DefaultAnnotations map[string]string `short:"A" help:"Default annotations to apply to the image" env:"TKO_DEFAULT_ANNOTATIONS" default:"" mapsep:"," sep:"="`
Annotations map[string]string `short:"a" help:"Additional annotations to apply to the image. Can override default-annotations." env:"TKO_ANNOTATIONS" default:"" mapsep:"," sep:"="`

Tmp string `help:"Path where tko can write temporary files. Defaults to golang's tmp logic." env:"TKO_TMP" default:""`
Verbose bool `short:"v" help:"Enable verbose output"`
Expand All @@ -50,13 +50,13 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
github.Keychain,
)

// Labels would ideally be merged by kong, but this works too
labels := make(map[string]string)
for k, v := range b.DefaultLabels {
labels[k] = v
// Annotations would ideally be merged by kong, but this works too
annotations := make(map[string]string)
for k, v := range b.DefaultAnnotations {
annotations[k] = v
}
for k, v := range b.Labels {
labels[k] = v
for k, v := range b.Annotations {
annotations[k] = v
}

cfg := build.BuildSpec{
Expand All @@ -72,8 +72,8 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
Type: targetType,
},

Author: b.Author,
Labels: labels,
Author: b.Author,
Annotations: annotations,
}

out, err := yaml.Marshal(cfg)
Expand Down
4 changes: 2 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"^.github/workflows/(.+).yml$"
],
"matchStrings": [
"TKO_BASE_IMAGE:\\s*(?<depName>[^:\\n]+):(?<currentValue>[^@\\n]+)(@(?<currentDigest>sha256:[a-f0-9]+))?"
"TKO_BASE_REF:\\s*(?<depName>[^:\\n]+):(?<currentValue>[^@\\n]+)(@(?<currentDigest>sha256:[a-f0-9]+))?"
],
"autoReplaceStringTemplate": "TKO_BASE_IMAGE: {{{depName}}}:{{{newValue}}}{{#if newDigest}}@{{{newDigest}}}{{/if}}",
"autoReplaceStringTemplate": "TKO_BASE_REF: {{{depName}}}:{{{newValue}}}{{#if newDigest}}@{{{newDigest}}}{{/if}}",
"datasourceTemplate": "docker"
}
]
Expand Down

0 comments on commit f470246

Please sign in to comment.