forked from webmeshproj/webmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
110 lines (81 loc) · 3.09 KB
/
Makefile
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
99
100
101
102
103
104
105
106
107
108
109
110
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
PARALLEL ?= $(shell nproc)
build: fmt vet ## Build node, wmctl, and turn binary for the local platform.
$(GORELEASER) build --single-target $(BUILD_ARGS) --id node --id wmctl --id turn --parallelism=$(PARALLEL)
dist: fmt vet ## Build distribution binaries and packages for all platforms.
$(GORELEASER) release --skip-sign $(BUILD_ARGS) --parallelism=$(PARALLEL)
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-turn: docker-build-turn-bin ## Build the turn docker image for the current architecture.
$(DOCKER) build \
-f Dockerfile.turn \
--build-arg PREFIX=turn-docker-linux \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(ARCH) \
-t $(REPO)/turn:latest .
docker-build-bin:
$(GORELEASER) build $(BUILD_ARGS) --id node-docker-linux --single-target
docker-build-turn-bin:
$(GORELEASER) build $(BUILD_ARGS) --id turn-docker-linux --single-target
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
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)