From 835352f11e3c15e14a5b37c02fabde3501abf4a5 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Fri, 13 Sep 2024 16:42:11 +0200 Subject: [PATCH] build: add docker static build for v20 (#3331) * build: add docker static build for v20 * update makefile * update goreleaser * update makefile --- .goreleaser.yml | 68 ------------------------------------------------- Makefile | 29 +++++++++++++++------ 2 files changed, 21 insertions(+), 76 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 7b15cf6c36..4012924347 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -76,72 +76,6 @@ builds: - -X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,static_wasm - -X github.com/cometbft/cometbft/version.TMCoreSemVer={{ .Env.TM_VERSION }} - - id: gaiad-linux-amd64 - main: ./cmd/gaiad - binary: gaiad - hooks: - pre: - - wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.x86_64.a -O /lib/libwasmvm_muslc.x86_64.a - goos: - - linux - goarch: - - amd64 - env: - - CC=x86_64-linux-gnu-gcc - flags: - - -mod=readonly - - -trimpath - ldflags: - - -X main.commit={{.Commit}} - - -X main.date={{ .CommitDate }} - - -X github.com/cosmos/cosmos-sdk/version.Name=gaia - - -X github.com/cosmos/cosmos-sdk/version.AppName=gaiad - - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} - - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - - -X github.com/cometbft/cometbft/version.TMCoreSemVer={{ .Env.TM_VERSION }} - - -X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger,muslc,osusergo - - -w -s - - -linkmode=external - - -extldflags '-Wl,-z,muldefs -static -lm' - tags: - - netgo - - ledger - - muslc - - osusergo - - - id: gaiad-linux-arm64 - main: ./cmd/gaiad - binary: gaiad - hooks: - pre: - - wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvm_muslc.aarch64.a -O /lib/libwasmvm_muslc.aarch64.a - goos: - - linux - goarch: - - arm64 - env: - - CC=aarch64-linux-gnu-gcc - flags: - - -mod=readonly - - -trimpath - ldflags: - - -s -w - - -linkmode=external - - -X main.commit={{.Commit}} - - -X main.date={{ .CommitDate }} - - -X github.com/cosmos/cosmos-sdk/version.Name=gaia - - -X github.com/cosmos/cosmos-sdk/version.AppName=gaiad - - -X github.com/cosmos/cosmos-sdk/version.Version=v{{ .Version }} - - -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }} - - -X github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger - - -X github.com/cometbft/cometbft/version.TMCoreSemVer={{ .Env.TM_VERSION }} - - -extldflags '-Wl,-z,muldefs -static -lm' - tags: - - netgo - - ledger - - muslc - - osusergo - universal_binaries: - id: gaiad-darwin-universal @@ -168,8 +102,6 @@ archives: builds: - gaiad-darwin-arm64 - gaiad-darwin-amd64 - - gaiad-linux-amd64 - - gaiad-linux-arm64 wrap_in_directory: false files: - none* diff --git a/Makefile b/Makefile index 2de6d14fc6..e21967e1fc 100644 --- a/Makefile +++ b/Makefile @@ -120,9 +120,6 @@ vulncheck: $(BUILDDIR)/ GOBIN=$(BUILDDIR) go install golang.org/x/vuln/cmd/govulncheck@latest $(BUILDDIR)/govulncheck ./... -build-linux: go.sum - LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build - go.sum: go.mod @echo "--> Ensure dependencies have not been modified" @echo "--> Ensure dependencies have not been modified unless suppressed by SKIP_MOD_VERIFY" @@ -184,9 +181,27 @@ else @echo "--> No tag specified, skipping tag release" endif - -# uses goreleaser to create static binaries for linux an darwin on local machine -# platform is set because not setting it results in broken builds for linux-amd64 +# Build static binaries for linux/amd64 using docker buildx +# Pulled from neutron-org/neutron: https://github.com/neutron-org/neutron/blob/v4.2.2/Makefile#L107 +build-static-linux-amd64: go.sum $(BUILDDIR)/ + $(DOCKER) buildx create --name gaiabuilder || true + $(DOCKER) buildx use gaiabuilder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --build-arg BUILD_TAGS=$(build_tags_comma_sep),muslc \ + --platform linux/amd64 \ + -t gaiad-static-amd64 \ + -f Dockerfile . \ + --load + $(DOCKER) rm -f gaiabinary || true + $(DOCKER) create -ti --name gaiabinary gaiad-static-amd64 + $(DOCKER) cp gaiabinary:/usr/local/bin/ $(BUILDDIR)/gaiad-linux-amd64 + $(DOCKER) rm -f gaiabinary + + +# uses goreleaser to create static binaries for darwin on local machine goreleaser-build-local: docker run \ --rm \ @@ -195,7 +210,6 @@ goreleaser-build-local: -e COSMWASM_VERSION=$(COSMWASM_VERSION) \ -v `pwd`:/go/src/gaiad \ -w /go/src/gaiad \ - --platform=linux/amd64 \ $(GORELEASER_IMAGE) \ release \ --snapshot \ @@ -216,7 +230,6 @@ ci-release: -e COSMWASM_VERSION=$(COSMWASM_VERSION) \ -v `pwd`:/go/src/gaiad \ -w /go/src/gaiad \ - --platform=linux/amd64 \ $(GORELEASER_IMAGE) \ release \ --release-notes ./RELEASE_NOTES.md \