18
18
# Licensed under the Apache License, Version 2.0
19
19
# -----------------------------------------------------------------------------
20
20
21
+ # #########################
22
+ # Configuration
23
+ # #########################
24
+ PACKAGE := "github.com/containerd/nerdctl/v2"
25
+ ORG_PREFIXES := "github.com/containerd"
26
+
21
27
DOCKER ?= docker
22
28
GO ?= go
23
29
GOOS ?= $(shell $(GO ) env GOOS)
24
30
ifeq ($(GOOS ) ,windows)
25
31
BIN_EXT := .exe
26
32
endif
27
33
28
- PACKAGE := github.com/containerd/nerdctl/v2
29
-
30
- # distro builders might wanna override these
34
+ # distro builders might want to override these
31
35
PREFIX ?= /usr/local
32
36
BINDIR ?= $(PREFIX ) /bin
33
37
DATADIR ?= $(PREFIX ) /share
34
38
DOCDIR ?= $(DATADIR ) /doc
35
39
40
+ BINARY ?= "nerdctl"
36
41
MAKEFILE_DIR := $(patsubst % /,% ,$(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) ) )
37
42
VERSION ?= $(shell git -C $(MAKEFILE_DIR ) describe --match 'v[0-9]* ' --dirty='.m' --always --tags)
38
43
VERSION_TRIMMED := $(VERSION:v%=% )
39
44
REVISION ?= $(shell git -C $(MAKEFILE_DIR ) rev-parse HEAD)$(shell if ! git -C $(MAKEFILE_DIR ) diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
45
+ LINT_COMMIT_RANGE ?= main..HEAD
46
+ GO_BUILD_LDFLAGS ?= -s -w
47
+ GO_BUILD_FLAGS ?=
40
48
49
+ # #########################
50
+ # Helpers
51
+ # #########################
41
52
ifdef VERBOSE
42
53
VERBOSE_FLAG := -v
43
54
VERBOSE_FLAG_LONG := --verbose
44
55
endif
45
56
46
- GO_BUILD_LDFLAGS ?= -s -w
47
- GO_BUILD_FLAGS ?=
48
57
export GO_BUILD=CGO_ENABLED =0 GOOS=$(GOOS ) $(GO ) -C $(MAKEFILE_DIR ) build -ldflags "$(GO_BUILD_LDFLAGS ) $(VERBOSE_FLAG ) -X $(PACKAGE ) /pkg/version.Version=$(VERSION ) -X $(PACKAGE ) /pkg/version.Revision=$(REVISION ) "
49
58
59
+ ifndef NO_COLORS
60
+ NC := \033[0m
61
+ GREEN := \033[1;32m
62
+ ORANGE := \033[1;33m
63
+ endif
64
+
50
65
recursive_wildcard =$(wildcard $1$2) $(foreach e,$(wildcard $1* ) ,$(call recursive_wildcard,$e/,$2) )
51
66
67
+ define title
68
+ @printf "$(GREEN ) ____________________________________________________________________________________________________\n"
69
+ @printf "$(GREEN ) %*s\n" $$(( ( $(shell echo "🤓$(1 ) 🤓" | wc -c ) + 100 ) / 2 )) "🤓$(1 ) 🤓"
70
+ @printf "$(GREEN ) ____________________________________________________________________________________________________\n$(ORANGE ) "
71
+ endef
72
+
73
+ define footer
74
+ @printf "$(GREEN ) > %s: done!\n" "$(1 ) "
75
+ @printf "$(GREEN ) ____________________________________________________________________________________________________\n$(NC ) "
76
+ endef
77
+
78
+ # #########################
79
+ # High-level tasks definitions
80
+ # #########################
52
81
all : binaries
53
82
83
+ lint : lint-go-all lint-imports lint-yaml lint-shell lint-commits lint-mod lint-licenses-all
84
+
85
+ fix : fix-mod fix-imports fix-go-all
86
+
87
+ # TODO: fix race task and add it
88
+ test : test-unit # test-unit-race test-unit-bench
89
+
54
90
help :
55
91
@echo " Usage: make <target>"
56
92
@echo
57
- @echo " * 'install' - Install binaries to system locations."
93
+ @echo " * 'lint' - Run linters against codebase."
94
+ @echo " * 'fix' - Automatically fixes imports, modules, and simple formatting."
95
+ @echo " * 'test' - Run basic unit testing."
58
96
@echo " * 'binaries' - Build nerdctl."
97
+ @echo " * 'install' - Install binaries to system locations."
59
98
@echo " * 'clean' - Clean artifacts."
60
- @echo " * 'lint' - Run various linters."
61
99
62
- nerdctl :
63
- $(GO_BUILD ) $(GO_BUILD_FLAGS ) $(VERBOSE_FLAG ) -o $(CURDIR ) /_output/nerdctl$(BIN_EXT ) ./cmd/nerdctl
100
+ # #########################
101
+ # Building and installation tasks
102
+ # #########################
103
+ binaries : $(CURDIR ) /_output/$(BINARY )$(BIN_EXT )
104
+
105
+ $(CURDIR ) /_output/$(BINARY )$(BIN_EXT ) :
106
+ $(call title, $@ )
107
+ $(GO_BUILD ) $(GO_BUILD_FLAGS ) $(VERBOSE_FLAG ) -o $(CURDIR ) /_output/$(BINARY )$(BIN_EXT ) ./cmd/nerdctl
108
+ $(call footer, $@ )
109
+
110
+ install :
111
+ $(call title, $@ )
112
+ install -D -m 755 $(CURDIR ) /_output/$(BINARY ) $(DESTDIR )$(BINDIR ) /$(BINARY )
113
+ install -D -m 755 $(MAKEFILE_DIR ) /extras/rootless/containerd-rootless.sh $(DESTDIR )$(BINDIR ) /containerd-rootless.sh
114
+ install -D -m 755 $(MAKEFILE_DIR ) /extras/rootless/containerd-rootless-setuptool.sh $(DESTDIR )$(BINDIR ) /containerd-rootless-setuptool.sh
115
+ install -D -m 644 -t $(DESTDIR )$(DOCDIR ) /nerdctl $(MAKEFILE_DIR ) /docs/* .md
116
+ $(call footer, $@ )
64
117
65
118
clean :
119
+ $(call title, $@ )
66
120
find . -name \* ~ -delete
67
121
find . -name \#\* -delete
68
122
rm -rf $(CURDIR ) /_output/* $(MAKEFILE_DIR ) /vendor
123
+ $(call footer, $@ )
69
124
70
- lint : lint-go lint-imports lint-yaml lint-shell
71
-
125
+ # #########################
126
+ # Linting tasks
127
+ # #########################
72
128
lint-go :
73
- cd $(MAKEFILE_DIR ) && GOOS=linux golangci-lint run $(VERBOSE_FLAG_LONG ) ./... && \
74
- GOOS=windows golangci-lint run $(VERBOSE_FLAG_LONG ) ./... && \
75
- GOOS=freebsd golangci-lint run $(VERBOSE_FLAG_LONG ) ./...
129
+ $(call title, $@ : $(GOOS ) )
130
+ @cd $(MAKEFILE_DIR ) \
131
+ && golangci-lint run $(VERBOSE_FLAG_LONG ) ./...
132
+ $(call footer, $@ )
133
+
134
+ lint-go-all :
135
+ $(call title, $@ )
136
+ @cd $(MAKEFILE_DIR ) \
137
+ && GOOS=linux make lint-go \
138
+ && GOOS=windows make lint-go \
139
+ && GOOS=freebsd make lint-go
140
+ $(call footer, $@ )
76
141
77
142
lint-imports :
78
- cd $( MAKEFILE_DIR ) && goimports-reviser -recursive -list-diff -set-exit-status -output stdout -company-prefixes " github.com/containerd " ./...
79
-
80
- lint-fix-imports :
81
- cd $( MAKEFILE_DIR ) && goimports-reviser -company-prefixes " github.com/containerd " ./...
143
+ $( call title, $@ )
144
+ @cd $( MAKEFILE_DIR ) \
145
+ && goimports-reviser -recursive -list-diff -set-exit-status -output stdout -company-prefixes " $( ORG_PREFIXES ) " ./...
146
+ $( call footer, $@ )
82
147
83
148
lint-yaml :
84
- cd $(MAKEFILE_DIR ) && yamllint .
149
+ $(call title, $@ )
150
+ cd $(MAKEFILE_DIR ) \
151
+ && yamllint .
152
+ $(call footer, $@ )
85
153
86
154
lint-shell : $(call recursive_wildcard,$(MAKEFILE_DIR ) /,* .sh)
155
+ $(call title, $@ )
87
156
shellcheck -a -x $^
88
-
157
+ $(call footer, $@ )
158
+
159
+ lint-commits :
160
+ $(call title, $@ )
161
+ @cd $(MAKEFILE_DIR ) \
162
+ && git-validation $(VERBOSE_FLAG ) -run DCO,short-subject,dangling-whitespace -range " $( LINT_COMMIT_RANGE) "
163
+ $(call footer, $@ )
164
+
165
+ lint-mod :
166
+ $(call title, $@ )
167
+ @cd $(MAKEFILE_DIR ) \
168
+ && go mod tidy --diff
169
+ $(call footer, $@ )
170
+
171
+ lint-licenses :
172
+ $(call title, $@ : $(GOOS ) )
173
+ @cd $(MAKEFILE_DIR ) \
174
+ && ./hack/make-lint-licenses.sh
175
+ $(call footer, $@ )
176
+
177
+ lint-licenses-all :
178
+ $(call title, $@ )
179
+ @cd $(MAKEFILE_DIR ) \
180
+ && GOOS=linux make lint-licenses \
181
+ && GOOS=freebsd make lint-licenses \
182
+ && GOOS=windows make lint-licenses
183
+ $(call footer, $@ )
184
+
185
+ # #########################
186
+ # Automated fixing tasks
187
+ # #########################
188
+ fix-go :
189
+ $(call title, $@ : $(GOOS ) )
190
+ @cd $(MAKEFILE_DIR ) \
191
+ && golangci-lint run --fix
192
+ $(call footer, $@ )
193
+
194
+ fix-go-all :
195
+ $(call title, $@ )
196
+ @cd $(MAKEFILE_DIR ) \
197
+ && GOOS=linux make fix-go \
198
+ && GOOS=freebsd make fix-go \
199
+ && GOOS=windows make fix-go
200
+ $(call footer, $@ )
201
+
202
+ fix-imports :
203
+ $(call title, $@ )
204
+ @cd $(MAKEFILE_DIR ) \
205
+ && goimports-reviser -company-prefixes $(ORG_PREFIXES ) ./...
206
+ $(call footer, $@ )
207
+
208
+ fix-mod :
209
+ $(call title, $@ )
210
+ @cd $(MAKEFILE_DIR ) \
211
+ && go mod tidy
212
+ $(call footer, $@ )
213
+
214
+ # #########################
215
+ # Development tools installation
216
+ # #########################
217
+ install-dev-tools :
218
+ $(call title, $@ )
219
+ # golangci: v1.64.5
220
+ # git-validation: main from 2023/11
221
+ # ltag: v0.2.5
222
+ # go-licenses: v2.0.0-alpha.1
223
+ # goimports-reviser: v3.8.2
224
+ @cd $(MAKEFILE_DIR ) \
225
+ && go install github.com/golangci/golangci-lint/cmd/golangci-lint@0a603e49e5e9870f5f9f2035bcbe42cd9620a9d5 \
226
+ && go install github.com/vbatts/git-validation@679e5cad8c50f1605ab3d8a0a947aaf72fb24c07 \
227
+ && go install github.com/kunalkushwaha/ltag@b0cfa33e4cc9383095dc584d3990b62c95096de0 \
228
+ && go install github.com/google/go-licenses/v2@d01822334fba5896920a060f762ea7ecdbd086e8 \
229
+ && go install github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 \
230
+ && go install gotest.tools/gotestsum@ac6dad9c7d87b969004f7749d1942938526c9716
231
+ @echo " Remember to add GOROOT/bin to your path"
232
+ $(call footer, $@ )
233
+
234
+ # #########################
235
+ # Testing tasks
236
+ # #########################
89
237
test-unit :
90
- go test -v $(MAKEFILE_DIR ) /pkg/...
91
-
92
- binaries : nerdctl
93
-
94
- install :
95
- install -D -m 755 $(CURDIR ) /_output/nerdctl $(DESTDIR )$(BINDIR ) /nerdctl
96
- install -D -m 755 $(MAKEFILE_DIR ) /extras/rootless/containerd-rootless.sh $(DESTDIR )$(BINDIR ) /containerd-rootless.sh
97
- install -D -m 755 $(MAKEFILE_DIR ) /extras/rootless/containerd-rootless-setuptool.sh $(DESTDIR )$(BINDIR ) /containerd-rootless-setuptool.sh
98
- install -D -m 644 -t $(DESTDIR )$(DOCDIR ) /nerdctl $(MAKEFILE_DIR ) /docs/* .md
99
-
238
+ $(call title, $@ )
239
+ @go test $(VERBOSE_FLAG ) $(MAKEFILE_DIR ) /pkg/...
240
+ $(call footer, $@ )
241
+
242
+ test-unit-bench :
243
+ $(call title, $@ )
244
+ @go test $(VERBOSE_FLAG ) $(MAKEFILE_DIR ) /pkg/... -bench=.
245
+ $(call footer, $@ )
246
+
247
+ test-unit-race :
248
+ $(call title, $@ )
249
+ @go test $(VERBOSE_FLAG ) $(MAKEFILE_DIR ) /pkg/... -race
250
+ $(call footer, $@ )
251
+
252
+ # #########################
253
+ # Release tasks
254
+ # #########################
100
255
# Note that these options will not work on macOS - unless you use gnu-tar instead of tar
101
256
TAR_OWNER0_FLAGS=--owner =0 --group=0
102
257
TAR_FLATTEN_FLAGS =--transform 's/.*\///g'
@@ -107,6 +262,7 @@ define make_artifact_full_linux
107
262
endef
108
263
109
264
artifacts : clean
265
+ $(call title, $@ )
110
266
GOOS=linux GOARCH=amd64 make -C $(CURDIR ) -f $(MAKEFILE_DIR ) /Makefile binaries
111
267
tar $(TAR_OWNER0_FLAGS ) $(TAR_FLATTEN_FLAGS ) -czvf $(CURDIR ) /_output/nerdctl-$(VERSION_TRIMMED ) -linux-amd64.tar.gz $(CURDIR ) /_output/nerdctl $(MAKEFILE_DIR ) /extras/rootless/*
112
268
@@ -138,15 +294,19 @@ artifacts: clean
138
294
139
295
$(GO) -C $(MAKEFILE_DIR) mod vendor
140
296
tar $(TAR_OWNER0_FLAGS) -czf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-go-mod-vendor.tar.gz $(MAKEFILE_DIR)/go.mod $(MAKEFILE_DIR)/go.sum $(MAKEFILE_DIR)/vendor
297
+ $(call footer, $@)
141
298
142
299
.PHONY : \
300
+ all \
301
+ lint \
302
+ fix \
303
+ test \
143
304
help \
144
- nerdctl \
145
- clean \
146
305
binaries \
147
306
install \
307
+ clean \
308
+ lint-go lint-go-all lint-imports lint-yaml lint-shell lint-commits lint-mod lint-licenses lint-licenses-all \
309
+ fix-go fix-go-all fix-imports fix-mod \
310
+ install-dev-tools \
311
+ test-unit test-unit-race test-unit-bench \
148
312
artifacts
149
- lint \
150
- lint-yaml \
151
- lint-go \
152
- lint-shell
0 commit comments