github.com/demonoid81/containerd@v1.3.4/Makefile (about) 1 # Copyright The containerd Authors. 2 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 7 # http://www.apache.org/licenses/LICENSE-2.0 8 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 16 # Root directory of the project (absolute path). 17 ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 18 19 # Base path used to install. 20 DESTDIR ?= /usr/local 21 22 # Used to populate variables in version package. 23 VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always) 24 REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) 25 PACKAGE=github.com/containerd/containerd 26 27 ifneq "$(strip $(shell command -v go 2>/dev/null))" "" 28 GOOS ?= $(shell go env GOOS) 29 GOARCH ?= $(shell go env GOARCH) 30 else 31 ifeq ($(GOOS),) 32 # approximate GOOS for the platform if we don't have Go and GOOS isn't 33 # set. We leave GOARCH unset, so that may need to be fixed. 34 ifeq ($(OS),Windows_NT) 35 GOOS = windows 36 else 37 UNAME_S := $(shell uname -s) 38 ifeq ($(UNAME_S),Linux) 39 GOOS = linux 40 endif 41 ifeq ($(UNAME_S),Darwin) 42 GOOS = darwin 43 endif 44 ifeq ($(UNAME_S),FreeBSD) 45 GOOS = freebsd 46 endif 47 endif 48 else 49 GOOS ?= $$GOOS 50 GOARCH ?= $$GOARCH 51 endif 52 endif 53 54 ifndef GODEBUG 55 EXTRA_LDFLAGS += -s -w 56 DEBUG_GO_GCFLAGS := 57 DEBUG_TAGS := 58 else 59 DEBUG_GO_GCFLAGS := -gcflags=all="-N -l" 60 DEBUG_TAGS := static_build 61 endif 62 63 WHALE = "🇩" 64 ONI = "👹" 65 66 RELEASE=containerd-$(VERSION:v%=%).${GOOS}-${GOARCH} 67 68 PKG=github.com/containerd/containerd 69 70 # Project packages. 71 PACKAGES=$(shell go list ./... | grep -v /vendor/) 72 INTEGRATION_PACKAGE=${PKG} 73 TEST_REQUIRES_ROOT_PACKAGES=$(filter \ 74 ${PACKAGES}, \ 75 $(shell \ 76 for f in $$(git grep -l testutil.RequiresRoot | grep -v Makefile); do \ 77 d="$$(dirname $$f)"; \ 78 [ "$$d" = "." ] && echo "${PKG}" && continue; \ 79 echo "${PKG}/$$d"; \ 80 done | sort -u) \ 81 ) 82 83 ifdef SKIPTESTS 84 PACKAGES:=$(filter-out ${SKIPTESTS},${PACKAGES}) 85 TEST_REQUIRES_ROOT_PACKAGES:=$(filter-out ${SKIPTESTS},${TEST_REQUIRES_ROOT_PACKAGES}) 86 endif 87 88 # Project binaries. 89 COMMANDS=ctr containerd containerd-stress 90 MANPAGES=ctr.8 containerd.8 containerd-config.8 containerd-config.toml.5 91 92 ifdef BUILDTAGS 93 GO_BUILDTAGS = ${BUILDTAGS} 94 endif 95 # Build tags seccomp and apparmor are needed by CRI plugin. 96 GO_BUILDTAGS ?= seccomp apparmor 97 GO_BUILDTAGS += ${DEBUG_TAGS} 98 GO_TAGS=$(if $(GO_BUILDTAGS),-tags "$(GO_BUILDTAGS)",) 99 GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PACKAGE) $(EXTRA_LDFLAGS)' 100 SHIM_GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PACKAGE) -extldflags "-static" $(EXTRA_LDFLAGS)' 101 102 #Replaces ":" (*nix), ";" (windows) with newline for easy parsing 103 GOPATHS=$(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n") 104 105 TESTFLAGS_RACE= 106 GO_BUILD_FLAGS= 107 # See Golang issue re: '-trimpath': https://github.com/golang/go/issues/13809 108 GO_GCFLAGS=$(shell \ 109 set -- ${GOPATHS}; \ 110 echo "-gcflags=-trimpath=$${1}/src"; \ 111 ) 112 113 #include platform specific makefile 114 -include Makefile.$(GOOS) 115 116 BINARIES=$(addprefix bin/,$(COMMANDS)) 117 118 # Flags passed to `go test` 119 TESTFLAGS ?= $(TESTFLAGS_RACE) $(EXTRA_TESTFLAGS) 120 TESTFLAGS_PARALLEL ?= 8 121 122 .PHONY: clean all AUTHORS build binaries test integration generate protos checkprotos coverage ci check help install uninstall vendor release mandir install-man genman 123 .DEFAULT: default 124 125 all: binaries 126 127 check: proto-fmt ## run all linters 128 @echo "$(WHALE) $@" 129 GOGC=75 golangci-lint run 130 131 ci: check binaries checkprotos coverage coverage-integration ## to be used by the CI 132 133 AUTHORS: .mailmap .git/HEAD 134 git log --format='%aN <%aE>' | sort -fu > $@ 135 136 generate: protos 137 @echo "$(WHALE) $@" 138 @PATH="${ROOTDIR}/bin:${PATH}" go generate -x ${PACKAGES} 139 140 protos: bin/protoc-gen-gogoctrd ## generate protobuf 141 @echo "$(WHALE) $@" 142 @PATH="${ROOTDIR}/bin:${PATH}" protobuild --quiet ${PACKAGES} 143 144 check-protos: protos ## check if protobufs needs to be generated again 145 @echo "$(WHALE) $@" 146 @test -z "$$(git status --short | grep ".pb.go" | tee /dev/stderr)" || \ 147 ((git diff | cat) && \ 148 (echo "$(ONI) please run 'make protos' when making changes to proto files" && false)) 149 150 check-api-descriptors: protos ## check that protobuf changes aren't present. 151 @echo "$(WHALE) $@" 152 @test -z "$$(git status --short | grep ".pb.txt" | tee /dev/stderr)" || \ 153 ((git diff $$(find . -name '*.pb.txt') | cat) && \ 154 (echo "$(ONI) please run 'make protos' when making changes to proto files and check-in the generated descriptor file changes" && false)) 155 156 proto-fmt: ## check format of proto files 157 @echo "$(WHALE) $@" 158 @test -z "$$(find . -path ./vendor -prune -o -path ./protobuf/google/rpc -prune -o -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \ 159 (echo "$(ONI) please indent proto files with tabs only" && false) 160 @test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn "Meta meta = " {} \; | grep -v '(gogoproto.nullable) = false' | tee /dev/stderr)" || \ 161 (echo "$(ONI) meta fields in proto files must have option (gogoproto.nullable) = false" && false) 162 163 build: ## build the go packages 164 @echo "$(WHALE) $@" 165 @go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES} 166 167 test: ## run tests, except integration tests and tests that require root 168 @echo "$(WHALE) $@" 169 @go test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 170 171 root-test: ## run tests, except integration tests 172 @echo "$(WHALE) $@" 173 @go test ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) -test.root 174 175 integration: ## run integration tests 176 @echo "$(WHALE) $@" 177 @go test ${TESTFLAGS} -test.root -parallel ${TESTFLAGS_PARALLEL} 178 179 benchmark: ## run benchmarks tests 180 @echo "$(WHALE) $@" 181 @go test ${TESTFLAGS} -bench . -run Benchmark -test.root 182 183 FORCE: 184 185 # Build a binary from a cmd. 186 bin/%: cmd/% FORCE 187 @echo "$(WHALE) $@${BINARY_SUFFIX}" 188 @go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ./$< 189 190 bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220 191 @echo "$(WHALE) bin/containerd-shim" 192 @CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim 193 194 bin/containerd-shim-runc-v1: cmd/containerd-shim-runc-v1 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220 195 @echo "$(WHALE) bin/containerd-shim-runc-v1" 196 @CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1 197 198 bin/containerd-shim-runc-v2: cmd/containerd-shim-runc-v2 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220 199 @echo "$(WHALE) bin/containerd-shim-runc-v2" 200 @CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v2 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v2 201 202 binaries: $(BINARIES) ## build binaries 203 @echo "$(WHALE) $@" 204 205 man: mandir $(addprefix man/,$(MANPAGES)) 206 @echo "$(WHALE) $@" 207 208 mandir: 209 @mkdir -p man 210 211 # Kept for backwards compatability 212 genman: man/containerd.8 man/ctr.8 213 214 man/containerd.8: FORCE 215 @echo "$(WHALE) $@" 216 go run cmd/gen-manpages/main.go $(@F) $(@D) 217 218 man/ctr.8: FORCE 219 @echo "$(WHALE) $@" 220 go run cmd/gen-manpages/main.go $(@F) $(@D) 221 222 man/%: docs/man/%.md FORCE 223 @echo "$(WHALE) $@" 224 go-md2man -in "$<" -out "$@" 225 226 define installmanpage 227 mkdir -p $(DESTDIR)/man/man$(2); 228 gzip -c $(1) >$(DESTDIR)/man/man$(2)/$(3).gz; 229 endef 230 231 install-man: 232 @echo "$(WHALE) $@" 233 $(foreach manpage,$(addprefix man/,$(MANPAGES)), $(call installmanpage,$(manpage),$(subst .,,$(suffix $(manpage))),$(notdir $(manpage)))) 234 235 releases/$(RELEASE).tar.gz: $(BINARIES) 236 @echo "$(WHALE) $@" 237 @rm -rf releases/$(RELEASE) releases/$(RELEASE).tar.gz 238 @install -d releases/$(RELEASE)/bin 239 @install $(BINARIES) releases/$(RELEASE)/bin 240 @tar -czf releases/$(RELEASE).tar.gz -C releases/$(RELEASE) bin 241 @rm -rf releases/$(RELEASE) 242 243 release: $(BINARIES) releases/$(RELEASE).tar.gz 244 @echo "$(WHALE) $@" 245 @cd releases && sha256sum $(RELEASE).tar.gz >$(RELEASE).tar.gz.sha256sum 246 247 cri-release: $(BINARIES) releases/$(RELEASE).tar.gz 248 @echo "$(WHALE) $@" 249 @VERSION=$(VERSION:v%=%) script/release/release-cri 250 251 clean: ## clean up binaries 252 @echo "$(WHALE) $@" 253 @rm -f $(BINARIES) 254 255 clean-test: ## clean up debris from previously failed tests 256 @echo "$(WHALE) $@" 257 $(eval containers=$(shell find /run/containerd/runc -mindepth 2 -maxdepth 3 -type d -exec basename {} \;)) 258 $(shell pidof containerd containerd-shim runc | xargs -r -n 1 kill -9) 259 @( for container in $(containers); do \ 260 grep $$container /proc/self/mountinfo | while read -r mountpoint; do \ 261 umount $$(echo $$mountpoint | awk '{print $$5}'); \ 262 done; \ 263 find /sys/fs/cgroup -name $$container -print0 | xargs -r -0 rmdir; \ 264 done ) 265 @rm -rf /run/containerd/runc/* 266 @rm -rf /run/containerd/fifo/* 267 @rm -rf /run/containerd-test/* 268 269 install: ## install binaries 270 @echo "$(WHALE) $@ $(BINARIES)" 271 @mkdir -p $(DESTDIR)/bin 272 @install $(BINARIES) $(DESTDIR)/bin 273 274 uninstall: 275 @echo "$(WHALE) $@" 276 @rm -f $(addprefix $(DESTDIR)/bin/,$(notdir $(BINARIES))) 277 278 279 coverage: ## generate coverprofiles from the unit tests, except tests that require root 280 @echo "$(WHALE) $@" 281 @rm -f coverage.txt 282 @go test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}) 2> /dev/null 283 @( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${PACKAGES}); do \ 284 go test ${TESTFLAGS} \ 285 -cover \ 286 -coverprofile=profile.out \ 287 -covermode=atomic $$pkg || exit; \ 288 if [ -f profile.out ]; then \ 289 cat profile.out >> coverage.txt; \ 290 rm profile.out; \ 291 fi; \ 292 done ) 293 294 root-coverage: ## generate coverage profiles for unit tests that require root 295 @echo "$(WHALE) $@" 296 @go test -i ${TESTFLAGS} $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}) 2> /dev/null 297 @( for pkg in $(filter-out ${INTEGRATION_PACKAGE},${TEST_REQUIRES_ROOT_PACKAGES}); do \ 298 go test ${TESTFLAGS} \ 299 -cover \ 300 -coverprofile=profile.out \ 301 -covermode=atomic $$pkg -test.root || exit; \ 302 if [ -f profile.out ]; then \ 303 cat profile.out >> coverage.txt; \ 304 rm profile.out; \ 305 fi; \ 306 done ) 307 308 vendor: 309 @echo "$(WHALE) $@" 310 @vndr 311 312 help: ## this help 313 @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort