Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Few minor makefile and dockerfile improvements #10970

Merged
merged 5 commits into from Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Expand Up @@ -38,7 +38,7 @@ coverage-all.html
.idea/
*.plist

cilium/bash_autocomplete
*_bash_completion
*.swo
outgoing

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -40,7 +40,7 @@ coverage-all.html
.idea/
*.plist

cilium/bash_autocomplete
*_bash_completion
*.swo
outgoing

Expand Down
3 changes: 3 additions & 0 deletions Documentation/Makefile
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
errordeveloper marked this conversation as resolved.
Show resolved Hide resolved
# SPDX-License-Identifier: Apache-2.0

include ../Makefile.quiet

.PHONY: default clean builder-image cmdref epub latex html run-server stop-server
Expand Down
17 changes: 10 additions & 7 deletions Makefile
@@ -1,13 +1,16 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

include Makefile.defs

SUBDIRS_CILIUM_CONTAINER := proxylib envoy plugins/cilium-cni bpf cilium daemon cilium-health bugtool
ifdef LIBNETWORK_PLUGIN
SUBDIRS_CILIUM_CONTAINER += plugins/cilium-docker
endif
SUBDIRS := $(SUBDIRS_CILIUM_CONTAINER) operator plugins tools hubble-proxy
GOFILES_EVAL := $(subst _$(ROOT_DIR)/,,$(shell $(CGO_DISABLED) $(GOLIST) $(GO) list -e ./...))
GOFILES_EVAL := $(subst _$(ROOT_DIR)/,,$(shell $(GO_LIST) -e ./...))
GOFILES ?= $(GOFILES_EVAL)
TESTPKGS_EVAL := $(subst github.com/cilium/cilium/,,$(shell $(CGO_DISABLED) $(GOLIST) $(GO) list -e ./... | grep -v '/api/v1\|/vendor\|/contrib' | grep -v -P 'test(?!/helpers/logutils)'))
TESTPKGS_EVAL := $(subst github.com/cilium/cilium/,,$(shell $(GO_LIST) -e ./... | grep -v '/api/v1\|/vendor\|/contrib' | grep -v -P 'test(?!/helpers/logutils)'))
TESTPKGS ?= $(TESTPKGS_EVAL)
GOLANGVERSION := $(shell $(GO) version 2>/dev/null | grep -Eo '(go[0-9].[0-9])')
GOLANG_SRCFILES := $(shell for pkg in $(subst github.com/cilium/cilium/,,$(GOFILES)); do find $$pkg -name *.go -print; done | grep -v vendor | sort | uniq)
Expand Down Expand Up @@ -89,7 +92,7 @@ tests-privileged:
# cilium-map-migrate is a dependency of some unit tests.
$(QUIET) $(MAKE) $(SUBMAKEOPTS) -C bpf cilium-map-migrate
$(QUIET)$(foreach pkg,$(PRIV_TEST_PKGS),\
$(GO) test $(GOFLAGS) $(TEST_LDFLAGS) github.com/cilium/cilium/$(pkg) $(GOTEST_PRIV_OPTS) || exit 1;)
$(GO_TEST) $(TEST_LDFLAGS) github.com/cilium/cilium/$(pkg) $(GOTEST_PRIV_OPTS) || exit 1;)

start-kvstores:
ifeq ($(SKIP_KVSTORES),"false")
Expand Down Expand Up @@ -151,7 +154,7 @@ endif
# hence will trigger an error of too many arguments. As a workaround, we
# have to process these packages in different subshells.
for pkg in $(patsubst %,github.com/cilium/cilium/%,$(TESTPKGS)); do \
$(_GO) test $(GOFLAGS) $(TEST_UNITTEST_LDFLAGS) $$pkg $(GOTEST_BASE) $(GOTEST_COVER_OPTS) || exit 1; \
$(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $$pkg $(GOTEST_BASE) $(GOTEST_COVER_OPTS) || exit 1; \
tail -n +2 coverage.out >> coverage-all-tmp.out; \
done
$(MAKE) generate-cov
Expand All @@ -160,14 +163,14 @@ endif

bench: start-kvstores
$(QUIET)$(foreach pkg,$(patsubst %,github.com/cilium/cilium/%,$(TESTPKGS)),\
$(GO) test $(GOFLAGS) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) \
$(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) \
$(pkg) \
|| exit 1;)
$(MAKE) stop-kvstores

