-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
125 lines (107 loc) · 4.32 KB
/
Makefile
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Shortcut targets
default: image
## Build binary for current platform
all: image-all
###############################################################################
# Both native and cross architecture builds are supported.
# The target architecture is select by setting the ARCH variable.
# When ARCH is undefined it is set to the detected host architecture.
# When ARCH differs from the host architecture a crossbuild will be performed.
ARCHES = amd64 arm64 ppc64le s390x
# BUILDARCH is the host architecture
# ARCH is the target architecture
# we need to keep track of them separately
BUILDARCH ?= $(shell uname -m)
# canonicalized names for host architecture
ifeq ($(BUILDARCH),aarch64)
BUILDARCH=arm64
endif
ifeq ($(BUILDARCH),x86_64)
BUILDARCH=amd64
endif
# unless otherwise set, I am building for my own architecture, i.e. not cross-compiling
ARCH ?= $(BUILDARCH)
# canonicalized names for target architecture
ifeq ($(ARCH),aarch64)
override ARCH=arm64
endif
ifeq ($(ARCH),x86_64)
override ARCH=amd64
endif
###############################################################################
VERSION ?= v7.4.0
DEFAULTORG ?= calico
DEFAULTIMAGE ?= $(DEFAULTORG)/bpftool:$(VERSION)
ARCHIMAGE ?= $(DEFAULTIMAGE)-$(ARCH)
BPFTOOLIMAGE ?= $(DEFAULTIMAGE)-$(BUILDARCH)
SOURCEREF ?= $(VERSION)
SOURCEREPO ?= https://github.com/libbpf/bpftool.git
MANIFEST_TOOL_VERSION := v0.7.0
MANIFEST_TOOL_DIR := $(shell mktemp -d)
export PATH := $(MANIFEST_TOOL_DIR):$(PATH)
space :=
space +=
comma := ,
prefix_linux = $(addprefix linux/,$(strip $(subst armv,arm/v,$1)))
join_platforms = $(subst $(space),$(comma),$(call prefix_linux,$(strip $1)))
# Check if the docker daemon is running in experimental mode (to get the --squash flag)
DOCKER_EXPERIMENTAL=$(shell docker version -f '{{ .Server.Experimental }}')
DOCKER_BUILD_ARGS=
ifeq ($(DOCKER_EXPERIMENTAL),true)
override DOCKER_BUILD_ARGS=--squash
endif
###############################################################################
# Building the image
###############################################################################
image: $(DEFAULTORG)/bpftool
$(DEFAULTORG)/bpftool: register
# Make sure we re-pull the base image to pick up security fixes.
docker build $(DOCKER_BUILD_ARGS) --platform=linux/$(ARCH) --build-arg SOURCE_REF=$(SOURCEREF) --build-arg SOURCE_REPO=$(SOURCEREPO) --pull -t $(ARCHIMAGE) -f Dockerfile .
image-all: $(addprefix sub-image-,$(ARCHES))
sub-image-%:
$(MAKE) image ARCH=$*
# Enable binfmt adding support for miscellaneous binary formats.
.PHONY: register
register:
ifeq ($(ARCH),amd64)
docker run --rm --privileged multiarch/qemu-user-static:register --reset
endif
push: image
docker push $(ARCHIMAGE)
# to handle default case, because quay.io does not support manifest yet
ifeq ($(ARCH),amd64)
docker tag $(ARCHIMAGE) quay.io/$(DEFAULTIMAGE)
docker push quay.io/$(DEFAULTIMAGE)
endif
push-all: $(addprefix sub-push-,$(ARCHES))
sub-push-%:
$(MAKE) push ARCH=$*
push-manifest:
# Docker login to hub.docker.com required before running this target as we are using $(HOME)/.docker/config.json holds the docker login credentials
docker run -t --entrypoint /bin/sh -v $(HOME)/.docker/config.json:/root/.docker/config.json $(ARCHIMAGE) -c "/usr/bin/manifest-tool push from-args --platforms $(call join_platforms,$(ARCHES)) --template $(DEFAULTIMAGE)-ARCHVARIANT --target $(DEFAULTIMAGE)"
###############################################################################
# UTs
###############################################################################
test:
docker run --rm $(BPFTOOLIMAGE) /bpftool version | grep -q "bpftool v"
@echo "success"
###############################################################################
# CI
###############################################################################
.PHONY: ci
## Run what CI runs
ci: image-all test
###############################################################################
# CD
###############################################################################
.PHONY: cd
## Deploys images to registry
cd:
ifndef CONFIRM
$(error CONFIRM is undefined - run using make <target> CONFIRM=true)
endif
ifndef BRANCH_NAME
$(error BRANCH_NAME is undefined - run using make <target> BRANCH_NAME=var or set an environment variable)
endif
$(MAKE) push-all VERSION=${BRANCH_NAME}
$(MAKE) push-manifest VERSION=${BRANCH_NAME}