1
- .PHONY : all build-container build-tar build push-container push-tar push clean vet fmt version
1
+ # Copyright 2017 The Kubernetes 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
+ # Build the node-problem-detector image.
16
+
17
+ .PHONY : all build-container build-tar build push-container push-tar push clean vet fmt version Dockerfile
2
18
3
19
all : build
4
20
5
- VERSION := $(shell git describe --tags --dirty)
21
+ # VERSION is the version of the binary.
22
+ VERSION: =$(shell git describe --tags --dirty)
6
23
7
- TAG ?= $(VERSION )
24
+ # TAG is the tag of the container image, default to binary version.
25
+ TAG? =$(VERSION )
8
26
9
- UPLOAD_PATH ?= gs://kubernetes-release
27
+ # PROJ is the image project.
28
+ PROJ? =gcr.io/google_containers
29
+
30
+ # UPLOAD_PATH is the cloud storage path to upload release tar.
31
+ UPLOAD_PATH? =gs://kubernetes-release
10
32
# Trim the trailing '/' in the path
11
- UPLOAD_PATH := $(shell echo $(UPLOAD_PATH ) | sed '$$s/\/* $$//')
33
+ UPLOAD_PATH: =$(shell echo $(UPLOAD_PATH ) | sed '$$s/\/* $$//')
34
+
35
+ # PKG is the package name of node problem detector repo.
36
+ PKG: =k8s.io/node-problem-detector
37
+
38
+ # PKG_SOURCES are all the go source code.
39
+ PKG_SOURCES: =$(shell find pkg cmd -name '* .go')
12
40
13
- PROJ ?= google_containers
41
+ # TARBALL is the name of release tar. Include binary version by default.
42
+ TARBALL: =node-problem-detector-$(VERSION ) .tar.gz
14
43
15
- PKG := k8s.io/node-problem-detector
44
+ # IMAGE is the image name of the node problem detector container image.
45
+ IMAGE: =$(PROJ ) /node-problem-detector:$(TAG )
16
46
17
- PKG_SOURCES := $(shell find pkg cmd -name '* .go')
47
+ # ENABLE_JOURNALD enables build journald support or not. Building journald support needs libsystemd-dev
48
+ # or libsystemd-journal-dev.
49
+ # TODO(random-liu): Build NPD inside container.
50
+ ENABLE_JOURNALD? =1
18
51
19
- TARBALL := node-problem-detector-$(VERSION ) .tar.gz
52
+ # TODO(random-liu): Support different architectures.
53
+ BASEIMAGE: =alpine:3.4
20
54
21
- IMAGE := gcr.io/$(PROJ ) /node-problem-detector:$(TAG )
55
+ # Disable cgo by default to make the binary statically linked.
56
+ CGO_ENABLED: =0
57
+
58
+ # NOTE that enable journald will increase the image size.
59
+ ifeq ($(ENABLE_JOURNALD ) , 1)
60
+ # Enable journald build tag.
61
+ BUILD_TAGS:=-tags journald
62
+ # Use fedora because it has newer systemd version (229) and support +LZ4. +LZ4 is needed
63
+ # on some os distros such as GCI.
64
+ BASEIMAGE:=fedora
65
+ # Enable cgo because sdjournal needs cgo to compile. The binary will be dynamically
66
+ # linked if CGO_ENABLED is enabled. This is fine because fedora already has necessary
67
+ # dynamic library. We can not use `-extldflags "-static"` here, because go-systemd uses
68
+ # dlopen, and dlopen will not work properly in a statically linked application.
69
+ CGO_ENABLED:=1
70
+ endif
22
71
23
72
vet :
24
73
go list ./... | grep -v " ./vendor/*" | xargs go vet
@@ -30,14 +79,17 @@ version:
30
79
@echo $(VERSION )
31
80
32
81
./bin/node-problem-detector : $(PKG_SOURCES )
33
- GOOS=linux go build -o bin/node-problem-detector \
34
- -ldflags ' -w -extldflags "-static" -X $(PKG)/pkg/version.version=$(VERSION)' \
35
- cmd/node_problem_detector.go
82
+ CGO_ENABLED=$(CGO_ENABLED ) GOOS=linux go build -o bin/node-problem-detector \
83
+ -ldflags ' -w -X $(PKG)/pkg/version.version=$(VERSION)' \
84
+ $(BUILD_TAGS ) cmd/node_problem_detector.go
85
+
86
+ Dockerfile : Dockerfile.in
87
+ sed -e ' s|@BASEIMAGE@|$(BASEIMAGE)|g' $< > $@
36
88
37
89
test : vet fmt
38
- go test -timeout=1m -v -race ./pkg/...
90
+ go test -timeout=1m -v -race ./pkg/... $( BUILD_TAGS )
39
91
40
- build-container : ./bin/node-problem-detector
92
+ build-container : ./bin/node-problem-detector Dockerfile
41
93
docker build -t $(IMAGE ) .
42
94
43
95
build-tar : ./bin/node-problem-detector
0 commit comments