From 119306640fc15bed1c15a6696b336e5a7f4a4c16 Mon Sep 17 00:00:00 2001 From: Josh Kneubuhl Date: Wed, 14 Dec 2022 12:33:43 -0500 Subject: [PATCH 1/2] Manually set TARGETARCH and TARGETOS for building with Rancher Desktop. Signed-off-by: Josh Kneubuhl --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 0044830e03d..87219ba0807 100644 --- a/Makefile +++ b/Makefile @@ -251,6 +251,8 @@ $(BUILD_DIR)/images/%/$(DUMMY): --build-arg GO_VER=$(GO_VER) \ --build-arg ALPINE_VER=$(ALPINE_VER) \ --build-arg FABRIC_VER=$(FABRIC_VER) \ + --build-arg TARGETARCH=$(ARCH) \ + --build-arg TARGETOS=linux \ $(BUILD_ARGS) \ -t $(DOCKER_NS)/fabric-$* ./$(BUILD_CONTEXT) @touch $@ From 0587942134621520d9629b0de3913a3a82de718f Mon Sep 17 00:00:00 2001 From: Josh Kneubuhl Date: Wed, 14 Dec 2022 12:48:02 -0500 Subject: [PATCH 2/2] Turn static cgo linking on only for release builds Signed-off-by: Josh Kneubuhl --- Makefile | 4 ++-- images/orderer/Dockerfile | 5 +++++ images/peer/Dockerfile | 5 +++++ images/tools/Dockerfile | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 87219ba0807..a28d8239cea 100644 --- a/Makefile +++ b/Makefile @@ -225,7 +225,6 @@ tools: $(TOOLS_EXES) $(RELEASE_EXES): %: $(BUILD_DIR)/bin/% $(BUILD_DIR)/bin/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%) -$(BUILD_DIR)/bin/%: GO_LDFLAGS += -w -extldflags '-static' $(BUILD_DIR)/bin/%: @echo "Building $@" @mkdir -p $(@D) @@ -267,6 +266,7 @@ release-all: check-go-version $(RELEASE_PLATFORMS:%=release/%) .PHONY: $(RELEASE_PLATFORMS:%=release/%) $(RELEASE_PLATFORMS:%=release/%): GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%) +$(RELEASE_PLATFORMS:%=release/%): GO_LDFLAGS += -w -extldflags '-static' $(RELEASE_PLATFORMS:%=release/%): release/%: $(foreach exe,$(RELEASE_EXES),release/%/bin/$(exe)) $(RELEASE_PLATFORMS:%=release/%): release/%: ccaasbuilder/% @@ -356,7 +356,7 @@ ccaasbuilder-clean/%: .PHONY: ccaasbuilder ccaasbuilder/%: ccaasbuilder-clean - $(eval platform = $(patsubst ccaasbuilder/%,%,$@) ) + $(eval platform = $(patsubst ccaasbuilder/%,%,$@) ) $(eval GOOS = $(word 1,$(subst -, ,$(platform)))) $(eval GOARCH = $(word 2,$(subst -, ,$(platform)))) @mkdir -p release/$(strip $(platform))/builders/ccaas/bin diff --git a/images/orderer/Dockerfile b/images/orderer/Dockerfile index b483f5567ea..549507bcc8e 100644 --- a/images/orderer/Dockerfile +++ b/images/orderer/Dockerfile @@ -27,6 +27,11 @@ FROM golang as orderer ARG GO_TAGS ARG FABRIC_VER ENV FABRIC_VER ${FABRIC_VER} + +# Disable cgo when building in the container. This will create a static binary, which can be +# copied and run in the base alpine container without the libc/musl runtime. +ENV CGO_ENABLED 0 + RUN make orderer GO_TAGS=${GO_TAGS} FROM base diff --git a/images/peer/Dockerfile b/images/peer/Dockerfile index f4f699210ab..a93b6f4ab24 100644 --- a/images/peer/Dockerfile +++ b/images/peer/Dockerfile @@ -26,6 +26,11 @@ FROM golang as peer ARG GO_TAGS ARG FABRIC_VER ENV FABRIC_VER ${FABRIC_VER} + +# Disable cgo when building in the container. This will create a static binary, which can be +# copied and run in the base alpine container without the libc/musl runtime. +ENV CGO_ENABLED 0 + RUN make peer GO_TAGS=${GO_TAGS} RUN make ccaasbuilder diff --git a/images/tools/Dockerfile b/images/tools/Dockerfile index 92e9a14ece5..93518837bdf 100644 --- a/images/tools/Dockerfile +++ b/images/tools/Dockerfile @@ -21,6 +21,11 @@ FROM golang as tools ARG GO_TAGS ARG FABRIC_VER ENV FABRIC_VER ${FABRIC_VER} + +# Disable cgo when building in the container. This will create a static binary, which can be +# copied and run in the base alpine container without the libc/musl runtime. +ENV CGO_ENABLED 0 + RUN make tools GO_TAGS=${GO_TAGS} FROM golang:${GO_VER}-alpine${ALPINE_VER}