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

Add support for wormchain and update the docker files to better support a custom build dir #134

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions chains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,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
Expand Down
4 changes: 3 additions & 1 deletion dockerfile/cosmos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ RUN set -eux;\
export CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++;\
fi;\
fi;\
if [ ! -z "$BUILD_TARGET" ]; then\
if [ ! -z "$BUILD_DIR" ]; then cd "${BUILD_DIR}"; fi;\
fi;\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance this would be backwards breaking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't. If a build directory is defined, then we need to enter it to use the go list to find a wasm version in the next step. The current and only cosmos repo (gravitybridge) with a build dir set, does not use wasm so it wasn't an issue.

WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}');\
if [ ! -z "${WASM_VERSION}" ]; then\
wget -O $LIBDIR/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${WASM_VERSION}/libwasmvm_muslc.$ARCH.a;\
Expand All @@ -57,7 +60,6 @@ RUN set -eux;\
if [ ! -z "$BUILD_TARGET" ]; then\
if [ ! -z "$BUILD_ENV" ]; then export ${BUILD_ENV}; fi;\
if [ ! -z "$BUILD_TAGS" ]; then export "${BUILD_TAGS}"; fi;\
if [ ! -z "$BUILD_DIR" ]; then cd "${BUILD_DIR}"; fi;\
sh -c "${BUILD_TARGET}";\
fi

Expand Down
9 changes: 7 additions & 2 deletions dockerfile/cosmos/local.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ ARG BUILDARCH
ARG GITHUB_ORGANIZATION
ARG REPO_HOST
ARG GITHUB_REPO
ARG BUILD_DIR
ARG BUILD_TARGET

WORKDIR /go/src/${REPO_HOST}/${GITHUB_ORGANIZATION}/${GITHUB_REPO}

ADD . .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the ADD up here removes all of the caching optimizations that were done for local builds in #107 . Is there a reason it's necessary?

Copy link
Contributor Author

@misko9 misko9 Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optimization did not account for a build dir. When a build dir is defined, we would need to pull the go.mod and go.sum from that build directory for the wasmvm search, not from the root. If other modules from that repo are also used, i.e. wormchain's sdk module, the go list will also fail which is a second reason the ADD was moved up. Perhaps we need a new way to find the wasmvm version to keep the optimization? As it stands, the build will fail when using build dir with a chain that supports wasmvm and/or other modules in that repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we just move up the ARG BUILD_DIR so that it is available when adding the go.mod and go.sum, and then ADD ${BUILD_DIR}/go.mod ${BUILD_DIR}/go.sum ./ ?

Alternatively, what if we move the wasm version detection into the heighliner go code and add ARG WASM_VERSION to the dockerfiles? Heighliner already parses the go.mod to determine the go version. That would probably help caching the most so that libwasm wouldn't need to be re-downloaded when changing the go.mod, only when the wasm version changed.


# Download dependencies and CosmWasm libwasmvm if found.
ADD go.mod go.sum ./
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this and L22 removed? We should be able to cache deps still, but it could be done as a phase after the libwasmvm download since that no longer depends on the go.mod being present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling those files does not work when there is a custom build directory

RUN set -eux; \
if [ ! -z "$BUILD_TARGET" ]; then \
if [ ! -z "$BUILD_DIR" ]; then cd "${BUILD_DIR}"; fi; \
fi; \
export ARCH=$(uname -m); \
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}'); \
if [ ! -z "${WASM_VERSION}" ]; then \
Expand Down Expand Up @@ -103,7 +109,6 @@ ARG BUILD_DIR

# This Dockerfile is the same as native.Dockerfile except that the chain code is sourced from the
# current working directory instead of a remote git repository.
ADD . .

RUN set -eux; \
export CGO_ENABLED=1 LDFLAGS='-linkmode external -extldflags "-static"'; \
Expand Down
6 changes: 3 additions & 3 deletions dockerfile/cosmos/native.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,6 +26,9 @@ ARG BUILD_DIR

RUN set -eux;\
export ARCH=$(uname -m);\
if [ ! -z "$BUILD_TARGET" ]; then\
if [ ! -z "$BUILD_DIR" ]; then cd "${BUILD_DIR}"; fi;\
fi;\
WASM_VERSION=$(go list -m all | grep github.com/CosmWasm/wasmvm | awk '{print $2}');\
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;\
Expand All @@ -37,7 +38,6 @@ RUN set -eux;\
if [ ! -z "$BUILD_TARGET" ]; then\
if [ ! -z "$BUILD_ENV" ]; then export ${BUILD_ENV}; fi;\
if [ ! -z "$BUILD_TAGS" ]; then export "${BUILD_TAGS}"; fi;\
if [ ! -z "$BUILD_DIR" ]; then cd "${BUILD_DIR}"; fi;\
sh -c "${BUILD_TARGET}";\
fi

Expand Down