From f1cdd2222b2035109ae40e788134aa83f630215a Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 26 Aug 2019 16:58:24 +0300 Subject: [PATCH 1/3] Update Readme - add go minimal version - fix dependency manager --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45643f911..e8db4c4db 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,11 @@ A complete toolkit for the NEO blockchain, including: ## Installation +Go: 1.11+ + Install dependencies. -`neo-go` uses [dep](https://github.com/golang/dep) as its dependency manager. After installing `deps` you can run: +`neo-go` uses [GoModules](https://github.com/golang/go/wiki/Modules) as dependency manager: ``` make deps From 902125cbeb94fe6d8b1014fbd4fe73cf8cb08c2d Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 26 Aug 2019 17:05:17 +0300 Subject: [PATCH 2/3] Change the way to receive version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Used git to receive version from tags (see #304) - Version now displayed when start node (fix #102) Example: → ./bin/node --version neo-go version 0.44.10-245-g67d5e9f → ./bin/node -v neo-go version 0.44.10-245-g67d5e9f --- Makefile | 3 ++- cli/main.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae2710240..bbd31495c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ BRANCH = "master" BUILD_TIME = "$(shell date -u +\"%Y-%m-%dT%H:%M:%SZ\")" -VERSION = $(shell cat ./VERSION) REPONAME = "neo-go" NETMODE ?= "privnet" +VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')" + build: @echo "=> Building darwin binary" @go build -i -ldflags "-X github.com/CityOfZion/neo-go/config.Version=${VERSION}-dev -X github.com/CityOfZion/neo-go/config.BuildTime=${BUILD_TIME}" -o ./bin/neo-go ./cli/main.go diff --git a/cli/main.go b/cli/main.go index 7e98ae169..e58aaf157 100644 --- a/cli/main.go +++ b/cli/main.go @@ -7,12 +7,14 @@ import ( "github.com/CityOfZion/neo-go/cli/smartcontract" "github.com/CityOfZion/neo-go/cli/vm" "github.com/CityOfZion/neo-go/cli/wallet" + "github.com/CityOfZion/neo-go/config" "github.com/urfave/cli" ) func main() { ctl := cli.NewApp() ctl.Name = "neo-go" + ctl.Version = config.Version ctl.Usage = "Official Go client for Neo" ctl.Commands = []cli.Command{ From 9a79c004175904c36fbfeea5def4ca3f7f5c7053 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 26 Aug 2019 17:26:42 +0300 Subject: [PATCH 3/3] Fix build node and docker-image - Make Dockerfile useful and minimal - Update Makefile commands build / image - Docker should not ignore vendor (go build -mod=vendor) --- .dockerignore | 1 - Dockerfile | 42 +++++++++++++++++++++++++++++++++--------- Makefile | 25 +++++++++++++++---------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/.dockerignore b/.dockerignore index 8f94841fb..6ebc43372 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ -vendor .git chains diff --git a/Dockerfile b/Dockerfile index 160a732e0..c8114db1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,40 @@ -FROM vidsyhq/go-base:latest -LABEL maintainers="anthdm,stevenjack" +# Builder image +FROM golang:1.12-alpine3.10 as builder -ENV NETMODE=testnet +RUN set -x \ + && apk add --no-cache git \ + && mkdir -p /tmp -ARG VERSION +COPY . /neo-go + +WORKDIR /neo-go + +ARG REPO=repository +ARG VERSION=dev + +# https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away +# go build -mod=vendor +RUN set -x \ + && export BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ + && export GOGC=off \ + && export CGO_ENABLED=0 \ + && export LDFLAGS="-X ${REPO}/config.Version=${VERSION} -X ${REPO}/config.BuildTime=${BUILD_TIME}" \ + && go build -v -mod=vendor -ldflags "${LDFLAGS}" -o /go/bin/node ./cli/main.go + +# Executable image +FROM alpine:3.10 + +ENV NETMODE=testnet +ARG VERSION LABEL version=$VERSION -ADD bin/neo-go /usr/bin/neo-go -ADD config /config +WORKDIR / -RUN chmod u+x /usr/bin/neo-go -RUN mkdir -p /chains +ENV NETMODE=testnet +COPY --from=builder /neo-go/config /config +COPY --from=builder /go/bin/node /usr/bin/node +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ + +ENTRYPOINT ["/usr/bin/node"] -ENTRYPOINT ["neo-go"] CMD ["node", "--config-path", "./config", "--testnet"] diff --git a/Makefile b/Makefile index bbd31495c..02d05f42a 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,22 @@ BUILD_TIME = "$(shell date -u +\"%Y-%m-%dT%H:%M:%SZ\")" REPONAME = "neo-go" NETMODE ?= "privnet" +REPO ?= "$(shell go list -m)" VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')" +BUILD_FLAGS = "-X $(REPO)/config.Version=$(VERSION) -X $(REPO)/config.BuildTime=$(BUILD_TIME)" -build: - @echo "=> Building darwin binary" - @go build -i -ldflags "-X github.com/CityOfZion/neo-go/config.Version=${VERSION}-dev -X github.com/CityOfZion/neo-go/config.BuildTime=${BUILD_TIME}" -o ./bin/neo-go ./cli/main.go +build: deps + @echo "=> Building binary" + @set -x \ + && export GOGC=off \ + && export CGO_ENABLED=0 \ + && echo $(VERSION)-$(BUILD_TIME) \ + && go build -v -mod=vendor -ldflags $(BUILD_FLAGS) -o ./bin/node ./cli/main.go -build-image: - docker build -t cityofzion/neo-go --build-arg VERSION=${VERSION} . - -build-linux: - @echo "=> Building linux binary" - @GOOS=linux go build -i -ldflags "-X github.com/CityOfZion/neo-go/config.Version=${VERSION}-dev -X github.com/CityOfZion/neo-go/config.BuildTime=${BUILD_TIME}" -o ./bin/neo-go ./cli/main.go +image: deps + @echo "=> Building image" + @docker build -t cityofzion/neo-go:latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . + @docker build -t cityofzion/neo-go:$(VERSION) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) . check-version: git fetch && (! git rev-list ${VERSION}) @@ -26,7 +30,8 @@ clean-cluster: @docker-compose rm -f deps: - @dep ensure + @go mod tidy -v + @go mod vendor push-tag: git checkout ${BRANCH}