Skip to content

Commit

Permalink
chore: improve localnet build performance (#2928)
Browse files Browse the repository at this point in the history
* chore: improve localnet build performance

* propagate NODE_VERSION and NODE_COMMIT
  • Loading branch information
gartnera authored Oct 1, 2024
1 parent 2e13c04 commit f9cbcfc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ yarn.lock
.github/
.gitignore
dist/**
.git

# dockerfiles are not needed inside the docker build
Dockerfile
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile-localnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ COPY go.sum .
RUN go mod download
COPY version.sh .
COPY --exclude=*.sh --exclude=*.md --exclude=*.yml . .
ARG NODE_VERSION
ARG NODE_COMMIT

RUN --mount=type=cache,target="/root/.cache/go-build" make install
RUN --mount=type=cache,target="/root/.cache/go-build" make install-zetae2e
RUN --mount=type=cache,target="/root/.cache/go-build" \
NODE_VERSION=${NODE_VERSION} \
NODE_COMMIT=${NODE_COMMIT} \
make install install-zetae2e

FROM ghcr.io/zeta-chain/golang:1.22.5-bookworm AS cosmovisor-build
RUN go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.6.0
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: build

PACKAGE_NAME := github.com/zeta-chain/node
VERSION := $(shell ./version.sh)
COMMIT := $(shell [ -z "${COMMIT_ID}" ] && git log -1 --format='%H' || echo ${COMMIT_ID} )
NODE_VERSION := $(shell ./version.sh)
NODE_COMMIT := $(shell [ -z "${NODE_COMMIT}" ] && git log -1 --format='%H' || echo ${NODE_COMMIT} )
BUILDTIME := $(shell date -u +"%Y%m%d.%H%M%S" )
DOCKER ?= docker
# allow setting of NODE_COMPOSE_ARGS to pass additional args to docker compose
Expand All @@ -17,11 +17,11 @@ GOPATH ?= '$(HOME)/go'
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \
-X github.com/cosmos/cosmos-sdk/version.ServerName=zetacored \
-X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/cosmos/cosmos-sdk/version.Version=$(NODE_VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(NODE_COMMIT) \
-X github.com/zeta-chain/node/pkg/constant.Name=zetacored \
-X github.com/zeta-chain/node/pkg/constant.Version=$(VERSION) \
-X github.com/zeta-chain/node/pkg/constant.CommitHash=$(COMMIT) \
-X github.com/zeta-chain/node/pkg/constant.Version=$(NODE_VERSION) \
-X github.com/zeta-chain/node/pkg/constant.CommitHash=$(NODE_COMMIT) \
-X github.com/zeta-chain/node/pkg/constant.BuildTime=$(BUILDTIME) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb

Expand Down Expand Up @@ -233,7 +233,7 @@ stop-localnet:

zetanode:
@echo "Building zetanode"
$(DOCKER) build -t zetanode --target latest-runtime -f ./Dockerfile-localnet .
$(DOCKER) build -t zetanode --build-arg NODE_VERSION=$(NODE_VERSION) --build-arg NODE_COMMIT=$(NODE_COMMIT) --target latest-runtime -f ./Dockerfile-localnet .
$(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile.fastbuild .
.PHONY: zetanode

Expand Down
21 changes: 14 additions & 7 deletions version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash

# if NODE_VERSION is set, just return it immediately
# this allows you to do docker builds without the git directory
if [[ -n $NODE_VERSION ]]; then
echo $NODE_VERSION
exit
fi

# --exact-match will ensure the tag is only returned if our commit is a tag
version=$(git describe --exact-match --tags 2>/dev/null)
if [[ $? -eq 0 ]]; then
Expand All @@ -9,14 +16,14 @@ if [[ $? -eq 0 ]]; then
exit
fi

# use current timestamp for dirty builds
# develop build and use commit timestamp for version
commit_timestamp=$(git show --no-patch --format=%at)
short_commit=$(git rev-parse --short HEAD)

# append -dirty for dirty builds
if ! git diff --no-ext-diff --quiet --exit-code ; then
current_timestamp=$(date +"%s")
echo "0.0.${current_timestamp}-dirty"
echo "0.0.${commit_timestamp}-${short_commit}-dirty"
exit
fi

# otherwise assume we are on a develop build and use commit timestamp for version
commit_timestamp=$(git show --no-patch --format=%at)

echo "0.0.${commit_timestamp}-develop"
echo "0.0.${commit_timestamp}-${short_commit}"

0 comments on commit f9cbcfc

Please sign in to comment.