forked from webmeshproj/webmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (71 loc) · 2.61 KB
/
Makefile
File metadata and controls
98 lines (71 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
NAME ?= node
CTL ?= wmctl
REPO ?= ghcr.io/webmeshproj
IMAGE ?= $(REPO)/$(NAME):latest
DISTROLESS_IMAGE ?= $(REPO)/$(NAME)-distroless:latest
GO ?= go
ARCH ?= $(shell $(GO) env GOARCH)
OS ?= $(shell $(GO) env GOOS)
ifeq ($(OS),Windows_NT)
OS := windows
endif
default: build
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
GORELEASER ?= $(GO) run github.com/goreleaser/goreleaser@latest
BUILD_ARGS ?= --snapshot --clean
build: fmt vet ## Build node and wmctl binary for the local platform.
$(GORELEASER) build --single-target $(BUILD_ARGS) --id node --id wmctl
dist: fmt vet ## Build distribution binaries and packages for all platforms.
$(GORELEASER) release --skip-sign $(BUILD_ARGS)
DOCKER ?= docker
docker-build: docker-build-bin ## Build the node docker image for the current architecture.
$(DOCKER) build \
-f Dockerfile \
--build-arg PREFIX=node-docker-linux \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(ARCH) \
-t $(IMAGE) .
docker-build-distroless: docker-build-bin ## Build the distroless node docker image for the current architecture.
$(DOCKER) build \
-f Dockerfile.distroless \
--build-arg PREFIX=node-docker-linux \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(ARCH) \
-t $(DISTROLESS_IMAGE) .
docker-build-bin:
$(GORELEASER) build $(BUILD_ARGS) --id node-docker-linux
docker-push: docker-build ## Push the node docker image
$(DOCKER) push $(IMAGE)
docker-push-distroless: docker-build-distroless ## Push the distroless node docker image
$(DOCKER) push $(DISTROLESS_IMAGE)
##@ Testing
COVERAGE_FILE := coverage.out
TEST_ARGS := -v -cover -coverprofile=$(COVERAGE_FILE) -covermode=atomic -race
test: fmt vet ## Run unit tests.
$(GO) test $(TEST_ARGS) ./...
$(GO) tool cover -func=$(COVERAGE_FILE)
lint: ## Run linters.
$(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run --timeout=5m
.PHONY: fmt
fmt: ## Run go fmt against code.
ifeq ($(OS),windows)
echo "Skipping go fmt on windows"
else
$(GO) fmt ./...
endif
.PHONY: vet
vet: ## Run go vet against code.
$(GO) vet ./...
##@ Misc
generate: ## Run go generate against code.
$(GO) generate ./...
clean: ## Clean up build and development artifacts.
rm -rf dist/ $(COVERAGE_FILE)
build-ctl:
$(GORELEASER) build --single-target $(BUILD_ARGS) --id $(CTL) -o dist/$(CTL)
install-ctl: build-ctl
install -m 755 dist/$(CTL) $(shell go env GOPATH)/bin/$(CTL)