From 127b5fc8489154fab32abf048b8f6e38dba19b6b Mon Sep 17 00:00:00 2001 From: Enrico Candino Date: Tue, 18 Feb 2025 11:59:20 +0100 Subject: [PATCH] Remove dapper (#254) * wip drop dapper * added tests, validate * fix kubebuilder assets * debug * fix maybe * export global * export global 2 * fix goreleaser * dev doc section improved * crd and docs * drop dapper * drop unused tmpl * added help * typos, and added `build-crds` target to default --- .github/workflows/test.yaml | 38 ++---- .gitignore | 1 + .goreleaser.yaml | 4 +- Dockerfile.dapper | 34 ------ Makefile | 111 ++++++++++++++++-- docs/development.md | 94 +++++++++++++-- manifest-runtime.tmpl | 6 - ops/boilerplate.go.txt | 16 --- ops/build | 46 -------- ops/build-crds | 8 -- ops/checksum | 16 --- ops/ci | 11 -- ops/default | 8 -- ops/entry | 11 -- ops/index-chart | 31 ----- ops/package | 30 ----- ops/package-chart | 10 -- ops/release | 3 - ops/test | 9 -- ops/validate | 21 ---- ops/validate-ci | 15 --- ops/version | 33 ------ package/{Dockerfile => Dockerfile.k3k} | 0 ...kerfile.kubelet => Dockerfile.k3k-kubelet} | 0 scripts/build | 17 +-- 25 files changed, 204 insertions(+), 369 deletions(-) delete mode 100644 Dockerfile.dapper delete mode 100644 manifest-runtime.tmpl delete mode 100755 ops/boilerplate.go.txt delete mode 100755 ops/build delete mode 100755 ops/build-crds delete mode 100755 ops/checksum delete mode 100755 ops/ci delete mode 100755 ops/default delete mode 100755 ops/entry delete mode 100755 ops/index-chart delete mode 100755 ops/package delete mode 100755 ops/package-chart delete mode 100755 ops/release delete mode 100755 ops/test delete mode 100755 ops/validate delete mode 100755 ops/validate-ci delete mode 100755 ops/version rename package/{Dockerfile => Dockerfile.k3k} (100%) rename package/{Dockerfile.kubelet => Dockerfile.k3k-kubelet} (100%) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 834bde0e..0f426bb3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,24 +37,11 @@ jobs: with: go-version-file: go.mod - - name: Check go modules - run: | - go mod tidy + - name: Validate + run: make validate - git --no-pager diff go.mod go.sum - test -z "$(git status --porcelain)" - - - name: Install tools - run: | - go install github.com/onsi/ginkgo/v2/ginkgo - go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest - - ENVTEST_BIN=$(setup-envtest use -p path) - sudo mkdir -p /usr/local/kubebuilder/bin - sudo cp $ENVTEST_BIN/* /usr/local/kubebuilder/bin - - - name: Run tests - run: ginkgo -v -r --skip-file=tests + - name: Run unit tests + run: make test-unit tests-e2e: runs-on: ubuntu-latest @@ -70,19 +57,16 @@ jobs: with: go-version-file: go.mod - - name: Check go modules - run: | - go mod tidy - - git --no-pager diff go.mod go.sum - test -z "$(git status --porcelain)" + - name: Validate + run: make validate - name: Install Ginkgo run: go install github.com/onsi/ginkgo/v2/ginkgo - - name: Build + - name: Build and package run: | - ./scripts/build + make build + make package # add k3kcli to $PATH echo "${{ github.workspace }}/bin" >> $GITHUB_PATH @@ -90,8 +74,8 @@ jobs: - name: Check k3kcli run: k3kcli -v - - name: Run tests - run: ginkgo -v ./tests + - name: Run e2e tests + run: make test-e2e - name: Archive k3s logs uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index b0462247..5d1a1c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .vscode/ __debug* *-kubeconfig.yaml +.envtest diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c37f2213..030ae95d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -72,7 +72,7 @@ dockers: ids: - k3k - k3kcli - dockerfile: "package/Dockerfile" + dockerfile: "package/Dockerfile.k3k" skip_push: false image_templates: - "{{- if .Env.REGISTRY }}{{ .Env.REGISTRY }}/{{ end }}{{ .Env.REPO }}:{{ .Tag }}" @@ -84,7 +84,7 @@ dockers: use: docker ids: - k3k-kubelet - dockerfile: "package/Dockerfile.kubelet" + dockerfile: "package/Dockerfile.k3k-kubelet" skip_push: false image_templates: - "{{- if .Env.REGISTRY }}{{ .Env.REGISTRY }}/{{ end }}{{ .Env.REPO }}-kubelet:{{ .Tag }}" diff --git a/Dockerfile.dapper b/Dockerfile.dapper deleted file mode 100644 index c927f3ea..00000000 --- a/Dockerfile.dapper +++ /dev/null @@ -1,34 +0,0 @@ -ARG GOLANG=rancher/hardened-build-base:v1.23.4b1 -FROM ${GOLANG} - -ARG DAPPER_HOST_ARCH -ENV ARCH $DAPPER_HOST_ARCH - -RUN apk -U add \bash git gcc musl-dev docker vim less file curl wget ca-certificates -RUN if [ "${ARCH}" == "amd64" ]; then \ - curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.0; \ - fi - -RUN curl -sL https://github.com/helm/chart-releaser/releases/download/v1.5.0/chart-releaser_1.5.0_linux_${ARCH}.tar.gz | tar -xz cr \ - && mv cr /bin/ - -# Tool for CRD generation. -ENV CONTROLLER_GEN_VERSION v0.14.0 -RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} - -# Tool to setup the envtest framework to run the controllers integration tests -RUN go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && \ - ENVTEST_BIN=$(setup-envtest use -p path) && \ - mkdir -p /usr/local/kubebuilder/bin && \ - cp $ENVTEST_BIN/* /usr/local/kubebuilder/bin - -ENV GO111MODULE on -ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS GITHUB_TOKEN SKIP_TESTS GIT_TAG -ENV DAPPER_SOURCE /go/src/github.com/rancher/k3k/ -ENV DAPPER_OUTPUT ./bin ./dist ./deploy ./charts -ENV DAPPER_DOCKER_SOCKET true -ENV HOME ${DAPPER_SOURCE} -WORKDIR ${DAPPER_SOURCE} - -ENTRYPOINT ["./ops/entry"] -CMD ["ci"] diff --git a/Makefile b/Makefile index 8dcb2fc5..e78cdee4 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,103 @@ -TARGETS := $(shell ls ops) -.dapper: - @echo Downloading dapper - @curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp - @@chmod +x .dapper.tmp - @./.dapper.tmp -v - @mv .dapper.tmp .dapper -$(TARGETS): .dapper - ./.dapper $@ +REPO ?= rancher +VERSION ?= $(shell git describe --tags --always --dirty --match="v[0-9]*") -.DEFAULT_GOAL := default +## Dependencies -.PHONY: $(TARGETS) \ No newline at end of file +GOLANGCI_LINT_VERSION := v1.63.4 +CONTROLLER_TOOLS_VERSION ?= v0.14.0 +GINKGO_VERSION ?= v2.21.0 +ENVTEST_VERSION ?= latest +ENVTEST_K8S_VERSION := 1.31.0 + +GOLANGCI_LINT ?= go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) +CONTROLLER_GEN ?= go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) +GINKGO ?= go run github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) + +ENVTEST ?= go run sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION) +ENVTEST_DIR ?= $(shell pwd)/.envtest +export KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_DIR) -p path) + + +.PHONY: all +all: version build-crds build package ## Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' + +.PHONY: version +version: ## Print the current version + @echo $(VERSION) + +.PHONY: build +build: ## Build the the K3k binaries (k3k, k3k-kubelet and k3kcli) + @VERSION=$(VERSION) ./scripts/build + +.PHONY: package +package: package-k3k package-k3k-kubelet ## Package the k3k and k3k-kubelet Docker images + +.PHONY: package-% +package-%: + docker build -f package/Dockerfile.$* \ + -t $(REPO)/$*:$(VERSION) \ + -t $(REPO)/$*:latest \ + -t $(REPO)/$*:dev . + +.PHONY: push +push: push-k3k push-k3k-kubelet ## Push the K3k images to the registry + +.PHONY: push-% +push-%: + docker push $(REPO)/$*:$(VERSION) + docker push $(REPO)/$*:latest + docker push $(REPO)/$*:dev + + +.PHONY: test +test: ## Run all the tests + $(GINKGO) -v -r + +.PHONY: test-unit +test-unit: ## Run the unit tests (skips the e2e) + $(GINKGO) -v -r --skip-file=tests/* + +.PHONY: test-controller +test-controller: ## Run the controller tests (pkg/controller) + $(GINKGO) -v -r pkg/controller + +.PHONY: test-e2e +test-e2e: ## Run the e2e tests + $(GINKGO) -v -r tests + +.PHONY: build-crds +build-crds: ## Build the CRDs specs + @# This will return non-zero until all of our objects in ./pkg/apis can generate valid crds. + @# allowDangerousTypes is needed for struct that use floats + $(CONTROLLER_GEN) crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=false \ + paths=./pkg/apis/... \ + output:crd:dir=./charts/k3k/crds + +.PHONY: docs +docs: ## Build the CRDs docs + $(MAKE) -C docs/crds + +.PHONY: lint +lint: ## Find any linting issues in the project + $(GOLANGCI_LINT) run --timeout=5m + +.PHONY: validate +validate: build-crds docs ## Validate the project checking for any dependency or doc mismatch + go mod tidy + git --no-pager diff go.mod go.sum + test -z "$(shell git status --porcelain)" + + +.PHONY: install +install: ## Install K3k with Helm on the targeted Kubernetes cluster + helm upgrade --install --namespace k3k-system --create-namespace \ + --set image.repository=$(REPO)/k3k \ + --set image.tag=$(VERSION) \ + --set sharedAgent.image.repository=$(REPO)/k3k-kubelet \ + --set sharedAgent.image.tag=$(VERSION) \ + k3k ./charts/k3k/ + +.PHONY: help +help: ## Show this help. + @egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' \ No newline at end of file diff --git a/docs/development.md b/docs/development.md index 1689a7f2..b59a7a9c 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,15 +1,93 @@ # Development + +## Prerequisites + +To start developing K3k you will need: + +- Go +- Docker +- Helm +- A running Kubernetes cluster + + +### TLDR + +```shell +#!/bin/bash + +set -euo pipefail + +# These environment variables configure the image repository and tag. +export REPO=ghcr.io/myuser +export VERSION=dev-$(date -u '+%Y%m%d%H%M') + +make +make push +make install +``` + +### Makefile + +To see all the available Make commands you can run `make help`, i.e: + +``` +-> % make help + all Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' + version Print the current version + build Build the the K3k binaries (k3k, k3k-kubelet and k3kcli) + package Package the k3k and k3k-kubelet Docker images + push Push the K3k images to the registry + test Run all the tests + test-unit Run the unit tests (skips the e2e) + test-controller Run the controller tests (pkg/controller) + test-e2e Run the e2e tests + build-crds Build the CRDs specs + docs Build the CRDs docs + lint Find any linting issues in the project + validate Validate the project checking for any dependency or doc mismatch + install Install K3k with Helm on the targeted Kubernetes cluster + help Show this help. +``` + +### Build + +To build the needed binaries (`k3k`, `k3k-kubelet` and the `k3kcli`) and package the images you can simply run `make`. + +By default the `rancher` repository will be used, but you can customize this to your registry with the `REPO` env var: + +``` +REPO=ghcr.io/userorg make +``` + +To customize the tag you can also explicitly set the VERSION: + +``` +VERSION=dev-$(date -u '+%Y%m%d%H%M') make +``` + + +### Push + +You will need to push the built images to your registry, and you can use the `make push` command to do this. + + +### Install + +Once you have your images available you can install K3k with the `make install` command. This will use `helm` to install the release. + + ## Tests -To run the tests we use [Ginkgo](https://onsi.github.io/ginkgo/), and [`envtest`](https://book.kubebuilder.io/reference/envtest) for testing the controllers. +To run the tests you can just run `make test`, or one of the other available "sub-tests" targets (`test-unit`, `test-controller`, `test-e2e`). -Install the required binaries from `envtest` with [`setup-envtest`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest), and then put them in the default path `/usr/local/kubebuilder/bin`: +We use [Ginkgo](https://onsi.github.io/ginkgo/), and [`envtest`](https://book.kubebuilder.io/reference/envtest) for testing the controllers. -``` -ENVTEST_BIN=$(setup-envtest use -p path) -sudo mkdir -p /usr/local/kubebuilder/bin -sudo cp $ENVTEST_BIN/* /usr/local/kubebuilder/bin -``` +The required binaries for `envtest` are installed with [`setup-envtest`](https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest), in the `.envtest` folder. -then run `ginkgo run ./...`. + +## CRDs and Docs + +We are using Kubebuilder and `controller-gen` to build the needed CRDs. To generate the specs you can run `make build-crds`. + +Remember also to update the CRDs documentation running the `make docs` command. diff --git a/manifest-runtime.tmpl b/manifest-runtime.tmpl deleted file mode 100644 index 05a21a68..00000000 --- a/manifest-runtime.tmpl +++ /dev/null @@ -1,6 +0,0 @@ -image: rancher/k3k:{{replace "+" "-" build.tag}} -manifests: - - image: rancher/k3k:{{replace "+" "-" build.tag}}-amd64 - platform: - architecture: amd64 - os: linux \ No newline at end of file diff --git a/ops/boilerplate.go.txt b/ops/boilerplate.go.txt deleted file mode 100755 index 115ad205..00000000 --- a/ops/boilerplate.go.txt +++ /dev/null @@ -1,16 +0,0 @@ -/* -Copyright YEAR Rancher Labs, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - diff --git a/ops/build b/ops/build deleted file mode 100755 index 7bbf7ccb..00000000 --- a/ops/build +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -ex - -source $(dirname $0)/version - -cd $(dirname $0)/.. - -mkdir -p bin deploy - -if [ "$(uname)" = "Linux" ]; then - OTHER_LINKFLAGS="-extldflags -static -s" -fi - -LINKFLAGS="-X github.com/rancher/k3k.Version=$VERSION" -LINKFLAGS="-X github.com/rancher/k3k.GitCommit=$COMMIT $LINKFLAGS" -CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k -if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then - CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k-s390x - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k-arm64 - GOOS=freebsd GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3k-freebsd - GOOS=darwin GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3k-darwin-amd64 - GOOS=darwin GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3k-darwin-aarch64 - GOOS=windows GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3k-windows -fi - -# build k3k-kubelet -CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k-kubelet ./k3k-kubelet -if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then - CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k-kubelet-s390x - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3k-kubelet-arm64 - GOOS=freebsd GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3k-kubelet-freebsd - GOOS=darwin GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3k-kubelet-darwin-amd64 - GOOS=darwin GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3k-kubelet-darwin-aarch64 - GOOS=windows GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3k-kubelet-windows -fi - -# build k3kcli -CGO_ENABLED=0 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3kcli ./cli -if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then - CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3kcli-s390x ./cli - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/k3kcli-arm64 ./cli - GOOS=freebsd GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3kcli-freebsd ./cli - GOOS=darwin GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3kcli-darwin-amd64 ./cli - GOOS=darwin GOARCH=arm64 go build -ldflags "$LINKFLAGS" -o bin/k3kcli-darwin-aarch64 ./cli - GOOS=windows GOARCH=amd64 go build -ldflags "$LINKFLAGS" -o bin/k3kcli-windows ./cli -fi diff --git a/ops/build-crds b/ops/build-crds deleted file mode 100755 index 295bc4c8..00000000 --- a/ops/build-crds +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/sh - -cd $(dirname $0)/../ - -# This will return non-zero until all of our objects in ./pkg/apis can generate valid crds. -# allowDangerousTypes is needed for struct that use floats -controller-gen crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=false paths=./pkg/apis/... output:crd:dir=./charts/k3k/crds - diff --git a/ops/checksum b/ops/checksum deleted file mode 100755 index 5cbc2c66..00000000 --- a/ops/checksum +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -ex - -cd $(dirname $0)/.. - -CHECKSUM_DIR=${CHECKSUM_DIR:-./bin} - -sumfile="${CHECKSUM_DIR}/sha256sum.txt" -echo -n "" > "${sumfile}" - -files=$(ls ${CHECKSUM_DIR} | grep -v "sha256sum.txt") -for file in ${files}; do - sha256sum "${CHECKSUM_DIR}/${file}" | sed "s;$(dirname ${CHECKSUM_DIR}/${file})/;;g" >> "${sumfile}" -done - -cat "${sumfile}" \ No newline at end of file diff --git a/ops/ci b/ops/ci deleted file mode 100755 index a26b8e61..00000000 --- a/ops/ci +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0) - -./build -./checksum -./test -./validate -./validate-ci -./package diff --git a/ops/default b/ops/default deleted file mode 100755 index af2ad2db..00000000 --- a/ops/default +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0) - -./build -./test -./package diff --git a/ops/entry b/ops/entry deleted file mode 100755 index 3b5eeef4..00000000 --- a/ops/entry +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -mkdir -p bin dist -if [ -e ./ops/$1 ]; then - ./ops/"$@" -else - exec "$@" -fi - -chown -R $DAPPER_UID:$DAPPER_GID . diff --git a/ops/index-chart b/ops/index-chart deleted file mode 100755 index 58d79646..00000000 --- a/ops/index-chart +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -set -ex - -source $(dirname $0)/version - -cd $(dirname $0)/.. - -git fetch --tags -CHART_TAG=chart-$(grep "version: " charts/k3k/Chart.yaml | awk '{print $2}') -if [ $(git tag -l "$version") ]; then - echo "tag already exists" - exit 1 -fi - -# update the index.yaml -cr index --token ${GITHUB_TOKEN} \ - --release-name-template "chart-{{ .Version }}" \ - --package-path ./deploy/ \ - --index-path index.yaml \ - --git-repo k3k \ - -o rancher - -# push to gh-pages -git config --global user.email "hussein.galal.ahmed.11@gmail.com" -git config --global user.name "galal-hussein" -git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/ - -# push index.yaml to gh-pages -git add index.yaml -git commit -m "add chart-${CHART_TAG} to index.yaml" -git push --force --set-upstream origin HEAD:gh-pages diff --git a/ops/package b/ops/package deleted file mode 100755 index 783e0fec..00000000 --- a/ops/package +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set -e - -source $(dirname $0)/version - -cd $(dirname $0)/.. - -mkdir -p dist/artifacts -cp bin/k3k dist/artifacts/k3k${SUFFIX} -cp bin/k3kcli dist/artifacts/k3kcli${SUFFIX} -cp bin/k3k-kubelet dist/artifacts/k3k-kubelet${SUFFIX} - -IMAGE=${REPO}/k3k:${TAG} -DOCKERFILE=package/Dockerfile -if [ -e ${DOCKERFILE}.${ARCH} ]; then - DOCKERFILE=${DOCKERFILE}.${ARCH} -fi - -docker build -f ${DOCKERFILE} -t ${IMAGE} . -echo Built ${IMAGE} - -# todo: This might need to go to it's own repo -IMAGE=${REPO}/k3k:${TAG}-kubelet -DOCKERFILE=package/Dockerfile.kubelet -if [ -e ${DOCKERFILE}.${ARCH} ]; then - DOCKERFILE=${DOCKERFILE}.${ARCH} -fi - -docker build -f ${DOCKERFILE} -t ${IMAGE} . -echo Built ${IMAGE} diff --git a/ops/package-chart b/ops/package-chart deleted file mode 100755 index 361f24c0..00000000 --- a/ops/package-chart +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -ex - -source $(dirname $0)/version - -cd $(dirname $0)/.. - -mkdir -p deploy/ - -cr package --package-path deploy/ charts/k3k \ No newline at end of file diff --git a/ops/release b/ops/release deleted file mode 100755 index 7af0df35..00000000 --- a/ops/release +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -exec $(dirname $0)/ci diff --git a/ops/test b/ops/test deleted file mode 100755 index 19b2d792..00000000 --- a/ops/test +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -if [ -z ${SKIP_TESTS} ]; then - echo Running tests - go test -cover -tags=test ./... -fi diff --git a/ops/validate b/ops/validate deleted file mode 100755 index 7f98128b..00000000 --- a/ops/validate +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -echo Running validation - -PACKAGES="$(go list ./...)" - -if ! command -v golangci-lint; then - echo Skipping validation: no golangci-lint available - exit -fi - -echo Running validation - -echo Running: golangci-lint -golangci-lint run - -echo Running: go fmt -test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)" diff --git a/ops/validate-ci b/ops/validate-ci deleted file mode 100755 index 9217ab2a..00000000 --- a/ops/validate-ci +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -e - -cd $(dirname $0)/.. - -go generate - -source ./ops/version - -if [ -n "$DIRTY" ]; then - echo Git is dirty - git status - git diff - exit 1 -fi diff --git a/ops/version b/ops/version deleted file mode 100755 index 112eb69d..00000000 --- a/ops/version +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - DIRTY="-dirty" -fi - -COMMIT=$(git rev-parse --short HEAD) -GIT_TAG=${TAG:-$(git tag -l --contains HEAD | head -n 1)} - -if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then - VERSION=$GIT_TAG -else - VERSION="${COMMIT}${DIRTY}" -fi - -if [ -z "$ARCH" ]; then - ARCH=$(go env GOHOSTARCH) -fi - -SUFFIX="-${ARCH}" - - -if [[ $VERSION = "chart*" ]]; then - TAG=${TAG:-${VERSION}} -else - TAG=${TAG:-${VERSION}${SUFFIX}} -fi - -REPO=${REPO:-rancher} - -if echo $TAG | grep dirty; then - TAG=dev -fi diff --git a/package/Dockerfile b/package/Dockerfile.k3k similarity index 100% rename from package/Dockerfile rename to package/Dockerfile.k3k diff --git a/package/Dockerfile.kubelet b/package/Dockerfile.k3k-kubelet similarity index 100% rename from package/Dockerfile.kubelet rename to package/Dockerfile.k3k-kubelet diff --git a/scripts/build b/scripts/build index 6f318352..5e7b8af8 100755 --- a/scripts/build +++ b/scripts/build @@ -1,17 +1,11 @@ #!/bin/bash -set -e pipefail +set -eou pipefail -TAG=$(git describe --tag --always --match="v[0-9]*") +LDFLAGS="-X \"github.com/rancher/k3k/pkg/buildinfo.Version=${VERSION}\"" -if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - TAG="${TAG}-dirty" -fi - -LDFLAGS="-X \"github.com/rancher/k3k/pkg/buildinfo.Version=${TAG}\"" - -echo "Building k3k..." -echo "Current TAG: ${TAG}" +echo "Building k3k... [cli os/arch: $(go env GOOS)/$(go env GOARCH)]" +echo "Current TAG: ${VERSION} " export CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/k3k @@ -19,6 +13,3 @@ GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o bin/k3k-kubelet ./k3k- # build the cli for the local OS and ARCH go build -ldflags="${LDFLAGS}" -o bin/k3kcli ./cli - -docker build -f package/Dockerfile -t rancher/k3k:dev -t rancher/k3k:${TAG} . -docker build -f package/Dockerfile.kubelet -t rancher/k3k-kubelet:dev -t rancher/k3k-kubelet:${TAG} .