neo-go/Makefile

134 lines
3.8 KiB
Makefile
Raw Normal View History

2018-02-01 18:54:23 +00:00
BRANCH = "master"
REPONAME = "neo-go"
NETMODE ?= "privnet"
BINARY=./bin/neo-go$(shell go env GOEXE)
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
DC_FILE=.docker/docker-compose.yml
GOOS ?= $(shell go env GOOS)
REPO ?= "$(shell go list -m)"
VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')$(shell if [ "$(GOOS)" = "windows" ]; then echo "_unsupported"; fi)"
BUILD_FLAGS = "-X '$(REPO)/pkg/config.Version=$(VERSION)'"
IMAGE_REPO=nspccdev/neo-go
# All of the targets are phony here because we don't really use make dependency
# tracking for files
.PHONY: build deps image image-wsc image-latest image-push image-wsc-push image-push-latest check-version clean-cluster push-tag \
2021-03-19 08:20:08 +00:00
test vet lint fmt cover
build: deps
@echo "=> Building binary"
@set -x \
&& export GOGC=off \
&& export CGO_ENABLED=0 \
&& go build -trimpath -v -ldflags $(BUILD_FLAGS) -o ${BINARY} ./cli/main.go
2018-02-01 18:06:17 +00:00
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
@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 \
&& install -m 0755 -t $(BINDIR) $(BINARY) \
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
image: deps
2021-11-19 12:23:51 +00:00
@echo "=> Building image for Ubuntu"
@docker build -t $(IMAGE_REPO):$(VERSION) --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
2021-11-19 12:23:51 +00:00
image-wsc: deps
@echo "=> Building image for Windows Server Core"
@docker build -f Dockerfile.wsc -t $(IMAGE_REPO):$(VERSION)_WindowsServerCore --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
image-latest: deps
@echo "=> Building image with 'latest' tag"
@docker build -t $(IMAGE_REPO):latest --build-arg REPO=$(REPO) --build-arg VERSION=$(VERSION) .
image-push:
@echo "=> Publish image for Ubuntu"
@docker push $(IMAGE_REPO):$(VERSION)
image-wsc-push:
@echo "=> Publish image for Windows Server Core"
@docker push $(IMAGE_REPO):$(VERSION)_WindowsServerCore
image-push-latest:
@echo "=> Publish image for Ubuntu with 'latest' tag"
@docker push $(IMAGE_REPO):latest
2018-02-01 18:54:23 +00:00
check-version:
git fetch && (! git rev-list ${VERSION})
2018-02-01 18:06:17 +00:00
deps:
@CGO_ENABLED=0 \
go mod download
@CGO_ENABLED=0 \
go mod tidy -v
2018-02-01 18:06:17 +00:00
2018-02-01 18:54:23 +00:00
push-tag:
git checkout ${BRANCH}
git pull origin ${BRANCH}
git tag ${VERSION}
git push origin ${VERSION}
2018-02-01 18:54:23 +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:
@go vet ./...
lint:
@golangci-lint run
fmt:
@gofmt -l -w -s $$(find . -type f -name '*.go'| grep -v "/vendor/")
cover:
@go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./pkg/...,./cli/...
@go tool cover -html=coverage.txt -o coverage.html
# --- Environment ---
env_image:
@echo "=> Building env image"
@docker build \
-t env_neo_go_image \
--build-arg REPO=$(REPO) \
--build-arg VERSION=$(VERSION) .
env_up:
@echo "=> Bootup environment"
2019-11-25 13:33:00 +00:00
@docker-compose -f $(DC_FILE) up -d node_one node_two node_three node_four
env_single:
@echo "=> Bootup environment"
@docker-compose -f $(DC_FILE) up -d node_single
env_down:
@echo "=> Stop environment"
@docker-compose -f $(DC_FILE) down
env_restart:
@echo "=> Stop and start environment"
@docker-compose -f $(DC_FILE) restart
env_clean: env_down
@echo "=> Cleanup environment"
@docker volume rm docker_volume_chain