Skip to content

Commit

Permalink
improve: adding commit hash export as env var in docker and printing …
Browse files Browse the repository at this point in the history
…it along with the version on start in main.go

Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Oct 25, 2022
1 parent 7172709 commit 6e778b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ RUN cd /src && make build

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0
ARG BUILD_COMMIT
ENV COMMIT_HASH $BUILD_COMMIT
COPY --from=build /src/dist/zkevm-node /app/zkevm-node
COPY --from=build /src/config/environments/local/local.node.config.toml /app/example.config.toml
EXPOSE 8123
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ GOBIN := $(GOBASE)/dist
GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=amd64
GOBINARY := zkevm-node
GOCMD := $(GOBASE)/cmd
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))

.PHONY: build
build: ## Builds the binary locally into ./dist
$(GOENVVARS) go build $(LDFLAGS) -o $(GOBIN)/$(GOBINARY) $(GOCMD)

.PHONY: build-docker
build-docker: ## Builds a docker image with the node binary
docker build -t zkevm-node -f ./Dockerfile .
docker build -t zkevm-node --build-arg BUILD_COMMIT="$(BUILD_COMMIT)" -f ./Dockerfile .

.PHONY: build-docker-nc
build-docker-nc: ## Builds a docker image with the node binary - but without build cache
docker build --no-cache=true -t zkevm-node -f ./Dockerfile .
docker build --no-cache=true -t zkevm-node --build-arg BUILD_COMMIT="$(BUILD_COMMIT)" -f ./Dockerfile .

.PHONY: run-rpc
run-rpc: ## Runs all the services need to run a local zkEMV RPC node
Expand Down
11 changes: 9 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/test/testutils"
"github.com/urfave/cli/v2"
)

Expand All @@ -15,8 +16,6 @@ const (
appName = "zkevm-node"
// version represents the program based on the git tag
version = "v0.1.0"
// commit represents the program based on the git commit
commit = "dev"
// date represents the date of application was built
date = ""
)
Expand All @@ -34,7 +33,14 @@ const (
BROADCAST = "broadcast-trusted-state"
)

const (
//envCommitHash environment variable name for COMMIT_HASH
envCommitHash = "COMMIT_HASH"
)

var (
// commit represents the program based on the git commit
commit = testutils.GetEnv(envCommitHash, "dev")
configFileFlag = cli.StringFlag{
Name: config.FlagCfg,
Aliases: []string{"c"},
Expand Down Expand Up @@ -79,6 +85,7 @@ func main() {
&componentsFlag,
&httpAPIFlag,
}
log.Infof("Starting application [Commit Hash: %s, Version: %s] ...", commit, version)
app.Commands = []*cli.Command{
{
Name: "version",
Expand Down

0 comments on commit 6e778b5

Please sign in to comment.