forked from cilium/tetragon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.docker
108 lines (96 loc) · 4.02 KB
/
Makefile.docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0
# Set DOCKER_DEV_ACCOUNT with "cilium" by default
ifeq ($(DOCKER_DEV_ACCOUNT),)
DOCKER_DEV_ACCOUNT=cilium
endif
ifeq ($(BASE_IMAGE),)
BASE_IMAGE=scratch
endif
DOCKER_BUILDER := default
# Export with value expected by docker
export DOCKER_BUILDKIT=1
# Docker Buildx support. If ARCH is defined, a builder instance 'cross'
# on the local node is configured for amd64 and arm64 platform targets.
# Otherwise build on the current (typically default) builder for the host
# platform only.
ifdef ARCH
# Default to multi-arch builds, always create the builder for all the platforms we support
DOCKER_PLATFORMS := linux/arm64,linux/amd64
DOCKER_BUILDER := $(shell docker buildx ls | grep -E -e "[a-zA-Z0-9-]+ \*" | cut -d ' ' -f1)
ifeq ($(DOCKER_BUILDER),default)
DOCKER_BUILDKIT_DRIVER :=
ifdef DOCKER_BUILDKIT_IMAGE
DOCKER_BUILDKIT_DRIVER := --driver docker-container --driver-opt image=$(DOCKER_BUILDKIT_IMAGE)
endif
BUILDER_SETUP := $(shell docker buildx create --platform $(DOCKER_PLATFORMS) $(DOCKER_BUILDKIT_DRIVER) --use)
endif
# Override default for a single platform
ifneq ($(ARCH),multi)
DOCKER_PLATFORMS := linux/$(ARCH)
endif
DOCKER_FLAGS += --push --platform $(DOCKER_PLATFORMS)
else
# ARCH not specified, build for the host platfrom without pushing, mimicking regular docker build
DOCKER_FLAGS += --load
endif
DOCKER_BUILDER := $(shell docker buildx ls | grep -E -e "[a-zA-Z0-9-]+ \*" | cut -d ' ' -f1)
##@ Docker Images
.PHONY: builder-info
builder-info: ## Print information about the docker builder that will be used for building images.
@echo "Using Docker Buildx builder \"$(DOCKER_BUILDER)\" with build flags \"$(DOCKER_FLAGS)\"."
# Generic rule for augmented .dockerignore files.
GIT_IGNORE_FILES := $(shell find . -not -path "./vendor*" -name .gitignore -print)
.PRECIOUS: %.dockerignore
%.dockerignore: $(GIT_IGNORE_FILES) Makefile.docker
@-mkdir -p $(dir $@)
@echo "/hack" > $@
@echo ".git" >> $@
@echo "/Makefile.docker" >> $@
echo $(dir $(GIT_IGNORE_FILES)) | tr ' ' '\n' | xargs -P1 -n1 -I {DIR} sed \
-e '# Remove lines with white space, comments and files that must be passed to docker, "$$" due to make. #' \
-e '/^[[:space:]]*$$/d' -e '/^#/d' -e '/GIT_VERSION/d' \
-e '# Apply pattern in all directories if it contains no "/", keep "!" up front. #' \
-e '/^[^!/][^/]*$$/s<^<**/<' -e '/^![^/]*$$/s<^!<!**/<' \
-e '# Prepend with the directory name, keep "!" up front. #' \
-e '/^[^!]/s<^<{DIR}<' -e '/^!/s<^!<!{DIR}<'\
-e '# Remove leading "./", keep "!" up front. #' \
-e 's<^\./<<' -e 's<^!\./<!<' \
-e '# Append newline to the last line if missing. GNU sed does not do this automatically. #' \
-e '$$a\' \
{DIR}.gitignore >> $@
DOCKER_REGISTRY ?= quay.io
ifeq ($(findstring /,$(DOCKER_DEV_ACCOUNT)),/)
# DOCKER_DEV_ACCOUNT already contains '/', assume it specifies a registry
IMAGE_REPOSITORY := $(DOCKER_DEV_ACCOUNT)
else
IMAGE_REPOSITORY := $(DOCKER_REGISTRY)/$(DOCKER_DEV_ACCOUNT)
endif
#
# Template for Docker images. Paramaters are:
# $(1) image target name
# $(2) Dockerfile path
# $(3) image name stem (e.g., cilium, cilium-operator, etc)
# $(4) image tag
#
define DOCKER_IMAGE_TEMPLATE
.PHONY: $(1)
$(1): $(2) $(2).dockerignore builder-info
$(eval IMAGE_NAME := $(subst %,$$$$*,$(3))$(UNSTRIPPED))
$(QUIET)docker buildx build -f $(subst %,$$*,$(2)) \
$(DOCKER_FLAGS) \
--build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(IMAGE_REPOSITORY)/$(IMAGE_NAME):$(4) .
ifeq ($(findstring --push,$(DOCKER_FLAGS)),)
@echo 'Define "DOCKER_FLAGS=--push" to push the build results.'
else
docker buildx imagetools inspect $(IMAGE_REPOSITORY)/$(IMAGE_NAME):$(4)
@echo '^^^ Images pushed, multi-arch manifest should be above. ^^^'
endif
endef
# docker-tetragon-operator-image
$(eval $(call DOCKER_IMAGE_TEMPLATE,docker-tetragon-operator-image,./operator.Dockerfile,tetragon-operator,$(DOCKER_IMAGE_TAG)))
#
# docker-*-all targets are mainly used from the CI
#
docker-images-all: docker-tetragon-operator-image