bench-privileged:
$(QUIET)$(foreach pkg,$(patsubst %,github.com/cilium/cilium/%,$(TESTPKGS)),\
$(GO) test $(GOFLAGS) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) \
$(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) \
-tags=privileged_tests $(pkg) \
|| exit 1;)

Expand Down Expand Up @@ -365,7 +368,7 @@ gofmt:

govet:
@$(ECHO_CHECK) vetting all GOFILES...
$(QUIET) $(GOLIST) $(_GO) vet \
$(QUIET) $(GO_VET) \
./api/... \
./bugtool/... \
./cilium/... \
Expand Down
88 changes: 51 additions & 37 deletions Makefile.defs
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c

Expand All @@ -14,16 +17,32 @@ LOCALSTATEDIR?=/var
RUNDIR?=/var/run
CONFDIR?=/etc

CGO_DISABLED = CGO_ENABLED=0
GOLIST ?= GO111MODULE=off
ifeq ($(GO),)
GO = $(CGO_DISABLED) go
_GO = go
INSTALL = install

# Container engine
export CONTAINER_ENGINE?=docker
CONTAINER_ENGINE_FULL=$(QUIET)$(CONTAINER_ENGINE)

# Set DOCKER_IMAGE_TAG with "latest" by default
ifeq ($(DOCKER_IMAGE_TAG),)
DOCKER_IMAGE_TAG="latest"
endif

ifeq ($(shell uname -m),aarch64)
ETCD_IMAGE=quay.io/coreos/etcd:v3.2.17-arm64
else
_GO = $(GO)
ETCD_IMAGE=quay.io/coreos/etcd:v3.2.17
endif

INSTALL = install
GO ?= go

# go build/test/clean flags
# these are declared here so they are treated explicitly
# as non-immediate variables
GO_BUILD_FLAGS =
GO_TEST_FLAGS =
GO_CLEAN_FLAGS =
GO_BUILD_LDFLAGS =

VERSION = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION)
VERSION_MAJOR = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION | cut -d. -f1)
Expand All @@ -33,70 +52,65 @@ ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git),)
else
GIT_VERSION = $(shell cat $(ROOT_DIR)/GIT_VERSION)
endif
BUILD = $(VERSION) $(GIT_VERSION) $(shell $(GO) version)
GOLDFLAGS = -X "github.com/cilium/cilium/pkg/version.Version=$(BUILD)"
FULL_BUILD_VERSION = $(VERSION) $(GIT_VERSION) $(shell $(GO) version)
GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/version.Version=$(FULL_BUILD_VERSION)"

ifeq ($(NOSTRIP),)
# Note: these options will not remove annotations needed for stack
# traces, so panic backtraces will still be readable.
#
# -w: Omit the DWARF symbol table.
# -s: Omit the symbol table and debug information.
GOLDFLAGS += -s -w
GO_BUILD_LDFLAGS += -s -w
endif

CILIUM_ENVOY_SHA=$(shell grep -o "FROM.*cilium/cilium-envoy:[0-9a-fA-F]*" $(ROOT_DIR)/Dockerfile | cut -d : -f 2)
GOLDFLAGS += -X "github.com/cilium/cilium/pkg/envoy.RequiredEnvoyVersionSHA=$(CILIUM_ENVOY_SHA)"
GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/envoy.RequiredEnvoyVersionSHA=$(CILIUM_ENVOY_SHA)"

BPF_FILES_EVAL := $(shell git ls-files $(ROOT_DIR)/bpf/ | grep -v .gitignore | tr "\n" ' ')
BPF_FILES ?= $(BPF_FILES_EVAL)
BPF_SRCFILES := $(subst ../,,$(BPF_FILES))

CILIUM_DATAPATH_SHA=$(shell cat $(BPF_FILES) | sha1sum | awk '{print $$1}')
GOLDFLAGS += -X "github.com/cilium/cilium/pkg/datapath/loader.DatapathSHA=$(CILIUM_DATAPATH_SHA)"

# Set DOCKER_IMAGE_TAG with "latest" by default
ifeq ($(DOCKER_IMAGE_TAG),)
DOCKER_IMAGE_TAG="latest"
endif
GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/datapath/loader.DatapathSHA=$(CILIUM_DATAPATH_SHA)"

