Files
IT-Nexus/nexus-scanner/Makefile

50 lines
1.3 KiB
Makefile

BINARY := nexus-scanner
CMD := ./cmd/nexus-scanner
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION)"
.PHONY: build run test fmt vet clean install
## build: compile for the local OS/arch
build:
go build $(LDFLAGS) -o $(BINARY) $(CMD)
## build-linux: cross-compile for Linux amd64 + arm64
build-linux:
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY)-linux-amd64 $(CMD)
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY)-linux-arm64 $(CMD)
## run: build and run with the example config (local testing only)
run: build
./$(BINARY) config.example.yaml
## test: run all tests
test:
go test -v -race ./...
## fmt: format all Go source files
fmt:
gofmt -w ./...
## vet: run go vet
vet:
go vet ./...
## tidy: update go.sum and remove unused dependencies
tidy:
go mod tidy
## clean: remove built binaries
clean:
rm -f $(BINARY) $(BINARY)-linux-amd64 $(BINARY)-linux-arm64
## install: deploy to a scanner VM (set SCANNER_HOST env var)
## Usage: SCANNER_HOST=root@192.168.0.x make install
install: build-linux
scp $(BINARY)-linux-amd64 $(SCANNER_HOST):/usr/local/bin/$(BINARY)
ssh $(SCANNER_HOST) "systemctl restart $(BINARY)"
## help: print this help
help:
@grep -E '^## ' Makefile | sed 's/## / /'