Skip to content

Commit

Permalink
use labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dskiff committed Apr 27, 2024
1 parent d1bcc5c commit 9b6d90e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
run: cp ./dist/tko_linux_amd64_v1/tko /usr/local/bin/tko

- name: Publish (latest)
run: tko build -t "ghcr.io/dskiff/tko:latest" "./dist/tko_linux_amd64_v1"
run: tko build -t "ghcr.io/dskiff/tko:latest" -e "/bin/bash" "./dist/tko_linux_amd64_v1"
env:
TKO_ENTRYPOINT: /bin/bash
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
TKO_ADDITIONAL_LABELS: org.opencontainers.image.revision=${{ github.sha }}
GITHUB_TOKEN: ${{ github.token }}
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ jobs:
- name: Publish (bin)
run: tko build -b "scratch" -t "ghcr.io/dskiff/tko:bin" "./dist/tko_linux_amd64_v1"
env:
TKO_ADDITIONAL_LABELS: org.opencontainers.image.revision=${{ github.sha }},org.opencontainers.image.version=${{ github.ref_name }}
GITHUB_TOKEN: ${{ github.token }}

- name: Publish (version)
run: tko build -t "ghcr.io/dskiff/tko:${{ github.ref_name }}" "./dist/tko_linux_amd64_v1"
run: tko build -t "ghcr.io/dskiff/tko:${{ github.ref_name }}" -e "/bin/bash" "./dist/tko_linux_amd64_v1"
env:
TKO_ENTRYPOINT: /bin/bash
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
TKO_ADDITIONAL_LABELS: org.opencontainers.image.revision=${{ github.sha }},org.opencontainers.image.version=${{ github.ref_name }}
GITHUB_TOKEN: ${{ github.token }}
4 changes: 4 additions & 0 deletions .tko.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
build:
destination-path: /usr/local/bin
entrypoint: /usr/local/bin/tko
labels:
org.opencontainers.image.title: tko
org.opencontainers.image.url: github.com/dskiff/tko
org.opencontainers.image.source: github.com/dskiff/tko
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ Enter ko. ko is a simple, single binary. You call `ko build`. It doesn't require

Unfortunately, ko is only for go. If you're using go, and by some weird SEO quirk you ended up here instead. Stop. Go use [ko](https://ko.build). If you're not, tko may be your answer.

## Configuration file

You can also provide any of the supported parameters using a `.tko.yml` (or `.tko.yaml`).

```
build:
base-ref: ubuntu:jammy@sha256:6d7b5d3317a71adb5e175640150e44b8b9a9401a7dd394f44840626aff9fa94d
author: my name
labels:
org.opencontainers.image.source: github.com/my-org/my-project
```

## Examples

### Quarkus + Rootless Github Self Hosted Runners
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ require (
)

require (
github.com/alecthomas/assert/v2 v2.6.0
github.com/alecthomas/kong-yaml v0.2.0
gotest.tools/v3 v3.0.3
)

require (
github.com/alecthomas/repr v0.4.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
)
require github.com/google/go-cmp v0.6.0 // indirect

require (
github.com/kr/pretty v0.3.1 // indirect
Expand Down
16 changes: 13 additions & 3 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +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"`
Labels map[string]string `short:"l" help:"Labels to apply to the image" env:"TKO_LABELS" default:"" mapsep:"," sep:"="`
Author string `short:"a" help:"Author of the build" env:"TKO_AUTHOR" default:"github.com/dskiff/tko"`
Labels map[string]string `short:"l" help:"Labels to apply to the image" env:"TKO_LABELS" default:"" mapsep:"," sep:"="`
AdditionalLabels map[string]string `short:"al" help:"Additional labels to apply to the image" env:"TKO_ADDITIONAL_LABELS" 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 @@ -49,6 +50,15 @@ 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.Labels {
labels[k] = v
}
for k, v := range b.AdditionalLabels {
labels[k] = v
}

cfg := build.BuildSpec{
BaseRef: b.BaseRef,
InjectLayer: build.BuildSpecInjectLayer{
Expand All @@ -63,7 +73,7 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
},

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

out, err := yaml.Marshal(cfg)
Expand Down

0 comments on commit 9b6d90e

Please sign in to comment.