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