Skip to content

Commit

Permalink
add yaml config file
Browse files Browse the repository at this point in the history
  • Loading branch information
dskiff committed Apr 27, 2024
1 parent 84c5505 commit d1bcc5c
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ 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" -d "/usr/local/bin" "./dist/tko_linux_amd64_v1"
run: tko build -t "ghcr.io/dskiff/tko:latest" "./dist/tko_linux_amd64_v1"
env:
TKO_ENTRYPOINT: /bin/bash
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
run: cp ./dist/tko_linux_amd64_v1/tko /usr/local/bin/tko

- name: Publish (bin)
run: tko build -b "scratch" -d "/usr/local/bin" -t "ghcr.io/dskiff/tko:bin" "./dist/tko_linux_amd64_v1"
run: tko build -b "scratch" -t "ghcr.io/dskiff/tko:bin" "./dist/tko_linux_amd64_v1"
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Publish (version)
run: tko build -d "/usr/local/bin" -t "ghcr.io/dskiff/tko:${{ github.ref_name }}" "./dist/tko_linux_amd64_v1"
run: tko build -t "ghcr.io/dskiff/tko:${{ github.ref_name }}" "./dist/tko_linux_amd64_v1"
env:
TKO_ENTRYPOINT: /bin/bash
TKO_BASE_IMAGE: debian:bookworm-slim@sha256:155280b00ee0133250f7159b567a07d7cd03b1645714c3a7458b2287b0ca83cb
Expand Down
3 changes: 3 additions & 0 deletions .tko.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
destination-path: /usr/local/bin
entrypoint: /usr/local/bin/tko
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tko is:
- Simple (pull base image, add content, push to registry)
- Low footprint (~15MiB, single static binary, no runtime deps)
- Rootless (no sudo/daemon/chroot/caps/goats blood/etc needed)
- Reproducible (same build artifacts -> same image digest)
- Reproducible (same base + build artifacts -> same image digest)

tko is NOT a replacement for generic docker build (or buildah, kaniko, etc). It cannot run a Dockerfile. It combines your build artifacts with a base image and modifies metadata. That's it. For me, this was enough for the majority of my container builds, but YMMV.

Expand Down
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ require (
github.com/joho/godotenv v1.5.1
)

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/kr/pretty v0.3.1 // indirect
gopkg.in/yaml.v3 v3.0.1
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
github.com/alecthomas/kong-yaml v0.2.0 h1:iiVVqVttmOsHKawlaW/TljPsjaEv1O4ODx6dloSA58Y=
github.com/alecthomas/kong-yaml v0.2.0/go.mod h1:vMvOIy+wpB49MCZ0TA3KMts38Mu9YfRP03Q1StN69/g=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down Expand Up @@ -50,6 +52,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down Expand Up @@ -80,6 +83,7 @@ github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3I
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -89,6 +93,7 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand Down Expand Up @@ -120,6 +125,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -149,6 +155,7 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/dskiff/tko/pkg/cmd"

"github.com/alecthomas/kong"
kongyaml "github.com/alecthomas/kong-yaml"
"github.com/joho/godotenv"
)

Expand All @@ -35,7 +36,8 @@ func main() {
ExitCleanWatcher: exitCleanWatcher,
}

args := kong.Parse(&cmd.CLI)
cli := cmd.CLI{}
args := kong.Parse(&cli, kong.Configuration(kongyaml.Loader, "./.tko.yaml", "./.tko.yml"))

