Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
dist/metadata.yaml
dist/cluster-template*.yaml
dist/clusterclass-*.yaml
dist/kini-*
generate_release_notes: true
draft: ${{ contains(github.ref_name, 'rc') }}
prerelease: ${{ contains(github.ref_name, 'rc') }}
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ jobs:

- name: make test
run: make test

- name: make kini
run: |
make kini
./bin/kini --help
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,27 @@ release: manifests generate kustomize ## Generate a consolidated YAML with CRDs
sed -i 's,volumes: \[\],volumes: $${CAPN_VOLUMES:=[]},' dist/infrastructure-components.yaml

.PHONY: dist
dist: release ## Generate release assets.
dist: release kini-release ## Generate release assets.
cp templates/clusterclass*.yaml dist/
cp templates/cluster-template*.yaml dist/
cp metadata.yaml dist/
cp $(LOCALBIN)/kini-* dist/

##@ Kini

KINI ?= $(LOCALBIN)/kini

.PHONY: kini
kini: $(LOCALBIN) ## Build kini for development
go build -o $(KINI) ./cmd/exp/kini
./hack/scripts/kini/build.sh $(KINI) $(TAG)

ln -sf kini $(LOCALBIN)/docker
ln -sf kini $(LOCALBIN)/kind

.PHONY: kini-cross
kini-release: $(LOCALBIN) ## Build kini release binaries
./hack/scripts/kini/build-cross.sh $(LOCALBIN) $(TAG)

##@ Deployment

ifndef ignore-not-found
Expand Down
26 changes: 26 additions & 0 deletions cmd/exp/kini/kini/kini_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kini

import (
"fmt"
"runtime"

"github.com/spf13/cobra"
"sigs.k8s.io/kind/pkg/apis/config/defaults"
kindversion "sigs.k8s.io/kind/pkg/cmd/kind/version"
)

// Set with -X cmd/exp/kini/kini/kini_version.Version=v0.8.2
var version = "dev"

func newKiniVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "print kini version",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("kini version %s (%s %s/%s)\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("kind version v%s (default image %s)\n", kindversion.Version(), defaults.Image)

return nil
},
}
}
2 changes: 2 additions & 0 deletions cmd/exp/kini/kini/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ kini can also be used with an existing kind binary. You can do this as follows:
docker.NewCmd(),
)

cmd.AddCommand(newKiniVersionCmd())

return cmd
}
1 change: 1 addition & 0 deletions docs/book/src/get-kini.sh
11 changes: 11 additions & 0 deletions hack/scripts/kini/build-cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -e

# Usage: $0 <output-dir> <version>

DIR="$(dirname "$(realpath "$0")")"
OUT="$(realpath "${1}")"

# build for each platform
GOOS=linux GOARCH=amd64 "${DIR}/build.sh" "${OUT}/kini-linux-amd64" "${2}"
GOOS=linux GOARCH=arm64 "${DIR}/build.sh" "${OUT}/kini-linux-arm64" "${2}"
GOOS=darwin GOARCH=arm64 "${DIR}/build.sh" "${OUT}/kini-darwin-arm64" "${2}"
16 changes: 16 additions & 0 deletions hack/scripts/kini/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -e

# Usage: $0 <output> <version>

DIR="$(dirname "$(realpath "$0")")"

(
cd "${DIR}/../../../"
export CGO_ENABLED=0

(set -x; go build -o "${1}" \
-ldflags "-s -w -X=github.com/lxc/cluster-api-provider-incus/cmd/exp/kini/kini.version=$2" \
./cmd/exp/kini)

(cd "$(dirname "${1}")"; sha256sum "$(basename "${1}")" > "${1}.sha256sum")
)
55 changes: 55 additions & 0 deletions hack/scripts/kini/get-kini.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash -e

# Usage:
#
# 1). Install latest version
# $ curl https://capn.linuxcontainers.org/get-kini.sh | bash -x
#
# 2). Install in local directory (without root)
# $ curl https://capn.linuxcontainers.org/get-kini.sh | SUDO= KINI_INSTALL_DIR=~/.local/bin bash
#
# 3). Install specific version
# $ curl https://capn.linuxcontainers.org/get-kini.sh | KINI_DOWNLOAD_URL=https://github.com/lxc/cluster-api-provider/releases/v0.8.2/download bash

set -eu

KINI_INSTALL_DIR="${KINI_INSTALL_DIR:-/usr/local/bin}"
KINI_DOWNLOAD_URL="${KINI_DOWNLOAD_URL:-https://github.com/lxc/cluster-api-provider/releases/latest/download}"

# infer SUDO, if not running as root
SUDO="${SUDO:-sudo}"
if [ "$(id -u)" == "0" ]; then SUDO=; fi

# infer OS (linux, darwin)
case "$(uname)" in
Linux) OS=linux ;;
Darwin) OS=darwin ;;
*) echo "Unsupported OS $(uname)"; exit 1 ;;
esac

# infer ARCH (amd64, arm64)
case "$(uname -m)" in
x86_64|amd64) ARCH=amd64 ;;
aarch64|arm64) ARCH=arm64 ;;
*) echo "Unsupported ARCH $(uname -m)"; exit 1 ;;
esac

echo "Downloading ${KINI_DOWNLOAD_URL}/kini-${OS}-${ARCH}"

# download kini binary
(
set -x
mkdir -p "/tmp/kini$$"
curl "${KINI_DOWNLOAD_URL}/kini-${OS}-${ARCH}" -f -o "/tmp/kini$$/kini"

chmod +x "/tmp/kini$$/kini"

"/tmp/kini$$/kini" version

$SUDO mkdir -p "${KINI_INSTALL_DIR}"
$SUDO mv "/tmp/kini$$/kini" "${KINI_INSTALL_DIR}/kini"
rm -rf "/tmp/kini$$"
)

kini version
echo "Successfully downloaded kini at ${KINI_INSTALL_DIR}"
2 changes: 1 addition & 1 deletion internal/exp/kini/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SetupEnvironment(ctx context.Context, docker bool, kind bool) (string, func
return nil
}

self, err := filepath.Abs(os.Args[0])
self, err := os.Executable()
if err != nil {
_ = cleanup()
return "", nil, fmt.Errorf("failed to identity absolute path to %q: %w", os.Args[0], err)
Expand Down
Loading