-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
174 lines (140 loc) · 5.1 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
ICONS_FOLDER := icons
ICONS_PKG := icons
ICONS_GO_FILE := $(ICONS_FOLDER)/icons.go
ICONS_FILES := $(wildcard $(ICONS_FOLDER)/*.svg)
CMD_SOURCE_FILES := $(shell find cmd -type f -name '*.go')
INTERNAL_SOURCE_FILES := $(shell find internal -type f -name '*.go')
WIRE_SRC_FILES := $(shell find internal -type f -name 'wire*.go' -not -name '*_gen.go')
WIRE_GEN_FILES := $(patsubst %.go,%_gen.go,$(WIRE_SRC_FILES))
ICONS_SOURCE_FILES := $(wildcard icons/*.go)
SOURCE_FILES := $(CMD_SOURCE_FILES) $(INTERNAL_SOURCE_FILES) $(ICONS_SOURCE_FILES)
GRAPHS_FOLDER := docs
GRAPHS_SRC_FILES := $(wildcard $(GRAPHS_FOLDER)/*.puml)
GRAPHS_SVG_FILES := $(patsubst %.puml,%.svg,$(GRAPHS_SRC_FILES))
GRAPHS_PNG_FILES := $(patsubst %.puml,%.png,$(GRAPHS_SRC_FILES))
YAMLS := $(shell find . \( -name "*.yaml" -o -name "*.yml" \) -not -path "./vendor/*")
GIT_SHA = sha-$(shell git log -n 1 --format="%h")
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_REV = $(shell git log -n 1 --format="%H")
DATE = $(shell date -u +"%Y-%m-%dT%TZ")
REPO := wwmoraes/kubegraph
USERNAME = $(shell git config user.name)
EMAIL = $(shell git config user.email)
REPO_URL = https://github.com/$(REPO)
OCI_URL = ${REPO_URL}
OCI_SOURCE = ${REPO_URL}
OCI_VERSION = $(patsubst v%,%,$(shell git describe --tags))
OCI_CREATED = $(DATE)
OCI_REVISION = $(GIT_REV)
OCI_AUTHORS = $(USERNAME) <$(EMAIL)>
OCI_VENDOR = $(USERNAME) <$(EMAIL)>
OCI_DOCUMENTATION = https://github.com/$(REPO)
define dockerLabels
--label org.opencontainers.image.url="${OCI_URL}" \
--label org.opencontainers.image.source="${OCI_SOURCE}" \
--label org.opencontainers.image.version="${OCI_VERSION}" \
--label org.opencontainers.image.created="${OCI_CREATED}" \
--label org.opencontainers.image.revision="${OCI_REVISION}" \
--label org.opencontainers.image.documentation="${OCI_DOCUMENTATION}" \
--label org.opencontainers.image.authors="${OCI_AUTHORS}" \
--label org.opencontainers.image.vendor="${OCI_VENDOR}"
endef
define dockerCachedTag
--cache-from $(REPO):$(2)$(1) \
--tag $(REPO):$(2)$(1)
endef
.DEFAULT_GOAL := build
TMPDIR ?= $(or $(TMPDIR),$(shell dirname $(shell mktemp -u)))
.PHONY: icons
icons: $(ICONS_GO_FILE)
$(ICONS_GO_FILE): $(ICONS_FILES)
@type -p go-bindata 1>/dev/null || go get -u github.com/go-bindata/go-bindata/...
$(info removing old icons package file...)
-@rm $(ICONS_GO_FILE)
$(info regenerating icons package file...)
@go-bindata -o $(ICONS_GO_FILE) -pkg $(ICONS_PKG) -nometadata -mode 0664 -nomemcopy $(ICONS_FOLDER)
.PHONY: lint
lint: yamllint
golangci-lint run
yamllint:
@yamllint $(YAMLS)
.PHONY: test
test:
go test -race -v ./...
.PHONY: coverage
coverage: coverage.out
@go tool cover -func=$<
.PHONY: coverage-html
coverage-html: coverage.html
%.html: %.out
go tool cover -html=$< -o $@
%.out: $(SOURCE_FILES)
@go test -race -cover -coverprofile=$@ -v ./...
.PHONY: build
build: kubegraph
.PHONY: wire
wire: $(WIRE_GEN_FILES)
kubegraph: $(SOURCE_FILES) vendor
go build -mod=vendor -race -o ./ ./...
vendor: go.sum
go.sum: go.mod
go mod vendor
.PHONY: run
run: $(SOURCE_FILES) vendor
go run cmd/kubegraph/main.go sample.yaml
dot -Tsvg -o sample.svg sample.dot
.PHONY: image
image: GIT_BRANCH_SLUG=$(subst /,-,${GIT_BRANCH})
image: Dockerfile $(SOURCE_FILES)
@time docker buildx build \
--cache-to type=local,mode=max,dest=$(TMPDIR)/.buildx-cache/$(REPO) \
--cache-from type=local,src=$(TMPDIR)/.buildx-cache/$(REPO) \
$(call dockerLabels) \
--cache-from $(REPO):single-master \
$(call dockerCachedTag,latest,single-) \
$(call dockerCachedTag,$(GIT_SHA),single-) \
$(call dockerCachedTag,$(GIT_BRANCH_SLUG),single-) \
--load \
.
.PHONY: image-buildx
image-buildx: GIT_BRANCH_SLUG=$(subst /,-,${GIT_BRANCH})
image-buildx: Dockerfile $(SOURCE_FILES)
@docker buildx inspect --builder buildkit || docker buildx create --name buildkit --use
@time docker buildx build --builder buildkit \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--cache-to type=local,mode=max,dest=$(TMPDIR)/.buildx-cache/$(REPO) \
--cache-from type=local,src=$(TMPDIR)/.buildx-cache/$(REPO) \
$(call dockerLabels) \
--cache-from $(REPO):master \
$(call dockerCachedTag,latest) \
$(call dockerCachedTag,$(GIT_SHA)) \
$(call dockerCachedTag,$(GIT_BRANCH_SLUG)) \
--file ./Dockerfile .
.PHONY: docs
docs: $(GRAPHS_SVG_FILES) $(GRAPHS_PNG_FILES)
.PHONY: graphs
graphs: $(GRAPHS_FOLDER)/full-gen.puml $(GRAPHS_FOLDER)/core-gen.puml
@$(MAKE) docs
.PHONY: image-sh
image-sh: image
docker run --rm -it --entrypoint=ash wwmoraes/kubegraph:single-latest
.PHONY: release
release:
env -u GITLAB_TOKEN goreleaser release --rm-dist
.PHONY: test-release
test-release:
env -u GITLAB_TOKEN goreleaser release --rm-dist --snapshot
%_gen.go: %.go
wire ./...
$(GRAPHS_FOLDER)/full-gen.puml: cmd internal icons
$(info generating $@...)
@goplantuml -recursive $^ > $@
$(GRAPHS_FOLDER)/core-gen.puml: internal/registry internal/kubegraph internal/utils
$(info generating $@...)
@goplantuml -recursive $^ > $@
$(GRAPHS_FOLDER)/%.svg: $(GRAPHS_FOLDER)/%.puml
$(info generating $@ from $<...)
@plantuml -tsvg $<
$(GRAPHS_FOLDER)/%.png: $(GRAPHS_FOLDER)/%.puml
$(info generating $@ from $<...)
@plantuml -tpng $<