diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a7a5d6f..f7e4a8d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: - name: Build go project run: | - make build + make build-go build-docker: runs-on: ubuntu-22.04 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5d4bf0aa..e4417090 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,7 +84,7 @@ jobs: - name: Install AXONE blockchain run: | - make build && make install + make build-go && make install - name: Initialize blockchain run: | diff --git a/Dockerfile b/Dockerfile index 00989b4a..1a05a563 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN set -eux \ COPY . /src/ -RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build +RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build-go #--- Image stage FROM alpine:3.20.3 diff --git a/Makefile b/Makefile index 0dee2737..7cf3933a 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,15 @@ DOCKER_IMAGE_MARKDOWNLINT = thegeeklab/markdownlint-cli:0.32.2 DOCKER_IMAGE_GOTEMPLATE = hairyhenderson/gomplate:v3.11.3-alpine # Tools -TOOL_TPARSE_NAME := tparse -TOOL_TPARSE_VERSION := v0.16.0 -TOOL_TPARSE_PKG := github.com/mfridman/$(TOOL_TPARSE_NAME)@$(TOOL_TPARSE_VERSION) -TOOL_TPARSE_BIN := ${TOOLS_FOLDER}/$(TOOL_TPARSE_NAME)/$(TOOL_TPARSE_VERSION)/$(TOOL_TPARSE_NAME) +TOOL_TPARSE_NAME := tparse +TOOL_TPARSE_VERSION := v0.16.0 +TOOL_TPARSE_PKG := github.com/mfridman/$(TOOL_TPARSE_NAME)@$(TOOL_TPARSE_VERSION) +TOOL_TPARSE_BIN := ${TOOLS_FOLDER}/$(TOOL_TPARSE_NAME)/$(TOOL_TPARSE_VERSION)/$(TOOL_TPARSE_NAME) + +TOOL_HEIGHLINER_NAME := heighliner +TOOL_HEIGHLINER_VERSION := v1.7.1 +TOOL_HEIGHLINER_PKG := github.com/strangelove-ventures/$(TOOL_HEIGHLINER_NAME)@$(TOOL_HEIGHLINER_VERSION) +TOOL_HEIGHLINER_BIN := ${TOOLS_FOLDER}/$(TOOL_HEIGHLINER_NAME)/$(TOOL_HEIGHLINER_VERSION)/$(TOOL_HEIGHLINER_NAME) # Some colors (if supported) define get_color @@ -168,7 +173,7 @@ format-proto: ## Format proto files ## Build: .PHONY: build -build: build-go ## Build all available artefacts (executable, docker image, etc.) +build: build-go build-docker ## Build all available artefacts (executable, docker image, etc.) .PHONY: build-go build-go: ## Build node executable for the current environment (default build) @@ -177,6 +182,11 @@ build-go: ## Build node executable for the current environment (default build) build-go-all: $(ENVIRONMENTS_TARGETS) ## Build node executables for all available environments +.PHONY: build-docker +build-docker: $(TOOL_HEIGHLINER_BIN) ## Build docker image + @echo "${COLOR_CYAN} 🐳 Building local ${COLOR_RESET}docker${COLOR_CYAN} image${COLOR_RESET}" + @$(TOOL_HEIGHLINER_BIN) build -c axone --local + $(ENVIRONMENTS_TARGETS): @GOOS=$(word 3, $(subst -, ,$@)); \ GOARCH=$(word 4, $(subst -, ,$@)); \ @@ -213,7 +223,7 @@ test-go: $(TOOL_TPARSE_BIN) build ## Pass the test for the go source code @go test -v -coverprofile ./target/coverage.txt ./... -json | $(TOOL_TPARSE_BIN) ## Chain: -chain-init: build ## Initialize the blockchain with default settings. +chain-init: build-go ## Initialize the blockchain with default settings. @echo "${COLOR_CYAN} 🛠️ Initializing chain ${COLOR_RESET}${CHAIN}${COLOR_CYAN} under ${COLOR_YELLOW}${CHAIN_HOME}${COLOR_RESET}" @rm -rf "${CHAIN_HOME}"; \ @@ -245,7 +255,7 @@ chain-init: build ## Initialize the blockchain with default settings. ${CHAIN_BINARY} genesis collect-gentxs \ --home "${CHAIN_HOME}" -chain-start: build ## Start the blockchain with existing configuration (see chain-init) +chain-start: build-go ## Start the blockchain with existing configuration (see chain-init) @echo "${COLOR_CYAN} 🛠️ Starting chain ${COLOR_RESET}${CHAIN}${COLOR_CYAN} with configuration ${COLOR_YELLOW}${CHAIN_HOME}${COLOR_RESET}"; \ ${CHAIN_BINARY} start --moniker ${CHAIN_MONIKER} \ --home ${CHAIN_HOME} @@ -254,14 +264,14 @@ chain-stop: ## Stop the blockchain @echo "${COLOR_CYAN} ✋️ Stopping chain ${COLOR_RESET}${CHAIN}${COLOR_CYAN} with configuration ${COLOR_YELLOW}${CHAIN_HOME}${COLOR_RESET}" @killall axoned -chain-upgrade: build ## Test the chain upgrade from the given FROM_VERSION to the given TO_VERSION. +chain-upgrade: build-go ## Test the chain upgrade from the given FROM_VERSION to the given TO_VERSION. @echo "${COLOR_CYAN} ⬆️ Upgrade the chain ${COLOR_RESET}${CHAIN}${COLOR_CYAN} from ${COLOR_YELLOW}${FROM_VERSION}${COLOR_RESET}${COLOR_CYAN} to ${COLOR_YELLOW}${TO_VERSION}${COLOR_RESET}" @killall cosmovisor || \ rm -rf ${TARGET_FOLDER}/${FROM_VERSION}; \ git clone -b ${FROM_VERSION} https://github.com/axone-protocol/axoned.git ${TARGET_FOLDER}/${FROM_VERSION}; \ echo "${COLOR_CYAN} 🏗 Build the ${COLOR_YELLOW}${FROM_VERSION}${COLOR_RESET}${COLOR_CYAN} binary...${COLOR_RESET}"; \ cd ${TARGET_FOLDER}/${FROM_VERSION}; \ - make build; \ + make build-go; \ BINARY_OLD=${TARGET_FOLDER}/${FROM_VERSION}/${DIST_FOLDER}/${DAEMON_NAME}; \ cd ../../; \ echo $$BINARY_OLD; \ @@ -429,16 +439,33 @@ ensure-buildx-builder: ## Dependencies: .PHONY: deps -deps: deps-$(TOOL_TPARSE_NAME) ## Install all the dependencies (tools, etc.) +deps: deps-$(TOOL_TPARSE_NAME) deps-$(TOOL_HEIGHLINER_NAME) ## Install all the dependencies (tools, etc.) .PHONY: deps-$(TOOL_TPARSE_NAME) deps-tparse: $(TOOL_TPARSE_BIN) ## Install $TOOL_TPARSE_NAME $TOOL_TPARSE_VERSION ($TOOL_TPARSE_PKG) +.PHONY: deps-$(TOOL_HEIGHLINER_NAME) +deps-heighliner: $(TOOL_HEIGHLINER_BIN) ## Install $TOOL_HEIGHLINER_NAME $TOOL_HEIGHLINER_VERSION ($TOOL_HEIGHLINER_PKG) + $(TOOL_TPARSE_BIN): @echo "${COLOR_CYAN} 📦 Installing ${COLOR_GREEN}$(TOOL_TPARSE_NAME)@$(TOOL_TPARSE_VERSION)${COLOR_CYAN}...${COLOR_RESET}" @mkdir -p $(dir $(TOOL_TPARSE_BIN)) @GOBIN=$(dir $(abspath $(TOOL_TPARSE_BIN))) go install $(TOOL_TPARSE_PKG) +$(TOOL_HEIGHLINER_BIN): + @echo "${COLOR_CYAN} 📦 Installing ${COLOR_GREEN}$(TOOL_HEIGHLINER_NAME)@$(TOOL_HEIGHLINER_VERSION)${COLOR_CYAN}...${COLOR_RESET}" + @mkdir -p $(dir $(TOOL_HEIGHLINER_BIN)) + CUR_DIR=$(shell pwd) && \ + TEMP_DIR=$(shell mktemp -d) && \ + GIT_URL=https://$(firstword $(subst @, ,$(TOOL_HEIGHLINER_PKG))).git && \ + GIT_TAG=$(word 2,$(subst @, ,$(TOOL_HEIGHLINER_PKG))) && \ + git clone --branch $$GIT_TAG --depth 1 $$GIT_URL $$TEMP_DIR && \ + cd $$TEMP_DIR && \ + make build && \ + cd $$CUR_DIR && \ + mv $$TEMP_DIR/heighliner $(TOOL_HEIGHLINER_BIN) && \ + rm -rf $$TEMP_DIR + ## Help: .PHONY: help help: ## Show this help. diff --git a/README.md b/README.md index 7d8d6855..8a218cfc 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ Targets: build Build all available artefacts (executable, docker image, etc.) build-go Build node executable for the current environment (default build) build-go-all Build node executables for all available environments + build-docker Build docker image Install: install Install node executable Test: @@ -137,6 +138,7 @@ Targets: Dependencies: deps Install all the dependencies (tools, etc.) deps-tparse Install tparse v0.16.0 (github.com/mfridman/tparse@v0.16.0) + deps-heighliner Install heighliner v1.7.1 (github.com/strangelove-ventures/heighliner@v1.7.1) Help: help Show this help. @@ -148,14 +150,23 @@ This Makefile depends on docker. To install it, please follow the instructions: ### Build -To build the `axoned` node, invoke the goal `build` of the `Makefile`: +To build the `axoned` node, invoke the goal `build-go` of the `Makefile`: ```sh -make build +make build-go ``` The binary will be generated under the folder `target/dist`. +### Build a docker image + +This project leverages [heighliner](https://github.com/strangelove-ventures/heighliner) to simplify the management and +creation of production-grade container images. To build a Docker image, use the `build-docker` target in the `Makefile`: + +```sh +make build-docker +``` + ### Run a local network To initialize a local network configuration, invoke the goal `chain-init` of the `Makefile`: