Merge pull request #566 from thockin/v4_makefile_dbg
v4: Bring some Makefile cleanups from k/k
This commit is contained in:
commit
42d292d081
117
Makefile
117
Makefile
|
|
@ -24,6 +24,10 @@ VERSION ?= $(shell git describe --tags --always --dirty)
|
||||||
# This version-strategy uses a manual value to set the version string
|
# This version-strategy uses a manual value to set the version string
|
||||||
#VERSION ?= 1.2.3
|
#VERSION ?= 1.2.3
|
||||||
|
|
||||||
|
# These are passed to docker when building and testing.
|
||||||
|
HTTP_PROXY ?=
|
||||||
|
HTTPS_PROXY ?=
|
||||||
|
|
||||||
###
|
###
|
||||||
### These variables should not need tweaking.
|
### These variables should not need tweaking.
|
||||||
###
|
###
|
||||||
|
|
@ -43,6 +47,21 @@ TAG := $(VERSION)__$(OS)_$(ARCH)
|
||||||
|
|
||||||
BUILD_IMAGE ?= golang:1.18-alpine
|
BUILD_IMAGE ?= golang:1.18-alpine
|
||||||
|
|
||||||
|
DBG_MAKEFILE ?=
|
||||||
|
ifneq ($(DBG_MAKEFILE),1)
|
||||||
|
# If we're not debugging the Makefile, don't echo recipes.
|
||||||
|
MAKEFLAGS += -s
|
||||||
|
endif
|
||||||
|
|
||||||
|
# It's necessary to set this because some environments don't link sh -> bash.
|
||||||
|
SHELL := /usr/bin/env bash -o errexit -o pipefail -o nounset
|
||||||
|
|
||||||
|
# We don't need make's built-in rules.
|
||||||
|
MAKEFLAGS += --no-builtin-rules
|
||||||
|
# Be pedantic about undefined variables.
|
||||||
|
MAKEFLAGS += --warn-undefined-variables
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
# If you want to build all binaries, see the 'all-build' rule.
|
# If you want to build all binaries, see the 'all-build' rule.
|
||||||
# If you want to build all containers, see the 'all-container' rule.
|
# If you want to build all containers, see the 'all-container' rule.
|
||||||
# If you want to build AND push all containers, see the 'all-push' rule.
|
# If you want to build AND push all containers, see the 'all-push' rule.
|
||||||
|
|
@ -52,19 +71,19 @@ all: build
|
||||||
# because make pattern rules don't match with embedded '/' characters.
|
# because make pattern rules don't match with embedded '/' characters.
|
||||||
|
|
||||||
build-%:
|
build-%:
|
||||||
@$(MAKE) build \
|
$(MAKE) build \
|
||||||
--no-print-directory \
|
--no-print-directory \
|
||||||
GOOS=$(firstword $(subst _, ,$*)) \
|
GOOS=$(firstword $(subst _, ,$*)) \
|
||||||
GOARCH=$(lastword $(subst _, ,$*))
|
GOARCH=$(lastword $(subst _, ,$*))
|
||||||
|
|
||||||
container-%:
|
container-%:
|
||||||
@$(MAKE) container \
|
$(MAKE) container \
|
||||||
--no-print-directory \
|
--no-print-directory \
|
||||||
GOOS=$(firstword $(subst _, ,$*)) \
|
GOOS=$(firstword $(subst _, ,$*)) \
|
||||||
GOARCH=$(lastword $(subst _, ,$*))
|
GOARCH=$(lastword $(subst _, ,$*))
|
||||||
|
|
||||||
push-%:
|
push-%:
|
||||||
@$(MAKE) push \
|
$(MAKE) push \
|
||||||
--no-print-directory \
|
--no-print-directory \
|
||||||
GOOS=$(firstword $(subst _, ,$*)) \
|
GOOS=$(firstword $(subst _, ,$*)) \
|
||||||
GOARCH=$(lastword $(subst _, ,$*))
|
GOARCH=$(lastword $(subst _, ,$*))
|
||||||
|
|
@ -88,13 +107,13 @@ BUILD_DIRS := \
|
||||||
# will not trigger further work if nothing has actually changed.
|
# will not trigger further work if nothing has actually changed.
|
||||||
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
|
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
|
||||||
$(OUTBIN): .go/$(OUTBIN).stamp
|
$(OUTBIN): .go/$(OUTBIN).stamp
|
||||||
@true
|
true
|
||||||
|
|
||||||
# This will build the binary under ./.go and update the real binary iff needed.
|
# This will build the binary under ./.go and update the real binary iff needed.
|
||||||
.PHONY: .go/$(OUTBIN).stamp
|
.PHONY: .go/$(OUTBIN).stamp
|
||||||
.go/$(OUTBIN).stamp: $(BUILD_DIRS)
|
.go/$(OUTBIN).stamp: $(BUILD_DIRS)
|
||||||
@echo "making $(OUTBIN)"
|
echo "making $(OUTBIN)"
|
||||||
@docker run \
|
docker run \
|
||||||
-i \
|
-i \
|
||||||
--rm \
|
--rm \
|
||||||
-u $$(id -u):$$(id -g) \
|
-u $$(id -u):$$(id -g) \
|
||||||
|
|
@ -112,7 +131,7 @@ $(OUTBIN): .go/$(OUTBIN).stamp
|
||||||
VERSION=$(VERSION) \
|
VERSION=$(VERSION) \
|
||||||
./build/build.sh \
|
./build/build.sh \
|
||||||
"
|
"
|
||||||
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
|
if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
|
||||||
mv .go/$(OUTBIN) $(OUTBIN); \
|
mv .go/$(OUTBIN) $(OUTBIN); \
|
||||||
date >$@; \
|
date >$@; \
|
||||||
fi
|
fi
|
||||||
|
|
@ -123,56 +142,56 @@ DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
|
||||||
LICENSES = .licenses
|
LICENSES = .licenses
|
||||||
|
|
||||||
$(LICENSES):
|
$(LICENSES):
|
||||||
@GOOS=$(shell go env GOHOSTOS) \
|
GOOS=$(shell go env GOHOSTOS) \
|
||||||
GOARCH=$(shell go env GOHOSTARCH) \
|
GOARCH=$(shell go env GOHOSTARCH) \
|
||||||
go build -o ./bin/tools github.com/google/go-licenses
|
go build -o ./bin/tools github.com/google/go-licenses
|
||||||
@rm -rf $(LICENSES)
|
rm -rf $(LICENSES)
|
||||||
@./bin/tools/go-licenses save ./... --save_path=$(LICENSES)
|
./bin/tools/go-licenses save ./... --save_path=$(LICENSES)
|
||||||
@chmod -R a+rx $(LICENSES)
|
chmod -R a+rx $(LICENSES)
|
||||||
|
|
||||||
# Set this to any value to skip repeating the apt-get steps. Caution.
|
# Set this to any value to skip repeating the apt-get steps. Caution.
|
||||||
ALLOW_STALE_APT ?=
|
ALLOW_STALE_APT ?=
|
||||||
|
|
||||||
container: .container-$(DOTFILE_IMAGE) container-name
|
container: .container-$(DOTFILE_IMAGE) container-name
|
||||||
.container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) $(LICENSES) Dockerfile.in
|
.container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) $(LICENSES) Dockerfile.in
|
||||||
@sed \
|
sed \
|
||||||
-e 's|{ARG_BIN}|$(BIN)|g' \
|
-e 's|{ARG_BIN}|$(BIN)|g' \
|
||||||
-e 's|{ARG_ARCH}|$(ARCH)|g' \
|
-e 's|{ARG_ARCH}|$(ARCH)|g' \
|
||||||
-e 's|{ARG_OS}|$(OS)|g' \
|
-e 's|{ARG_OS}|$(OS)|g' \
|
||||||
-e 's|{ARG_FROM}|$(BASEIMAGE)|g' \
|
-e 's|{ARG_FROM}|$(BASEIMAGE)|g' \
|
||||||
Dockerfile.in > .dockerfile-$(OS)_$(ARCH)
|
Dockerfile.in > .dockerfile-$(OS)_$(ARCH)
|
||||||
@HASH_LICENSES=$$(find $(LICENSES) -type f \
|
HASH_LICENSES=$$(find $(LICENSES) -type f \
|
||||||
| xargs md5sum | md5sum | cut -f1 -d' '); \
|
| xargs md5sum | md5sum | cut -f1 -d' '); \
|
||||||
HASH_BINARY=$$(md5sum bin/$(OS)_$(ARCH)/$(BIN) \
|
HASH_BINARY=$$(md5sum bin/$(OS)_$(ARCH)/$(BIN) \
|
||||||
| cut -f1 -d' '); \
|
| cut -f1 -d' '); \
|
||||||
FORCE=0; \
|
FORCE=0; \
|
||||||
if [ -z "$(ALLOW_STALE_APT)" ]; then FORCE=$$(date +%s); fi; \
|
if [ -z "$(ALLOW_STALE_APT)" ]; then FORCE=$$(date +%s); fi; \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg FORCE_REBUILD="$$FORCE" \
|
--build-arg FORCE_REBUILD="$$FORCE" \
|
||||||
--build-arg HASH_LICENSES="$$HASH_LICENSES" \
|
--build-arg HASH_LICENSES="$$HASH_LICENSES" \
|
||||||
--build-arg HASH_BINARY="$$HASH_BINARY" \
|
--build-arg HASH_BINARY="$$HASH_BINARY" \
|
||||||
--progress=plain \
|
--progress=plain \
|
||||||
--load \
|
--load \
|
||||||
--platform "$(OS)/$(ARCH)" \
|
--platform "$(OS)/$(ARCH)" \
|
||||||
--build-arg HTTP_PROXY=$(HTTP_PROXY) \
|
--build-arg HTTP_PROXY=$(HTTP_PROXY) \
|
||||||
--build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
|
--build-arg HTTPS_PROXY=$(HTTPS_PROXY) \
|
||||||
-t $(IMAGE):$(TAG) \
|
-t $(IMAGE):$(TAG) \
|
||||||
-f .dockerfile-$(OS)_$(ARCH) \
|
-f .dockerfile-$(OS)_$(ARCH) \
|
||||||
.
|
.
|
||||||
@docker images -q $(IMAGE):$(TAG) > $@
|
docker images -q $(IMAGE):$(TAG) > $@
|
||||||
|
|
||||||
container-name:
|
container-name:
|
||||||
@echo "container: $(IMAGE):$(TAG)"
|
echo "container: $(IMAGE):$(TAG)"
|
||||||
@echo
|
echo
|
||||||
|
|
||||||
push: .push-$(DOTFILE_IMAGE) push-name
|
push: .push-$(DOTFILE_IMAGE) push-name
|
||||||
.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE)
|
.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE)
|
||||||
@docker push $(IMAGE):$(TAG)
|
docker push $(IMAGE):$(TAG)
|
||||||
@docker images -q $(IMAGE):$(TAG) > $@
|
docker images -q $(IMAGE):$(TAG) > $@
|
||||||
|
|
||||||
push-name:
|
push-name:
|
||||||
@echo "pushed: $(IMAGE):$(TAG)"
|
echo "pushed: $(IMAGE):$(TAG)"
|
||||||
@echo
|
echo
|
||||||
|
|
||||||
# This depends on github.com/estesp/manifest-tool in $PATH.
|
# This depends on github.com/estesp/manifest-tool in $PATH.
|
||||||
manifest-list: all-push
|
manifest-list: all-push
|
||||||
|
|
@ -186,10 +205,10 @@ manifest-list: all-push
|
||||||
--target $(REGISTRY)/$(BIN):$(VERSION)
|
--target $(REGISTRY)/$(BIN):$(VERSION)
|
||||||
|
|
||||||
version:
|
version:
|
||||||
@echo $(VERSION)
|
echo $(VERSION)
|
||||||
|
|
||||||
test: $(BUILD_DIRS)
|
test: $(BUILD_DIRS)
|
||||||
@docker run \
|
docker run \
|
||||||
-i \
|
-i \
|
||||||
-u $$(id -u):$$(id -g) \
|
-u $$(id -u):$$(id -g) \
|
||||||
-v $$(pwd):/src \
|
-v $$(pwd):/src \
|
||||||
|
|
@ -203,30 +222,30 @@ test: $(BUILD_DIRS)
|
||||||
/bin/sh -c " \
|
/bin/sh -c " \
|
||||||
./build/test.sh $(SRC_DIRS) \
|
./build/test.sh $(SRC_DIRS) \
|
||||||
"
|
"
|
||||||
@./test_e2e.sh
|
./test_e2e.sh
|
||||||
|
|
||||||
TEST_TOOLS := $(shell ls _test_tools)
|
TEST_TOOLS := $(shell ls _test_tools)
|
||||||
test-tools: $(foreach tool, $(TEST_TOOLS), .container-test_tool.$(tool))
|
test-tools: $(foreach tool, $(TEST_TOOLS), .container-test_tool.$(tool))
|
||||||
|
|
||||||
.container-test_tool.%: _test_tools/% _test_tools/%/*
|
.container-test_tool.%: _test_tools/% _test_tools/%/*
|
||||||
@docker build -t $(REGISTRY)/test/$$(basename $<) $<
|
docker build -t $(REGISTRY)/test/$$(basename $<) $<
|
||||||
@docker images -q $(REGISTRY)/test/$$(basename $<) > $@
|
docker images -q $(REGISTRY)/test/$$(basename $<) > $@
|
||||||
|
|
||||||
# Help set up multi-arch build tools. This assumes you have the tools
|
# Help set up multi-arch build tools. This assumes you have the tools
|
||||||
# installed. If you already have a buildx builder available, you don't need
|
# installed. If you already have a buildx builder available, you don't need
|
||||||
# this. See https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408
|
# this. See https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408
|
||||||
# for great context.
|
# for great context.
|
||||||
multiarch-build-tools: .qemu-initialized
|
multiarch-build-tools: .qemu-initialized
|
||||||
@docker buildx create --name git-sync --node git-sync-0
|
docker buildx create --name git-sync --node git-sync-0
|
||||||
@docker buildx use git-sync
|
docker buildx use git-sync
|
||||||
@docker buildx inspect --bootstrap
|
docker buildx inspect --bootstrap
|
||||||
|
|
||||||
.qemu-initialized:
|
.qemu-initialized:
|
||||||
@docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||||
@date > $@
|
date > $@
|
||||||
|
|
||||||
$(BUILD_DIRS):
|
$(BUILD_DIRS):
|
||||||
@mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
clean: container-clean bin-clean
|
clean: container-clean bin-clean
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue