Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare static binaries for release targets and docker runtimes, and dynamic binaries for local dev #3857

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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)
Expand All @@ -247,6 +246,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 $@
Expand All @@ -261,6 +262,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/%

Expand Down
5 changes: 5 additions & 0 deletions images/orderer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions images/peer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions images/tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down