diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 7f270e62c472..af9af8dcffe0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -195,11 +195,8 @@ jobs: env: EMBEDDED_BINS_BUILDMODE: none TARGET_OS: windows - GO: go - GO_ENV: '' run: | - make --touch .k0sbuild.docker-image.k0s - make check-unit + make check-unit DOCKER='' smoketests: strategy: diff --git a/Makefile b/Makefile index d5f5f90accbc..03d215872d55 100644 --- a/Makefile +++ b/Makefile @@ -22,21 +22,34 @@ GO_SRCS := $(shell find . -type f -name '*.go' -not -path './$(K0S_GO_BUILD_CACH 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 - # Disable Docker build integration if DOCKER is set to the empty string. ifeq ($(DOCKER),) - EMBEDDED_BINS_BUILDMODE ?= none - K0S_BUILD_IMAGE_FILE = - GO ?= go + GO_ENV_REQUISITES ?= + GO_ENV ?= PATH=$(abspath $(K0S_GO_BUILD_CACHE))/go/bin:"$$PATH" \ + GOBIN="$(abspath $(K0S_GO_BUILD_CACHE))/go/bin" \ + GOCACHE="$(abspath $(K0S_GO_BUILD_CACHE))/go/build" \ + GOMODCACHE="$(abspath $(K0S_GO_BUILD_CACHE))/go/mod" + GO ?= $(GO_ENV) go else - EMBEDDED_BINS_BUILDMODE ?= docker - K0S_BUILD_IMAGE_FILE = .k0sbuild.docker-image.k0s + GO_ENV_REQUISITES ?= .k0sbuild.docker-image.k0s + GO_ENV ?= $(DOCKER) run --rm \ + -v '$(realpath $(K0S_GO_BUILD_CACHE))':/run/k0s-build \ + -v '$(CURDIR)':/go/src/github.com/k0sproject/k0s \ + -w /go/src/github.com/k0sproject/k0s \ + -e GOOS \ + -e CGO_ENABLED \ + -e CGO_CFLAGS \ + -e GOARCH \ + --user $(BUILD_UID):$(BUILD_GID) \ + -- '$(shell cat .k0sbuild.docker-image.k0s)' GO ?= $(GO_ENV) go endif +# EMBEDDED_BINS_BUILDMODE can be either: +# docker builds the binaries in docker +# none does not embed any binaries +EMBEDDED_BINS_BUILDMODE ?= docker + # k0s runs on linux even if it's built on mac or windows TARGET_OS ?= linux BUILD_UID ?= $(shell id -u) @@ -81,17 +94,6 @@ endif LD_FLAGS += $(BUILD_GO_LDFLAGS_EXTRA) GOLANG_IMAGE ?= $(golang_buildimage) -K0S_GO_BUILD_CACHE_VOLUME_PATH=$(realpath $(K0S_GO_BUILD_CACHE)) -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 \ - -e GOOS \ - -e CGO_ENABLED \ - -e CGO_CFLAGS \ - -e GOARCH \ - --user $(BUILD_UID):$(BUILD_GID) \ - -- '$(shell cat $(K0S_BUILD_IMAGE_FILE))' # https://www.gnu.org/software/make/manual/make.html#index-spaces_002c-in-variable-values nullstring := @@ -114,12 +116,12 @@ all: k0s k0s.exe $(K0S_GO_BUILD_CACHE): mkdir -p -- '$@' -$(K0S_BUILD_IMAGE_FILE): build/Dockerfile embedded-bins/Makefile.variables | $(K0S_GO_BUILD_CACHE) +.k0sbuild.docker-image.k0s: build/Dockerfile embedded-bins/Makefile.variables | $(K0S_GO_BUILD_CACHE) $(DOCKER) build --progress=plain --iidfile '$@' \ --build-arg BUILDIMAGE=$(GOLANG_IMAGE) \ - -t $(patsubst .%,%,$(K0S_BUILD_IMAGE_FILE)) - '$@' airgap-image-bundle-linux-amd64.tar: TARGET_PLATFORM := linux/amd64 @@ -265,7 +266,7 @@ else check-unit: GO_TEST_RACE ?= -race endif check-unit: BUILD_GO_TAGS += hack -check-unit: $(K0S_BUILD_IMAGE_FILE) go.sum bindata +check-unit: $(GO_ENV_REQUISITES) 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 @@ -274,7 +275,7 @@ clean-gocache: rm -rf -- '$(K0S_GO_BUILD_CACHE)/go' .PHONY: clean-docker-image -clean-docker-image: IID_FILES = $(K0S_BUILD_IMAGE_FILE) +clean-docker-image: IID_FILES = .k0sbuild.docker-image.k0s clean-docker-image: $(clean-iid-files) diff --git a/README.md b/README.md index b3b8d018851d..aae3d3c902ab 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ The requirements for building k0s from source are as follows: All of the compilation steps are performed inside Docker containers, no installation of Go is required. -The k0s binary can be built in two different ways: +The k0s binary can be built in different ways: The "k0s" way, self-contained, all binaries compiled from source, statically linked and embedded: @@ -147,14 +147,23 @@ linked and embedded: make ``` -The "package maintainer" way, without any embedded binaries (requires that the -required binaries are provided separately at runtime): +The "package maintainer" way, without building and embedding the required +binaries. This assumes necessary binaries are provided separately at runtime: ```shell make EMBEDDED_BINS_BUILDMODE=none ``` -The embedded binaries can be built on their own: +As mentioned previously, Docker build integration is enabled by default. +Building k0s without Docker using the system toolchain can be done as follows: + +```shell +make DOCKER='' EMBEDDED_BINS_BUILDMODE=none +``` + +Note that the k0s build system does not currently support building the embedded +binaries using the system toolchain. However, the embedded binaries can be built +independently using Docker: ```shell make -C embedded-bins