From feb79f5463b216708c81e1aa94f83e074a2801bf Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 3 Oct 2024 23:49:26 +0200 Subject: [PATCH 1/2] Use a variable for docker runtime This makes it possible to use podman. Signed-off-by: Natanael Copa --- Makefile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5c2825e6df47..c4c1ca95bdfa 100644 --- a/Makefile +++ b/Makefile @@ -69,9 +69,10 @@ endif endif LD_FLAGS += $(BUILD_GO_LDFLAGS_EXTRA) +DOCKER = docker GOLANG_IMAGE ?= $(golang_buildimage) K0S_GO_BUILD_CACHE_VOLUME_PATH=$(realpath $(K0S_GO_BUILD_CACHE)) -GO_ENV ?= docker run --rm \ +GO_ENV ?= $(DOCKER) run --rm \ -v '$(K0S_GO_BUILD_CACHE_VOLUME_PATH)':/run/k0s-build \ -v '$(CURDIR)':/go/src/github.com/k0sproject/k0s \ -w /go/src/github.com/k0sproject/k0s \ @@ -105,7 +106,7 @@ $(K0S_GO_BUILD_CACHE): mkdir -p -- '$@' .k0sbuild.docker-image.k0s: build/Dockerfile embedded-bins/Makefile.variables | $(K0S_GO_BUILD_CACHE) - docker build --progress=plain --iidfile '$@' \ + $(DOCKER) build --progress=plain --iidfile '$@' \ --build-arg BUILDIMAGE=$(GOLANG_IMAGE) \ -t k0sbuild.docker-image.k0s - '$@' .k0sbuild.image-bundler.stamp: hack/image-bundler/* embedded-bins/Makefile.variables - docker build --progress=plain --iidfile '$@' \ + $(DOCKER) build --progress=plain --iidfile '$@' \ --build-arg ALPINE_VERSION=$(alpine_patch_version) \ -t k0sbuild.image-bundler -- hack/image-bundler @@ -294,7 +295,7 @@ docs: docs-serve-dev: DOCS_DEV_PORT ?= 8000 docs-serve-dev: $(MAKE) -C docs .docker-image.serve-dev.stamp - docker run --rm \ + $(DOCKER) run --rm \ -e KUBERNETES_VERSION='$(kubernetes_version)' \ -v "$(CURDIR):/k0s:ro" \ -p '$(DOCS_DEV_PORT):8000' \ @@ -302,7 +303,7 @@ docs-serve-dev: sbom/spdx.json: go.mod mkdir -p -- '$(dir $@)' - docker run --rm \ + $(DOCKER) run --rm \ -v "$(CURDIR)/go.mod:/k0s/go.mod" \ -v "$(CURDIR)/embedded-bins/staging/linux/bin:/k0s/bin" \ -v "$(CURDIR)/syft.yaml:/tmp/syft.yaml" \ @@ -313,7 +314,7 @@ sbom/spdx.json: go.mod .PHONY: sign-sbom sign-sbom: sbom/spdx.json - docker run --rm \ + $(DOCKER) run --rm \ -v "$(CURDIR):/k0s" \ -v "$(CURDIR)/sbom:/out" \ -e COSIGN_PASSWORD="$(COSIGN_PASSWORD)" \ @@ -325,7 +326,7 @@ sign-sbom: sbom/spdx.json .PHONY: sign-pub-key sign-pub-key: - docker run --rm \ + $(DOCKER) run --rm \ -v "$(CURDIR):/k0s" \ -v "$(CURDIR)/sbom:/out" \ -e COSIGN_PASSWORD="$(COSIGN_PASSWORD)" \ From 2cd152d6af46d6c282aed3ca96334035777d54bb Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 4 Oct 2024 00:03:02 +0200 Subject: [PATCH 2/2] Support build k0s without docker Disable use of docker by running: make DOCKER=false This will also disable the embedded bins. Signed-off-by: Natanael Copa --- Makefile | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index c4c1ca95bdfa..e00342a8972a 100644 --- a/Makefile +++ b/Makefile @@ -21,11 +21,20 @@ K0S_GO_BUILD_CACHE ?= build/cache GO_SRCS := $(shell find . -type f -name '*.go' -not -path './$(K0S_GO_BUILD_CACHE)/*' -not -path './inttest/*' -not -name '*_test.go' -not -name 'zz_generated*') GO_CHECK_UNIT_DIRS := . ./cmd/... ./pkg/... ./internal/... ./static/... ./hack/... +DOCKER = docker # EMBEDDED_BINS_BUILDMODE can be either: # docker builds the binaries in docker # none does not embed any binaries -EMBEDDED_BINS_BUILDMODE ?= docker +ifeq ($(DOCKER),false) + EMBEDDED_BINS_BUILDMODE ?= none + K0S_BUILD_IMAGE_FILE = + GO ?= go +else + EMBEDDED_BINS_BUILDMODE ?= docker + K0S_BUILD_IMAGE_FILE = .k0sbuild.docker-image.k0s + GO ?= $(GO_ENV) go +endif # k0s runs on linux even if it's built on mac or windows TARGET_OS ?= linux BUILD_UID ?= $(shell id -u) @@ -69,7 +78,6 @@ endif endif LD_FLAGS += $(BUILD_GO_LDFLAGS_EXTRA) -DOCKER = docker GOLANG_IMAGE ?= $(golang_buildimage) K0S_GO_BUILD_CACHE_VOLUME_PATH=$(realpath $(K0S_GO_BUILD_CACHE)) GO_ENV ?= $(DOCKER) run --rm \ @@ -81,8 +89,7 @@ GO_ENV ?= $(DOCKER) run --rm \ -e CGO_CFLAGS \ -e GOARCH \ --user $(BUILD_UID):$(BUILD_GID) \ - -- '$(shell cat .k0sbuild.docker-image.k0s)' -GO ?= $(GO_ENV) go + -- '$(shell cat $(K0S_BUILD_IMAGE_FILE))' # https://www.gnu.org/software/make/manual/make.html#index-spaces_002c-in-variable-values nullstring := @@ -105,12 +112,12 @@ all: k0s k0s.exe $(K0S_GO_BUILD_CACHE): mkdir -p -- '$@' -.k0sbuild.docker-image.k0s: build/Dockerfile embedded-bins/Makefile.variables | $(K0S_GO_BUILD_CACHE) +$(K0S_BUILD_IMAGE_FILE): build/Dockerfile embedded-bins/Makefile.variables | $(K0S_GO_BUILD_CACHE) $(DOCKER) build --progress=plain --iidfile '$@' \ --build-arg BUILDIMAGE=$(GOLANG_IMAGE) \ - -t k0sbuild.docker-image.k0s - '$@' airgap-image-bundle-linux-amd64.tar: TARGET_PLATFORM := linux/amd64 @@ -256,7 +263,7 @@ else check-unit: GO_TEST_RACE ?= -race endif check-unit: BUILD_GO_TAGS += hack -check-unit: .k0sbuild.docker-image.k0s go.sum bindata +check-unit: $(K0S_BUILD_IMAGE_FILE) go.sum bindata CGO_CFLAGS='$(BUILD_CGO_CFLAGS)' $(GO) test -tags=$(subst $(space),$(comma),$(BUILD_GO_TAGS)) $(GO_TEST_RACE) -ldflags='$(LD_FLAGS)' `$(GO) list -tags=$(subst $(space),$(comma),$(BUILD_GO_TAGS)) $(GO_CHECK_UNIT_DIRS)` .PHONY: clean-gocache @@ -265,7 +272,7 @@ clean-gocache: rm -rf -- '$(K0S_GO_BUILD_CACHE)/go' .PHONY: clean-docker-image -clean-docker-image: IID_FILES = .k0sbuild.docker-image.k0s +clean-docker-image: IID_FILES = $(K0S_BUILD_IMAGE_FILE) clean-docker-image: $(clean-iid-files)