# Set -mod=vendor if running >= go 1.13 or if GO111MODULE is set.
# A go build is being executed with go modules if:
# * The go command is invoked with GO111MODULE=on environment variable set.
# * The go command is invoked in a directory outside of the $GOPATH/src tree
# and the environment variable GO111MODULE unset (or explicitly set to 'auto').
ifeq ($(GO111MODULE),on)
GOFLAGS ?= -mod=vendor
GOCLEAN ?= -mod=vendor
GO_BUILD_FLAGS += -mod=vendor
GO_TEST_FLAGS += -mod=vendor
GO_CLEAN_FLAGS += -mod=vendor
endif

# Compile with '-mod=vendor' if go >= 1.13
GO_MAJOR_VERSION_GE_1 := $(shell expr `$(GO) version | grep -E 'go[0-9]{1}+' -o | sed 's/go//g'` \>= 1)
ifeq ($(GO_MAJOR_VERSION_GE_1),1)
GO_MINOR_VERSION_GE_13 := $(shell expr `$(GO) version | grep -E 'go[^ ]+' -o | sed 's/go1.//g'` \>= 13)
ifeq ($(GO_MINOR_VERSION_GE_13),1)
GOFLAGS ?= -mod=vendor
GOCLEAN ?= -mod=vendor
GO_BUILD_FLAGS += -mod=vendor
GO_TEST_FLAGS += -mod=vendor
GO_CLEAN_FLAGS += -mod=vendor
endif
endif

GOBUILD = $(GOFLAGS) -ldflags '$(GOLDFLAGS)' $(EXTRA_GOBUILD_FLAGS)

# Uncomment to enable race detection
#GOBUILD += -race

# Uncomment to enable deadlock detection
#GOBUILD += -tags lockdebug
ifneq ($(RACE),)
GO_BUILD_FLAGS += -race
GO_TEST_FLAGS += -race
endif

ifneq ($(LOCKDEBUG),)
GOBUILD += -tags lockdebug
GO_BUILD_FLAGS += -tags lockdebug
endif

# Container engine
export CONTAINER_ENGINE?=docker
CONTAINER_ENGINE_FULL=$(QUIET)$(CONTAINER_ENGINE)
GO_BUILD_FLAGS += -ldflags '$(GO_BUILD_LDFLAGS) $(EXTRA_GO_BUILD_LDFLAGS)' $(EXTRA_GO_BUILD_FLAGS)
errordeveloper marked this conversation as resolved.
Show resolved Hide resolved

ifeq ($(shell uname -m),aarch64)
ETCD_IMAGE=quay.io/coreos/etcd:v3.2.17-arm64
else
ETCD_IMAGE=quay.io/coreos/etcd:v3.2.17
endif
GO_BUILD = CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS)
GO_BUILD_WITH_CGO = CGO_ENABLED=1 $(GO) build $(GO_BUILD_FLAGS)
GO_TEST = $(GO) test $(GO_TEST_FLAGS)
GO_CLEAN = $(GO) clean $(GO_TEST_FLAGS)
# TODO: remove `GO111MODULE=off` once Go 1.13 is deprecated by Go maintainers
GO_VET = GO111MODULE=off $(GO) vet
GO_LIST = GO111MODULE=off $(GO) list
3 changes: 3 additions & 0 deletions Makefile.quiet
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

ifeq ($(ROOT_DIR),)
ROOT_DIR ?= $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
RELATIVE_DIR ?= $(shell echo $(realpath .) | sed "s;$(ROOT_DIR)[/]*;;")
Expand Down
3 changes: 3 additions & 0 deletions api/v1/Makefile
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

PROTOC ?= protoc

HUBBLE_PROTO_SOURCES := \
Expand Down
3 changes: 3 additions & 0 deletions bpf/Makefile
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

include ../Makefile.defs

.PHONY: all subdirs check preprocess assembly install clean
Expand Down
3 changes: 3 additions & 0 deletions bpf/Makefile.bpf
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

FLAGS := -I$(ROOT_DIR)/bpf/include -I$(ROOT_DIR)/bpf -D__NR_CPUS__=$(shell nproc) -O2 -g

CLANG_FLAGS := ${FLAGS} -target bpf -emit-llvm
Expand Down
3 changes: 3 additions & 0 deletions bpf/sockops/Makefile
@@ -1,3 +1,6 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

include ../../Makefile.defs

.PHONY: all assembly check preprocess clean
Expand Down
27 changes: 9 additions & 18 deletions bugtool/Makefile
@@ -1,31 +1,22 @@
# Copyright 2017-2020 Authors of Cilium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier: Apache-2.0

