2018-02-01 18:54:23 +00:00
|
|
|
BRANCH = "master"
|
2018-04-16 08:41:23 +00:00
|
|
|
REPONAME = "neo-go"
|
2018-03-15 20:45:37 +00:00
|
|
|
NETMODE ?= "privnet"
|
2022-06-06 13:54:53 +00:00
|
|
|
BINARY=neo-go
|
|
|
|
BINARY_PATH=./bin/$(BINARY)$(shell go env GOEXE)
|
2024-03-04 14:49:01 +00:00
|
|
|
GO_VERSION ?= 1.20
|
2019-11-07 11:57:02 +00:00
|
|
|
DESTDIR = ""
|
|
|
|
SYSCONFIGDIR = "/etc"
|
|
|
|
BINDIR = "/usr/bin"
|
|
|
|
SYSTEMDUNIT_DIR = "/lib/systemd/system"
|
|
|
|
UNITWORKDIR = "/var/lib/neo-go"
|
2018-02-01 18:54:23 +00:00
|
|
|
|
2022-03-25 13:08:13 +00:00
|
|
|
IMAGE_SUFFIX="$(shell if [ "$(OS)" = Windows_NT ]; then echo "_WindowsServerCore"; fi)"
|
|
|
|
D_FILE ?= "$(shell if [ "$(OS)" = Windows_NT ]; then echo "Dockerfile.wsc"; else echo "Dockerfile"; fi)"
|
|
|
|
DC_FILE ?= ".docker/docker-compose.yml" # Single docker-compose for Ubuntu/WSC, should be kept in sync with ENV_IMAGE_TAG.
|
|
|
|
ENV_IMAGE_TAG="env_neo_go_image"
|
2019-11-15 17:41:40 +00:00
|
|
|
|
2019-08-26 14:26:42 +00:00
|
|
|
REPO ?= "$(shell go list -m)"
|
2022-09-08 19:26:25 +00:00
|
|
|
VERSION ?= "$(shell git describe --tags --match "v*" --abbrev=8 2>/dev/null | sed -r 's,^v([0-9]+\.[0-9]+)\.([0-9]+)(-.*)?$$,\1 \2 \3,' | while read mm patch suffix; do if [ -z "$$suffix" ]; then echo $$mm.$$patch; else patch=`expr $$patch + 1`; echo $$mm.$${patch}-pre$$suffix; fi; done)"
|
2022-01-14 11:18:33 +00:00
|
|
|
MODVERSION ?= "$(shell cat go.mod | cat go.mod | sed -r -n -e 's|.*pkg/interop (.*)|\1|p')"
|
|
|
|
BUILD_FLAGS = "-X '$(REPO)/pkg/config.Version=$(VERSION)' -X '$(REPO)/cli/smartcontract.ModVersion=$(MODVERSION)'"
|
2019-08-26 14:05:17 +00:00
|
|
|
|
2020-01-28 10:03:18 +00:00
|
|
|
IMAGE_REPO=nspccdev/neo-go
|
|
|
|
|
2019-09-09 08:19:57 +00:00
|
|
|
# All of the targets are phony here because we don't really use make dependency
|
|
|
|
# tracking for files
|
2022-07-18 14:35:36 +00:00
|
|
|
.PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest clean-cluster \
|
2022-07-18 16:14:42 +00:00
|
|
|
test vet lint fmt cover version gh-docker-vars
|
2019-09-09 08:19:57 +00:00
|
|
|
|
2019-08-26 14:26:42 +00:00
|
|
|
build: deps
|
|
|
|
@echo "=> Building binary"
|
|
|
|
@set -x \
|
|
|
|
&& export GOGC=off \
|
|
|
|
&& export CGO_ENABLED=0 \
|
2022-06-06 13:54:53 +00:00
|
|
|
&& go build -trimpath -v -ldflags $(BUILD_FLAGS) -o ${BINARY_PATH} ./cli/main.go
|
2018-02-01 18:06:17 +00:00
|
|
|
|
2022-06-06 13:54:53 +00:00
|
|
|
$(BINARY): build
|
2022-06-06 05:09:38 +00:00
|
|
|
|
2022-06-07 12:51:43 +00:00
|
|
|
docker/$(BINARY):
|
|
|
|
@echo "=> Building binary using clean Docker environment"
|
|
|
|
@docker run --rm -t \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-w /src \
|
|
|
|
-u "$$(id -u):$$(id -g)" \
|
|
|
|
--env HOME=/src \
|
|
|
|
golang:$(GO_VERSION) make $(BINARY)
|
|
|
|
|
2019-11-13 12:05:13 +00:00
|
|
|
neo-go.service: neo-go.service.template
|
|
|
|
@sed -r -e 's_BINDIR_$(BINDIR)_' -e 's_UNITWORKDIR_$(UNITWORKDIR)_' -e 's_SYSCONFIGDIR_$(SYSCONFIGDIR)_' $< >$@
|
|
|
|
|
|
|
|
install: build neo-go.service
|
2019-11-06 13:09:07 +00:00
|
|
|
@echo "=> Installing systemd service"
|
2019-11-07 11:57:02 +00:00
|
|
|
@mkdir -p $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
|
|
|
&& mkdir -p $(SYSTEMDUNIT_DIR) \
|
|
|
|
&& cp ./neo-go.service $(SYSTEMDUNIT_DIR) \
|
|
|
|
&& cp ./config/protocol.mainnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
|
|
|
&& cp ./config/protocol.privnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
|
|
|
&& cp ./config/protocol.testnet.yml $(DESTDIR)$(SYSCONFIGDIR)/neo-go \
|
2022-06-06 13:54:53 +00:00
|
|
|
&& install -m 0755 -t $(BINDIR) $(BINARY_PATH) \
|
2019-11-07 11:57:02 +00:00
|
|
|
|
|
|
|
postinst: install
|
|
|
|
@echo "=> Preparing directories and configs"
|
|
|
|
@id neo-go || useradd -s /usr/sbin/nologin -d $(UNITWORKDIR) neo-go \
|
|
|
|
&& mkdir -p $(UNITWORKDIR) \
|
|
|
|
&& chown -R neo-go:neo-go $(UNITWORKDIR) $(BINDIR)/neo-go \
|
|
|
|
&& systemctl enable neo-go.service
|
2019-11-06 13:09:07 +00:00
|
|
|
|
2019-11-15 18:12:37 +00:00
|
|
|
image: deps
|
2022-03-25 13:08:13 +00:00
|
|
|
@echo "=> Building image"
|
|
|
|
@echo " Dockerfile: $(D_FILE)"
|
|
|
|
@echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)"
|
|
|
|
@docker build -f $(D_FILE) -t $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
|
2021-11-19 12:23:51 +00:00
|
|
|
|
2021-02-25 14:32:51 +00:00
|
|
|
image-latest: deps
|
|
|
|
@echo "=> Building image with 'latest' tag"
|
2022-03-25 13:08:13 +00:00
|
|
|
@echo " Dockerfile: Dockerfile" # Always use default Dockerfile for Ubuntu as `latest`.
|
|
|
|
@echo " Tag: $(IMAGE_REPO):latest"
|
2021-02-25 14:32:51 +00:00
|
|
|
@docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
|
|
|
|
|
2020-01-28 10:03:18 +00:00
|
|
|
image-push:
|
2022-03-25 13:08:13 +00:00
|
|
|
@echo "=> Publish image"
|
|
|
|
@echo " Tag: $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)"
|
|
|
|
@docker push $(IMAGE_REPO):$(VERSION)$(IMAGE_SUFFIX)
|
2021-11-25 08:32:44 +00:00
|
|
|
|
2021-02-25 14:32:51 +00:00
|
|
|
image-push-latest:
|
2021-11-25 08:32:44 +00:00
|
|
|
@echo "=> Publish image for Ubuntu with 'latest' tag"
|
2021-02-25 14:32:51 +00:00
|
|
|
@docker push $(IMAGE_REPO):latest
|
|
|
|
|
2018-02-01 18:06:17 +00:00
|
|
|
deps:
|
2021-05-13 14:22:10 +00:00
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod download
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod tidy -v
|
2018-02-01 18:06:17 +00:00
|
|
|
|
2022-07-18 16:14:42 +00:00
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
gh-docker-vars:
|
2022-11-14 09:37:06 +00:00
|
|
|
@echo "file=$(D_FILE)"
|
|
|
|
@echo "version=$(VERSION)"
|
|
|
|
@echo "repo=$(IMAGE_REPO)"
|
|
|
|
@echo "suffix=$(IMAGE_SUFFIX)"
|
2022-07-18 16:14:42 +00:00
|
|
|
|
2018-02-01 17:40:04 +00:00
|
|
|
test:
|
2018-02-24 07:23:02 +00:00
|
|
|
@go test ./... -cover
|
2018-02-01 18:54:23 +00:00
|
|
|
|
|
|
|
vet:
|
2018-03-03 07:16:05 +00:00
|
|
|
@go vet ./...
|
2019-09-09 08:11:49 +00:00
|
|
|
|
|
|
|
lint:
|
2021-05-12 20:25:06 +00:00
|
|
|
@golangci-lint run
|
2019-09-09 08:11:49 +00:00
|
|
|
|
|
|
|
fmt:
|
|
|
|
@gofmt -l -w -s $$(find . -type f -name '*.go'| grep -v "/vendor/")
|
|
|
|
|
|
|
|
cover:
|
2020-04-14 13:05:18 +00:00
|
|
|
@go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./pkg/...,./cli/...
|
2019-09-09 08:11:49 +00:00
|
|
|
@go tool cover -html=coverage.txt -o coverage.html
|
2019-11-15 17:41:40 +00:00
|
|
|
|
2022-03-25 13:08:13 +00:00
|
|
|
# --- Ubuntu/Windows environment ---
|
2021-05-13 14:22:10 +00:00
|
|
|
env_image:
|
2019-11-15 17:41:40 +00:00
|
|
|
@echo "=> Building env image"
|
2022-03-25 13:08:13 +00:00
|
|
|
@echo " Dockerfile: $(D_FILE)"
|
|
|
|
@echo " Tag: $(ENV_IMAGE_TAG)"
|
2019-11-15 17:41:40 +00:00
|
|
|
@docker build \
|
2022-03-25 13:08:13 +00:00
|
|
|
-f $(D_FILE) \
|
|
|
|
-t $(ENV_IMAGE_TAG) \
|
2019-11-15 17:41:40 +00:00
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) .
|
|
|
|
|
|
|
|
env_up:
|
|
|
|
@echo "=> Bootup environment"
|
2022-03-25 13:08:13 +00:00
|
|
|
@echo " Docker-compose file: $(DC_FILE)"
|
2024-08-06 12:46:27 +00:00
|
|
|
@docker compose -f $(DC_FILE) up -d node_one node_two node_three node_four
|
2019-11-15 17:41:40 +00:00
|
|
|
|
2020-01-13 12:22:21 +00:00
|
|
|
env_single:
|
|
|
|
@echo "=> Bootup environment"
|
2024-08-06 12:46:27 +00:00
|
|
|
@docker compose -f $(DC_FILE) up -d node_single
|
2020-01-13 12:22:21 +00:00
|
|
|
|
2019-11-15 17:41:40 +00:00
|
|
|
env_down:
|
2019-11-29 09:48:00 +00:00
|
|
|
@echo "=> Stop environment"
|
2024-08-06 12:46:27 +00:00
|
|
|
@docker compose -f $(DC_FILE) down
|
2019-11-15 17:41:40 +00:00
|
|
|
|
|
|
|
env_restart:
|
2019-11-29 09:48:00 +00:00
|
|
|
@echo "=> Stop and start environment"
|
2024-08-06 12:46:27 +00:00
|
|
|
@docker compose -f $(DC_FILE) restart
|
2019-11-15 17:41:40 +00:00
|
|
|
|
2019-11-29 09:48:00 +00:00
|
|
|
env_clean: env_down
|
|
|
|
@echo "=> Cleanup environment"
|
|
|
|
@docker volume rm docker_volume_chain
|