This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
76 lines (58 loc) · 1.72 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
NAME := noderig
BUILD_DIR := build
GITHASH := $(shell git rev-parse HEAD)
CC := GO111MODULE=on go build
CROSS := GOOS=linux GOARCH=amd64
DFLAGS := -race
CFLAGS := -i -v -mod vendor
LDFLAGS := -X github.com/ovh/noderig/cmd.githash=$(GITHASH)
rwildcard := $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
FORMAT_PATHS := ./cmd ./core ./collectors $(NAME).go
MODULE_PATHS := ./cmd/... ./core/... ./collectors/...
FILE_PATHS := $(call rwildcard, cmd, *.go) $(call rwildcard, core, *.go) $(NAME).go
.PHONY: all
all: init dep format lint release
.PHONY: init
init:
GO111MODULE=on go get -u -v github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: dep
dep:
GO111MODULE=on go mod vendor -v
.PHONY: fmt
format: $(FILE_PATHS)
gofmt -s -w $(FORMAT_PATHS)
.PHONY: lint
lint: $(FILE_PATHS)
golangci-lint run
.PHONY: build
build: $(FILE_PATHS)
$(CC) $(CFLAGS) $(DFLAGS) -ldflags '$(LDFLAGS)' -o $(BUILD_DIR)/$(NAME)
.PHONY: dev
dev: fmt lint build
.PHONY: release
release: $(FILE_PATHS)
$(CC) $(CFLAGS) -ldflags '$(LDFLAGS) -s -w' -o $(BUILD_DIR)/$(NAME)
.PHONY: dist
dist: $(FILE_PATHS)
$(CROSS) $(CC) $(CFLAGS) -ldflags '$(LDFLAGS) -s -w' -o $(BUILD_DIR)/$(NAME)
.PHONY: clean
clean:
rm -rfv $(BUILD_DIR)
rm -rfv vendor
# Docker build
.PHONY: build-docker
build-docker: build-go-in-docker build-docker-image
.PHONY: build-go-in-docker
build-go-in-docker:
docker run --rm \
-e GOBIN=/go/bin/ -e CGO_ENABLED=0 -e GOPATH=/go \
-v ${PWD}:/go/src/github.com/ovh/noderig \
-w /go/src/github.com/ovh/noderig \
golang:1.12.6 \
make
.PHONY: build-docker-image
build-docker-image:
docker build -t ovh/noderig .
.PHONY: run
run:
docker run --rm --net host ovh/noderig