err := args.Run(&cliContext)
if err != nil {
Expand Down
112 changes: 112 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main_test

import (
"strings"
"testing"

"github.com/alecthomas/kong"
kongyaml "github.com/alecthomas/kong-yaml"
"github.com/dskiff/tko/pkg/cmd"
"gotest.tools/v3/assert"
)

func TestYamlBasic(t *testing.T) {
yaml := `
build:
base-ref: base-image@sha256:1234
platform: custom-os/arch-variant
entrypoint: /entrypoint
destination-path: /destination
target-repo: repo/target
author: me
labels:
label1: value1
label2: value2
tmp: /tmp-dir
verbose: true
`

r, err := kongyaml.Loader(strings.NewReader(yaml))
assert.NilError(t, err)

cli := cmd.CLI{}
parser := mustNew(t, &cli, kong.Resolvers(r))
_, err = parser.Parse([]string{"build", "/source"})
assert.NilError(t, err)

assert.Equal(t, "base-image@sha256:1234", cli.Build.BaseRef)

assert.Equal(t, "custom-os/arch-variant", cli.Build.Platform)

assert.Equal(t, "/entrypoint", cli.Build.Entrypoint)
assert.Equal(t, "/destination", cli.Build.DestinationPath)
assert.Equal(t, "repo/target", cli.Build.TargetRepo)

assert.Equal(t, "me", cli.Build.Author)
assert.Equal(t, "value1", cli.Build.Labels["label1"])
assert.Equal(t, "value2", cli.Build.Labels["label2"])

assert.Equal(t, "/tmp-dir", cli.Build.Tmp)
assert.Equal(t, true, cli.Build.Verbose)
}

func TestVersionArgs(t *testing.T) {
cli := cmd.CLI{}
parser := mustNew(t, &cli)
args, err := parser.Parse([]string{"version"})
assert.NilError(t, err)

assert.Equal(t, true, args.Command() == "version")
}

func TestBuildArgs(t *testing.T) {
cli := cmd.CLI{}
parser := mustNew(t, &cli)
_, err := parser.Parse([]string{"build", "/source",
"-b", "base-image@sha256:1234",
"-p", "custom-os/arch-variant",
"-e", "/entrypoint",
"-d", "/destination",
"-t", "repo/target",
"-a", "me",
"-l", "label1=value1",
"-l", "label2=value2",
"-T", "REMOTE",
"-v",
"--tmp", "/tmp-dir",
})
assert.NilError(t, err)

assert.Equal(t, "base-image@sha256:1234", cli.Build.BaseRef)

assert.Equal(t, "custom-os/arch-variant", cli.Build.Platform)

assert.Equal(t, "/entrypoint", cli.Build.Entrypoint)
assert.Equal(t, "/destination", cli.Build.DestinationPath)
assert.Equal(t, "repo/target", cli.Build.TargetRepo)

assert.Equal(t, "me", cli.Build.Author)
assert.Equal(t, "value1", cli.Build.Labels["label1"])
assert.Equal(t, "value2", cli.Build.Labels["label2"])

assert.Equal(t, "/tmp-dir", cli.Build.Tmp)
assert.Equal(t, true, cli.Build.Verbose)
}

func mustNew(t *testing.T, cli interface{}, options ...kong.Option) *kong.Kong {
t.Helper()
options = append([]kong.Option{
kong.Name("test"),
kong.Exit(func(int) {
t.Helper()
t.Fatalf("unexpected exit()")
}),
}, options...)
parser, err := kong.New(cli, options...)
assert.NilError(t, err)
return parser
}
5 changes: 3 additions & 2 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type BuildCmd struct {
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:"="`

Verbose bool `short:"v" help:"Enable verbose output"`
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"`
}

func (b *BuildCmd) Run(cliCtx *CliCtx) error {
Expand Down Expand Up @@ -85,6 +86,6 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
ExitCleanupWatcher: cliCtx.ExitCleanWatcher,
Keychain: keychain,

TempPath: os.Getenv("TKO_TEMP_PATH"),
TempPath: b.Tmp,
}, cfg)
}
2 changes: 1 addition & 1 deletion pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (v *VersionCmd) Run(cliCtx *CliCtx) error {
return nil
}

var CLI struct {
type CLI struct {
Version VersionCmd `cmd:"" help:"Show version."`

Build BuildCmd `cmd:"" help:"Build and publish a container image."`
Expand Down

0 comments on commit d1bcc5c

Please sign in to comment.