include ../Makefile.defs

TARGET=cilium-bugtool
SOURCES := $(shell find ../common . -name '*.go')
$(TARGET): $(SOURCES)
@$(ECHO_GO)
$(QUIET)$(GO) build $(GOBUILD) -o $(TARGET)
TARGET := cilium-bugtool

.PHONY: all $(TARGET) clean install

all: $(TARGET)

$(TARGET):
@$(ECHO_GO)
$(QUIET)$(GO_BUILD) -o $@

clean:
@$(ECHO_CLEAN)
-$(QUIET)rm -f .cilium-bugtool.config $(TARGET)
$(QUIET)$(GO) clean $(GOCLEAN)
$(QUIET)$(GO_CLEAN)

install:
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
Expand Down
2 changes: 1 addition & 1 deletion cilium-dev.Dockerfile.dockerignore
Expand Up @@ -45,7 +45,7 @@ coverage-all.html
.idea/
*.plist

cilium/bash_autocomplete
*_bash_completion
*.swo
outgoing

Expand Down
3 changes: 1 addition & 2 deletions cilium-docker-plugin.Dockerfile
Expand Up @@ -3,8 +3,7 @@ LABEL maintainer="maintainer@cilium.io"
ADD . /go/src/github.com/cilium/cilium
WORKDIR /go/src/github.com/cilium/cilium/plugins/cilium-docker
ARG LOCKDEBUG
ARG V
RUN make CGO_ENABLED=0 GOOS=linux LOCKDEBUG=$LOCKDEBUG PKG_BUILD=1 EXTRA_GOBUILD_FLAGS="-a -installsuffix cgo"
errordeveloper marked this conversation as resolved.
Show resolved Hide resolved
RUN make LOCKDEBUG=$LOCKDEBUG
errordeveloper marked this conversation as resolved.
Show resolved Hide resolved

FROM scratch
LABEL maintainer="maintainer@cilium.io"
Expand Down
24 changes: 13 additions & 11 deletions cilium-health/Makefile
@@ -1,31 +1,33 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

include ../Makefile.defs

SUBDIRS = responder
TARGET = cilium-health
TARGET := cilium-health
SUBDIRS := responder

.PHONY: all $(SUBDIRS) install clean
.PHONY: all $(TARGET) $(SUBDIRS) clean install

all: $(TARGET) $(SUBDIRS)

SOURCES := $(shell find ../api/v1/health ../pkg/health cmd . \
\( -name '*.go' ! -name '*_test.go' $(foreach dir,$(SUBDIRS),! -path './$(dir)/*') \) )
$(TARGET): $(SOURCES)
$(TARGET):
@$(ECHO_GO)
$(QUIET)$(GO) build $(GOBUILD) -o $(TARGET)

$(SUBDIRS): force
@ $(MAKE) $(SUBMAKEOPTS) -C $@ all
$(QUIET)$(GO_BUILD) -o $@

clean:
@$(ECHO_CLEAN)
$(QUIET)for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i clean; done
-$(QUIET)rm -f $(TARGET)
$(QUIET)$(GO) clean $(GOCLEAN)
$(QUIET)$(GO_CLEAN)

install:
$(QUIET)for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i install; done
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
$(QUIET)$(INSTALL) -m 0755 $(TARGET) $(DESTDIR)$(BINDIR)


$(SUBDIRS): force
@ $(MAKE) $(SUBMAKEOPTS) -C $@ all

.PHONY: force
force :;
17 changes: 11 additions & 6 deletions cilium-health/responder/Makefile
@@ -1,17 +1,22 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

include ../../Makefile.defs

TARGET=cilium-health-responder
SOURCES := $(shell find ../../pkg/health/probe/responder . \( -name '*.go' ! -name '*_test.go' \))
$(TARGET): $(SOURCES)
@$(ECHO_GO)
$(QUIET)$(GO) build $(GOBUILD) -o $(TARGET)
TARGET := cilium-health-responder

.PHONY: all $(TARGET) clean install

all: $(TARGET)

$(TARGET):
@$(ECHO_GO)
$(QUIET)$(GO_BUILD) -o $@

clean:
@$(ECHO_CLEAN)
-$(QUIET)rm -f $(TARGET)
$(QUIET)$(GO) clean $(GOCLEAN)
$(QUIET)$(GO_CLEAN)

install:
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
Expand Down