Minor build improvements
Makefile * Make Go build flags parameterizable * Verbose by default * Do not force complete rebuild * Remove unnecessary '-installsuffix' flag https://plus.google.com/117192131596509381660/posts/eNnNePihYnK * Log build steps * Rename 'clean' target to 'clean-container' * Move artifact copy to '.container' target * Add 'clean' target Shell script * Fix shellcheck SC2068 https://github.com/koalaman/shellcheck/wiki/SC2068 * Reject mandatory vars with empty values
This commit is contained in:
parent
82bfcb0337
commit
446641eded
3 changed files with 26 additions and 13 deletions
27
Makefile
27
Makefile
|
@ -48,6 +48,8 @@ ARCH ?= $(shell go env GOARCH)
|
||||||
GOARCH = ${ARCH}
|
GOARCH = ${ARCH}
|
||||||
DUMB_ARCH = ${ARCH}
|
DUMB_ARCH = ${ARCH}
|
||||||
|
|
||||||
|
GOBUILD_FLAGS :=
|
||||||
|
|
||||||
ALL_ARCH = amd64 arm arm64 ppc64le s390x
|
ALL_ARCH = amd64 arm arm64 ppc64le s390x
|
||||||
|
|
||||||
QEMUVERSION = v2.12.0
|
QEMUVERSION = v2.12.0
|
||||||
|
@ -109,10 +111,15 @@ all-container: $(addprefix sub-container-,$(ALL_ARCH))
|
||||||
all-push: $(addprefix sub-push-,$(ALL_ARCH))
|
all-push: $(addprefix sub-push-,$(ALL_ARCH))
|
||||||
|
|
||||||
.PHONY: container
|
.PHONY: container
|
||||||
container: .container-$(ARCH)
|
container: clean-container .container-$(ARCH)
|
||||||
|
|
||||||
.PHONY: .container-$(ARCH)
|
.PHONY: .container-$(ARCH)
|
||||||
.container-$(ARCH):
|
.container-$(ARCH):
|
||||||
|
@echo "+ Copying artifact to temporary directory"
|
||||||
|
mkdir -p $(TEMP_DIR)/rootfs
|
||||||
|
cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller
|
||||||
|
|
||||||
|
@echo "+ Building container image $(MULTI_ARCH_IMG):$(TAG)"
|
||||||
cp -RP ./* $(TEMP_DIR)
|
cp -RP ./* $(TEMP_DIR)
|
||||||
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
|
$(SED_I) "s|BASEIMAGE|$(BASEIMAGE)|g" $(DOCKERFILE)
|
||||||
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)
|
$(SED_I) "s|QEMUARCH|$(QEMUARCH)|g" $(DOCKERFILE)
|
||||||
|
@ -134,6 +141,11 @@ ifeq ($(ARCH), amd64)
|
||||||
$(DOCKER) tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
|
$(DOCKER) tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY: clean-container
|
||||||
|
clean-container:
|
||||||
|
@echo "+ Deleting container image $(MULTI_ARCH_IMG):$(TAG)"
|
||||||
|
$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true
|
||||||
|
|
||||||
.PHONY: register-qemu
|
.PHONY: register-qemu
|
||||||
register-qemu:
|
register-qemu:
|
||||||
# Register /usr/bin/qemu-ARCH-static as the handler for binaries in multiple platforms
|
# Register /usr/bin/qemu-ARCH-static as the handler for binaries in multiple platforms
|
||||||
|
@ -149,17 +161,16 @@ ifeq ($(ARCH), amd64)
|
||||||
$(DOCKER) push $(IMAGE):$(TAG)
|
$(DOCKER) push $(IMAGE):$(TAG)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
$(DOCKER) rmi -f $(MULTI_ARCH_IMG):$(TAG) || true
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: clean
|
build:
|
||||||
|
@echo "+ Building bin/$(ARCH)/nginx-ingress-controller"
|
||||||
@$(DEF_VARS) \
|
@$(DEF_VARS) \
|
||||||
|
GOBUILD_FLAGS="$(GOBUILD_FLAGS)" \
|
||||||
build/go-in-docker.sh build/build.sh
|
build/go-in-docker.sh build/build.sh
|
||||||
|
|
||||||
mkdir -p $(TEMP_DIR)/rootfs
|
.PHONY: clean
|
||||||
cp bin/$(ARCH)/nginx-ingress-controller $(TEMP_DIR)/rootfs/nginx-ingress-controller
|
clean:
|
||||||
|
rm -rf bin/ .gocache/ .env
|
||||||
|
|
||||||
.PHONY: static-check
|
.PHONY: static-check
|
||||||
static-check:
|
static-check:
|
||||||
|
|
|
@ -28,20 +28,21 @@ mandatory=(
|
||||||
)
|
)
|
||||||
|
|
||||||
missing=false
|
missing=false
|
||||||
for var in ${mandatory[@]}; do
|
for var in "${mandatory[@]}"; do
|
||||||
if [[ -z "${!var+x}" ]]; then
|
if [[ -z "${!var:-}" ]]; then
|
||||||
echo "Environment variable $var must be set"
|
echo "Environment variable $var must be set"
|
||||||
missing=true
|
missing=true
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$missing" = true ];then
|
if [ "$missing" = true ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
go build -a -installsuffix cgo \
|
go build \
|
||||||
|
${GOBUILD_FLAGS} \
|
||||||
-ldflags "-s -w \
|
-ldflags "-s -w \
|
||||||
-X ${PKG}/version.RELEASE=${TAG} \
|
-X ${PKG}/version.RELEASE=${TAG} \
|
||||||
-X ${PKG}/version.COMMIT=${GIT_COMMIT} \
|
-X ${PKG}/version.COMMIT=${GIT_COMMIT} \
|
||||||
|
|
|
@ -56,6 +56,7 @@ TAG=${TAG:-"0.0"}
|
||||||
HOME=${HOME:-/root}
|
HOME=${HOME:-/root}
|
||||||
KUBECONFIG=${HOME}/.kube/config
|
KUBECONFIG=${HOME}/.kube/config
|
||||||
GOARCH=${GOARCH}
|
GOARCH=${GOARCH}
|
||||||
|
GOBUILD_FLAGS=${GOBUILD_FLAGS:-"-v"}
|
||||||
PWD=${PWD}
|
PWD=${PWD}
|
||||||
BUSTED_ARGS=${BUSTED_ARGS:-""}
|
BUSTED_ARGS=${BUSTED_ARGS:-""}
|
||||||
REPO_INFO=${REPO_INFO:-local}
|
REPO_INFO=${REPO_INFO:-local}
|
||||||
|
|
Loading…
Reference in a new issue