Skip to content

Commit

Permalink
deps: refactor goreleaser - add static builds with libwasmvm (#3157) (#…
Browse files Browse the repository at this point in the history
…3170)

* build: goreleaser cowmsawsm updates

* deps: add ci release make cmd; update workflows and go releaser

* enable workflows

* update Makefile run cmd for goreleaser

(cherry picked from commit 6429012)

Co-authored-by: MSalopek <[email protected]>
  • Loading branch information
mergify[bot] and MSalopek authored Jun 25, 2024
1 parent fea19c9 commit 2b50045
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 17 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- name: Set Env
run: echo "TM_VERSION=$(go list -m github.com/tendermint/tendermint | sed 's:.* ::')" >> $GITHUB_ENV
run: echo "TM_VERSION=$(go list -m github.com/cometbft/cometbft | sed 's:.* ::')" >> $GITHUB_ENV

- name: Release
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean --release-notes ./RELEASE_NOTES.md
run: |
make ci-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cleanup
run: |
sudo rm -rf dist
151 changes: 142 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,154 @@ project_name: gaia

env:
- GO111MODULE=on
- CGO_ENABLED=1

builds:
- main: ./cmd/gaiad
id: "gaiad"
- id: "gaiad-darwin-arm64"
main: ./cmd/gaiad
binary: gaiad
goos:
- darwin
goarch:
- arm64
mod_timestamp: "{{ .CommitTimestamp }}"
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
env:
- CC=oa64-clang
- CGO_LDFLAGS=-L/lib
tags:
- netgo
- ledger
- static_wasm
flags:
- -tags=netgo ledger
- -trimpath
env:
- CGO_ENABLED=0
- -mod=readonly

ldflags:
# .Env.TM_VERSION is provided in the workflow runner environment -> see .github/workflows/release.yml
- -s -w -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 }}
- -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,static_wasm
- -X github.com/cometbft/cometbft/version.TMCoreSemVer={{ .Env.TM_VERSION }}

- id: "gaiad-darwin-amd64"
main: ./cmd/gaiad
binary: gaiad
goos:
- darwin
goarch:
- amd64
mod_timestamp: "{{ .CommitTimestamp }}"
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.COSMWASM_VERSION }}/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
env:
- CC=oa64-clang
- CGO_LDFLAGS=-L/lib
tags:
- netgo
- ledger
- static_wasm
flags:
- -trimpath
- -mod=readonly

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,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 /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.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'
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 /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.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
ids:
- gaiad-darwin-arm64
- gaiad-darwin-amd64
replace: false

archives:
# disables archiving; to enable use commented lines below
- format: binary
name_template: "{{ .Binary }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

# - format: tar.gz
# wrap_in_directory: "true"
# format_overrides:
Expand All @@ -40,6 +162,17 @@ archives:
# - README.md
# rlcp: true

- format: binary
name_template: "{{ .Binary }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
builds:
- gaiad-darwin-arm64
- gaiad-darwin-amd64
- gaiad-linux-amd64
- gaiad-linux-arm64
wrap_in_directory: false
files:
- none*

release:
prerelease: true
name_template: "v{{.Version}}"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG IMG_TAG=latest

# Compile the gaiad binary
FROM golang:1.21-alpine3.18 AS gaiad-builder
FROM golang:1.22-alpine AS gaiad-builder
WORKDIR /src/app/
ENV PACKAGES="curl make git libc-dev bash file gcc linux-headers eudev-dev python3"
RUN apk add --no-cache $PACKAGES
Expand All @@ -18,7 +18,7 @@ COPY go.mod go.sum* ./
RUN go mod download

COPY . .
RUN LEDGER_ENABLED=false LINK_STATICALLY=true BUILD_TAGS=muslc make build
RUN LEDGER_ENABLED=true LINK_STATICALLY=true BUILD_TAGS=muslc make build
RUN echo "Ensuring binary is statically linked ..." \
&& file /src/app/build/gaiad | grep "statically linked"

Expand Down
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,52 @@ else
@echo "--> No tag specified, skipping tag release"
endif

GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GO_VERSION)
COSMWASM_VERSION := $(shell go list -m github.com/CosmWasm/wasmvm | sed 's/.* //')

# 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
goreleaser-build-local:
docker run \
--rm \
-e CGO_ENABLED=1 \
-e TM_VERSION=$(TM_VERSION) \
-e COSMWASM_VERSION=$(COSMWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/gaiad \
-w /go/src/gaiad \
--platform=linux/amd64 \
$(GORELEASER_IMAGE) \
release \
--snapshot \
--skip=publish \
--release-notes ./RELEASE_NOTES.md \
--debug

# uses goreleaser to create static binaries for linux an darwin
# requires access to GITHUB_TOKEN which has to be available in the CI environment
ifdef GITHUB_TOKEN
ci-release:
docker run \
--rm \
-e CGO_ENABLED=1 \
-e GITHUB_TOKEN=$(GITHUB_TOKEN) \
-e TM_VERSION=$(TM_VERSION) \
-e COSMWASM_VERSION=$(COSMWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/gaiad \
-w /go/src/gaiad \
--platform=linux/amd64 \
$(GORELEASER_IMAGE) \
release \
--release-notes ./RELEASE_NOTES.md \
--clean
else
ci-release:
@echo "Error: GITHUB_TOKEN is not defined. Please define it before running 'make release'."
endif

# create tag and publish it
create-release:
ifneq ($(strip $(TAG)),)
Expand Down
1 change: 1 addition & 0 deletions e2e.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN cp "/lib/libwasmvm_muslc.$(uname -m).a" /lib/libwasmvm_muslc.a

COPY go.mod go.sum* ./
RUN go mod download

COPY . .
RUN LEDGER_ENABLED=false LINK_STATICALLY=true BUILD_TAGS=muslc make build
RUN echo "Ensuring binary is statically linked ..." \
Expand Down

0 comments on commit 2b50045

Please sign in to comment.