Skip to content

Commit

Permalink
CNS-150: dockerize lavad build: better handling of 'release'
Browse files Browse the repository at this point in the history
Propagete LAVA_BUILD_OPTIONS env var and GIT_CLONE build-arg to the docker
build. This ensures that the build in docker indeeds generates the release.

Also allow user to select release version using LAVA_VERSION env variable.

Add examples in the Makefile for how to run.
  • Loading branch information
orenl-lava committed Jan 18, 2023
1 parent a5e1202 commit cdd83f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ ARG TARGETARCH
# (useful to compile a specific version, combined with GIT_VERSION).
ARG GIT_CLONE=false

# set LAVA_BUILD_OPTIONS to control the Makefile behavior (see there).
ARG BUILD_OPTIONS
ENV LAVA_BUILD_OPTIONS=${BUILD_OPTIONS}

# Download go dependencies
WORKDIR /lava
COPY go.mod go.sum ./
Expand All @@ -51,10 +55,10 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# Git clone the sources if requested
# NOTE TODO: after reset of chain (lava-testnet-1) prefix 'v' to ${GIT_VERISON}
# NOTE TODO: after reset of chain (lava-testnet-1) prefix 'v' to ${GIT_VERSION}
RUN if [ "${GIT_CLONE}" = true ]; then \
find . -mindepth 1 -delete && \
git clone --depth 1 --branch ${GIT_VERSION} https://github.com/lavanet/lava . \
git clone --depth 1 --branch v${GIT_VERSION} https://github.com/lavanet/lava . \
; fi

# Remove tag v0.4.0 (same v0.4.0-rc2, which was used in the upgrade proposal
Expand Down
54 changes: 46 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
#
# debug_mutex - (debug) enable debug mutex
# mask_consumer_logs - (debug) enable debug mutex
#
# Examples:
#
# Build locally and run unit tests
# make test build
#
# Build locally a static binary (runs on any distributions and in containers)
# LAVA_BUILD_OPTIONS="static" make build
#
# Build and generate docker image
# LAVA_BUILD_OPTIONS="static" make docker-build
#
# Build release [and optionally generate docker image]
# LAVA_BUILD_OPTIONS="static,release" make build
# LAVA_BUILD_OPTIONS="static,release" make docker-build
#
# Build release of specific version, and generate docker image
# LAVA_VERSION=0.4.3 LAVA_BUILD_OPTIONS="static,release" make docker-build

# do we have .git/ directory?
have_dot_git := $(if $(shell test -d .git && echo true),true,false)
Expand All @@ -43,26 +61,44 @@ else
COMMIT := $(BUILD_COMMIT)
endif

# If we have .git/ directory and 'release' option selected, then we examine
# the currently checked-out code to confirm that it is -
GIT_CLONE := false

# If we have .git/ directory and 'release' option selected, then we consult
# LAVA_VERSION for the desired version; If not set, then we infer the version
# from the currnently checked-out code - and then we examine that it is -
# - clean (no local uncommitted changes, no untracked files)
# - matching in version to the desired tag (no extra commit)
#
# Also, if 'release' option selected, then set GIT_COMMIT=true so that that
# the Dockerfile would clone the repository from scratch.

ifeq (true,$(have_dot_git))
ifeq (release,$(findstring release,$(LAVA_BUILD_OPTIONS)))
version_real := $(shell git describe --tags --exact-match 2> /dev/null || echo "none")
ifneq '$(VERSION)' '$(version_real)'
$(error Current checked-out code does not match requested release version)
endif
ifeq (-dirty,$(findstring -dirty,$(VERSION)))
$(error Current checked-out code has uncommitted changes or untracked files)
ifneq (,$(LAVA_VERSION))
VERSION := v$(LAVA_VERSION)
COMMIT := $(shell git log -1 --format='%H' $(VERSION))
else
version_real := $(shell git describe --tags --exact-match 2> /dev/null || echo "none")
ifneq '$(VERSION)' '$(version_real)'
$(error Current checked-out code does not match requested release version)
endif
ifeq (-dirty,$(findstring -dirty,$(VERSION)))
$(error Current checked-out code has uncommitted changes or untracked files)
endif
endif
GIT_CLONE := true
endif
endif

# strip the leading 'v'
VERSION := $(subst v,,$(VERSION))

ifeq (release,$(findstring release,$(LAVA_BUILD_OPTIONS)))
$(info ----------------------------------------------------------------)
$(info Building for release: VERSION=$(VERSION) COMMIT=$(COMMIT))
$(info ----------------------------------------------------------------)
endif

LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
Expand Down Expand Up @@ -193,6 +229,8 @@ build-docker-helper: $(BUILDDIR)/
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg GIT_CLONE=$(GIT_CLONE) \
--build-arg BUILD_OPTIONS=$(LAVA_BUILD_OPTIONS) \
--build-arg RUNNER_IMAGE=$(RUNNER_IMAGE_DEBIAN) \
--platform linux/$(call autogen_targetarch) \
-t lava:$(VERSION) \
Expand Down

0 comments on commit cdd83f2

Please sign in to comment.