2024-05-03 17:11:56 +00:00
|
|
|
BINARY_NAME = xmr-nodes
|
|
|
|
|
2024-07-03 20:45:37 +00:00
|
|
|
# These build are modified version of rclone's Makefile
|
|
|
|
# https://github.com/rclone/rclone/blob/master/Makefile
|
|
|
|
VERSION := $(shell cat VERSION)
|
|
|
|
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
# Last tag on this branch (eg. v1.0.0)
|
|
|
|
LAST_TAG := $(shell git describe --tags --abbrev=0)
|
|
|
|
# Tag of the current commit, if any. If this is not "" then we are building a release
|
|
|
|
RELEASE_TAG := $(shell git tag -l --points-at HEAD)
|
|
|
|
# If we are working on a release, override branch to main
|
|
|
|
ifdef RELEASE_TAG
|
|
|
|
BRANCH := main
|
|
|
|
LAST_TAG := $(shell git describe --abbrev=0 --tags $(VERSION)^)
|
|
|
|
endif
|
|
|
|
# Make version suffix -beta.NNNN.CCCCCCCC (N=Commit number, C=Commit)
|
|
|
|
VERSION_SUFFIX := -beta.$(shell git rev-list --count HEAD).$(shell git show --no-patch --no-notes --pretty='%h' HEAD)
|
|
|
|
TAG_BRANCH := .$(BRANCH)
|
|
|
|
# If building HEAD or master then unset TAG_BRANCH
|
2024-07-03 21:10:46 +00:00
|
|
|
ifeq ($(subst HEAD,,$(subst main,,$(BRANCH))),)
|
2024-07-03 20:45:37 +00:00
|
|
|
TAG_BRANCH :=
|
|
|
|
endif
|
|
|
|
# TAG is current version + commit number + commit + branch
|
|
|
|
TAG := $(VERSION)$(VERSION_SUFFIX)$(TAG_BRANCH)
|
|
|
|
ifdef RELEASE_TAG
|
|
|
|
TAG := $(RELEASE_TAG)
|
|
|
|
endif
|
|
|
|
# end modified rclone's Makefile
|
|
|
|
|
2024-07-06 18:28:44 +00:00
|
|
|
BUILD_LDFLAGS := -s -w -X github.com/ditatompel/xmr-remote-nodes/internal/config.Version=$(TAG)
|
2024-07-03 20:45:37 +00:00
|
|
|
|
|
|
|
# This called from air cmd (see .air.toml)
|
|
|
|
.PHONY: dev
|
2024-10-29 13:41:22 +00:00
|
|
|
dev: templ tailwind
|
2024-07-03 20:45:37 +00:00
|
|
|
go build -ldflags="$(BUILD_LDFLAGS)" -tags server -o ./tmp/main .
|
|
|
|
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: build
|
2024-05-18 11:05:53 +00:00
|
|
|
build: client server
|
2024-05-03 17:11:56 +00:00
|
|
|
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: client
|
2024-05-18 11:05:53 +00:00
|
|
|
client:
|
2024-07-03 20:45:37 +00:00
|
|
|
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build \
|
|
|
|
-ldflags="$(BUILD_LDFLAGS)" \
|
|
|
|
-o bin/${BINARY_NAME}-client-linux-amd64
|
|
|
|
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build \
|
|
|
|
-ldflags="$(BUILD_LDFLAGS)" \
|
|
|
|
-o bin/${BINARY_NAME}-client-linux-arm64
|
2024-05-03 17:11:56 +00:00
|
|
|
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: server
|
2024-10-29 13:41:22 +00:00
|
|
|
server: prepare templ tailwind
|
2024-07-03 20:45:37 +00:00
|
|
|
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build \
|
|
|
|
-ldflags="$(BUILD_LDFLAGS)" -tags server \
|
|
|
|
-o bin/${BINARY_NAME}-server-linux-amd64
|
|
|
|
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build \
|
|
|
|
-ldflags="$(BUILD_LDFLAGS)" -tags server \
|
|
|
|
-o bin/${BINARY_NAME}-server-linux-arm64
|
2024-05-06 12:55:41 +00:00
|
|
|
|
2024-10-29 13:41:22 +00:00
|
|
|
.PHONY: prepare
|
|
|
|
prepare:
|
|
|
|
bun install --frozen-lockfile
|
|
|
|
@mkdir -p ./internal/handler/views/assets/js
|
|
|
|
cp ./node_modules/htmx.org/dist/htmx.min.js ./internal/handler/views/assets/js
|
2024-10-31 11:09:02 +00:00
|
|
|
cp ./node_modules/clipboard/dist/clipboard.min.js ./internal/handler/views/assets/js
|
2024-10-29 13:41:22 +00:00
|
|
|
|
|
|
|
# Compile template
|
|
|
|
.PHONY: templ
|
|
|
|
templ:
|
|
|
|
@echo "Compiling Templ template..."
|
|
|
|
templ generate
|
|
|
|
|
|
|
|
.PHONY: tailwind
|
|
|
|
tailwind:
|
|
|
|
mkdir -p ./internal/handler/views/assets/css
|
|
|
|
@echo "Compiling TailwindCSS..."
|
|
|
|
bun tailwindcss -i ./internal/handler/views/src/css/main.css \
|
|
|
|
-o ./internal/handler/views/assets/css/main.min.css \
|
|
|
|
-c ./tailwind.config.js \
|
|
|
|
--minify
|
2024-10-30 07:23:45 +00:00
|
|
|
bun build ./internal/handler/views/src/js/main.js --minify \
|
|
|
|
--outfile ./internal/handler/views/assets/js/main.min.js
|
2024-10-29 13:41:22 +00:00
|
|
|
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: clean
|
2024-05-03 17:11:56 +00:00
|
|
|
clean:
|
|
|
|
go clean
|
|
|
|
rm -rfv ./bin
|
2024-10-29 13:41:22 +00:00
|
|
|
rm -rfv ./tmp/main
|
|
|
|
rm -rf ./internal/handler/views/*_templ.go
|
|
|
|
rm -rf ./internal/handler/views/assets/css/
|
2024-05-06 15:21:46 +00:00
|
|
|
|
2024-07-06 17:51:54 +00:00
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
|
|
|
golangci-lint run ./...
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
go test -race -cover ./...
|
|
|
|
|
|
|
|
.PHONY: bench
|
|
|
|
bench:
|
|
|
|
go test ./... -bench=. -benchmem -run=^#
|
|
|
|
|
2024-05-06 15:21:46 +00:00
|
|
|
# Deploying new binary file to server and probers host
|
|
|
|
# The deploy-* command doesn't build the binary file, so you need to run `make build` first.
|
|
|
|
# And make sure the inventory and deploy-*.yml file is properly configured.
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: deploy-server
|
2024-05-06 15:21:46 +00:00
|
|
|
deploy-server:
|
2024-10-29 13:41:22 +00:00
|
|
|
ansible-playbook -i ./deployment/ansible/inventory.ini \
|
|
|
|
-l server ./deployment/ansible/deploy-server.yml -K
|
2024-05-06 15:21:46 +00:00
|
|
|
|
2024-05-30 05:02:11 +00:00
|
|
|
.PHONY: deploy-prober
|
2024-05-06 15:21:46 +00:00
|
|
|
deploy-prober:
|
2024-10-29 13:41:22 +00:00
|
|
|
ansible-playbook -i ./deployment/ansible/inventory.ini \
|
|
|
|
-l prober ./deployment/ansible/deploy-prober.yml -K
|