diff --git a/builder/builder.go b/builder/builder.go index 5551971..b9c2a85 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -146,14 +146,22 @@ func rawDockerfile( } // baseImageForGoVersion will determine the go version in go.mod and return the base image -func baseImageForGoVersion( +func baseImageForGoVersion(modFile *modfile.File) GoVersion { + goVersion := modFile.Go.Version + baseImageVersion := GetImageAndVersionForGoVersion(goVersion) + fmt.Printf("Go version from go.mod: %s, will build with version: %s image: %s\n", goVersion, baseImageVersion.Version, baseImageVersion.Image) + + return baseImageVersion +} + +func getModFile( repoHost string, organization string, repoName string, ref string, buildDir string, local bool, -) (GoVersion, error) { +) (*modfile.File, error) { var goModBz []byte var err error @@ -165,7 +173,7 @@ func baseImageForGoVersion( if local { goModBz, err = os.ReadFile(goModPath) if err != nil { - return GoVersion{}, fmt.Errorf("failed to read %s for local build: %w", goModPath, err) + return nil, fmt.Errorf("failed to read %s for local build: %w", goModPath, err) } } else { // single branch depth 1 clone to only fetch most recent state of files @@ -187,33 +195,57 @@ func baseImageForGoVersion( _, err := git.Clone(memory.NewStorage(), fs, cloneOpts) if err != nil { - return GoVersion{}, fmt.Errorf("failed to clone go.mod file to determine go version: %w", err) + return nil, fmt.Errorf("failed to clone go.mod file to determine go version: %w", err) } } goModFile, err := fs.Open(goModPath) if err != nil { - return GoVersion{}, fmt.Errorf("failed to open go.mod file: %w", err) + return nil, fmt.Errorf("failed to open go.mod file: %w", err) } goModBz, err = io.ReadAll(goModFile) if err != nil { - return GoVersion{}, fmt.Errorf("failed to read go.mod file: %w", err) + return nil, fmt.Errorf("failed to read go.mod file: %w", err) } } goMod, err := modfile.Parse("go.mod", goModBz, nil) if err != nil { - return GoVersion{}, fmt.Errorf("failed to parse go.mod file: %w", err) + return nil, fmt.Errorf("failed to parse go.mod file: %w", err) } - goVersion := goMod.Go.Version - baseImageVersion := GetImageAndVersionForGoVersion(goVersion) - fmt.Printf("Go version from go.mod: %s, will build with version: %s image: %s\n", goVersion, baseImageVersion.Version, baseImageVersion.Image) + return goMod, nil +} + - return baseImageVersion, nil +// getWasmvmVersion will get the wasmvm version from the mod file +func getWasmvmVersion(modFile *modfile.File) string { + wasmvmRepo := "github.com/CosmWasm/wasmvm" + wasmvmVersion := "" + + // First check all the "requires" + for _, item := range modFile.Require { + // Must have 2 tokens, repo & version + if (len(item.Syntax.Token) == 2) && (strings.Contains(item.Syntax.Token[0], wasmvmRepo)) { + wasmvmVersion = item.Syntax.Token[1] + } + } + + // Then, check all the "replaces" + for _, item := range modFile.Replace { + // Must have 3 or more tokens + if (len(item.Syntax.Token) > 2) && (strings.Contains(item.Syntax.Token[0], wasmvmRepo)) { + wasmvmVersion = item.Syntax.Token[len(item.Syntax.Token)-1] + } + } + + fmt.Println("WasmVM version from go.mod: ", wasmvmVersion) + + return wasmvmVersion } + // buildChainNodeDockerImage builds the requested chain node docker image // based on the input configuration. func (h *HeighlinerBuilder) buildChainNodeDockerImage( @@ -319,10 +351,16 @@ func (h *HeighlinerBuilder) buildChainNodeDockerImage( var baseVersion string - baseVer, err := baseImageForGoVersion( + modFile, err := getModFile( repoHost, chainConfig.Build.GithubOrganization, chainConfig.Build.GithubRepo, chainConfig.Ref, chainConfig.Build.BuildDir, h.local, ) + if err != nil { + return fmt.Errorf("error getting mod file: %w", err) + } + + baseVer := baseImageForGoVersion(modFile) + wasmvmVersion := getWasmvmVersion(modFile) race := "" @@ -347,6 +385,11 @@ func (h *HeighlinerBuilder) buildChainNodeDockerImage( fmt.Printf("Building image from %s, resulting docker image tags: +%v\n", buildFrom, imageTags) + // If build dir is empty, add a "." for dockerfile compatibility + if chainConfig.Build.BuildDir == "" { + chainConfig.Build.BuildDir = "." + } + buildArgs := map[string]string{ "VERSION": chainConfig.Ref, "BASE_VERSION": baseVersion, @@ -367,6 +410,7 @@ func (h *HeighlinerBuilder) buildChainNodeDockerImage( "BUILD_DIR": chainConfig.Build.BuildDir, "BUILD_TIMESTAMP": buildTimestamp, "GO_VERSION": baseVer.Version, + "WASMVM_VERSION": wasmvmVersion, "RACE": race, } diff --git a/chains.yaml b/chains.yaml index 6bbdc21..1703109 100644 --- a/chains.yaml +++ b/chains.yaml @@ -1030,6 +1030,19 @@ build-env: - BUILD_TAGS=muslc +# Wormchain (Wormhole Gateway) +- name: wormchain + github-organization: wormhole-foundation + github-repo: wormhole + dockerfile: cosmos + build-target: | + BUILD_TAGS=netgo,muslc + LD_FLAGS="-s -w -X github.com/cosmos/cosmos-sdk/version.Name=wormchain -X github.com/cosmos/cosmos-sdk/version.Version=$(echo $(git describe --tags) | sed 's/^v//') -X github.com/cosmos/cosmos-sdk/version.Commit=$(git log -1 --format='%H') -X github.com/cosmos/cosmos-sdk/version.BuildTags=\"${BUILD_TAGS}\" -X github.com/cosmos/cosmos-sdk/version.ServerName=wormchaind" + go build -mod=readonly -tags="${BUILD_TAGS}" -ldflags="$LDFLAGS ${LD_FLAGS}" -o build/wormchaind cmd/wormchaind/main.go + build-dir: wormchain + binaries: + - wormchain/build/wormchaind + # Xion - name: xion github-organization: burnt-labs diff --git a/dockerfile/cosmos/Dockerfile b/dockerfile/cosmos/Dockerfile index 271a302..1f0ec78 100644 --- a/dockerfile/cosmos/Dockerfile +++ b/dockerfile/cosmos/Dockerfile @@ -30,6 +30,7 @@ ARG BUILD_ENV ARG BUILD_TAGS ARG PRE_BUILD ARG BUILD_DIR +ARG WASMVM_VERSION RUN set -eux;\ LIBDIR=/lib;\ @@ -48,9 +49,8 @@ RUN set -eux;\ export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++;\ fi;\ fi;\ - WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $NF}');\ - if [ ! -z "${WASM_VERSION}" ]; then\ - wget -O $LIBDIR/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.$ARCH.a;\ + if [ ! -z "${WASMVM_VERSION}" ]; then\ + wget -O $LIBDIR/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}/libwasmvm_muslc.$ARCH.a;\ fi;\ export GOOS=linux GOARCH=$TARGETARCH CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"';\ if [ ! -z "$PRE_BUILD" ]; then sh -c "${PRE_BUILD}"; fi;\ diff --git a/dockerfile/cosmos/local.Dockerfile b/dockerfile/cosmos/local.Dockerfile index a953f43..71a887a 100644 --- a/dockerfile/cosmos/local.Dockerfile +++ b/dockerfile/cosmos/local.Dockerfile @@ -8,18 +8,27 @@ ARG BUILDARCH ARG GITHUB_ORGANIZATION ARG REPO_HOST ARG GITHUB_REPO +ARG WASMVM_VERSION WORKDIR /go/src/${REPO_HOST}/${GITHUB_ORGANIZATION}/${GITHUB_REPO} -# Download dependencies and CosmWasm libwasmvm if found. -ADD go.mod go.sum ./ +# Download CosmWasm libwasmvm if found RUN set -eux; \ export ARCH=$(uname -m); \ - WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $NF}'); \ - if [ ! -z "${WASM_VERSION}" ]; then \ - wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.$(uname -m).a; \ - fi; \ - go mod download; + if [ ! -z "${WASMVM_VERSION}" ]; then \ + wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}/libwasmvm_muslc.$(uname -m).a; \ + fi; + +ARG BUILD_DIR + +ADD ${BUILD_DIR}/go.mod ${BUILD_DIR}/go.sum ./ + +# Download go mod dependencies, if there is no custom build directory +# Note: a custom build dir indicates a monorepo with potential dependencies we can't anticipate atm +RUN set -eux; \ + if [[ "${BUILD_DIR}" == "." ]]; then \ + go mod download; \ + fi; # Use minimal busybox from infra-toolkit image for final scratch image FROM ghcr.io/strangelove-ventures/infra-toolkit:v0.0.7 AS infra-toolkit diff --git a/dockerfile/cosmos/native.Dockerfile b/dockerfile/cosmos/native.Dockerfile index 751ccad..8aeb768 100644 --- a/dockerfile/cosmos/native.Dockerfile +++ b/dockerfile/cosmos/native.Dockerfile @@ -5,8 +5,6 @@ RUN apk add --update --no-cache curl make git libc-dev bash gcc linux-headers eu ARG TARGETARCH ARG BUILDARCH - - ARG GITHUB_ORGANIZATION ARG REPO_HOST @@ -25,12 +23,12 @@ ARG BUILD_ENV ARG BUILD_TAGS ARG PRE_BUILD ARG BUILD_DIR +ARG WASMVM_VERSION RUN set -eux;\ export ARCH=$(uname -m);\ - WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $NF}');\ - if [ ! -z "${WASM_VERSION}" ]; then\ - wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.$(uname -m).a;\ + if [ ! -z "${WASMVM_VERSION}" ]; then\ + wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}/libwasmvm_muslc.$(uname -m).a;\ fi;\ export CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"';\ if [ ! -z "$PRE_BUILD" ]; then sh -c "${PRE_BUILD}"; fi;\