-
Notifications
You must be signed in to change notification settings - Fork 141
/
Makefile
117 lines (98 loc) · 3.54 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
include ../common.mk
PLUGINS_DIR=$(realpath $(CURDIR)/../plugins)
GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/cli) && git rev-parse --short HEAD)
CLI_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/cli) && git rev-parse --short HEAD)
ENGINE_GITCOMMIT?=$(shell cd $(realpath $(CURDIR)/../src/github.com/docker/docker) && git rev-parse --short HEAD)
GO_BASE_IMAGE=golang
GO_IMAGE?=$(GO_BASE_IMAGE):$(GO_VERSION)-buster
GEN_DEB_VER=$(shell ./gen-deb-ver $(realpath $(CURDIR)/../src/github.com/docker/cli) "$(VERSION)")
EPOCH?=5
DOCKER_BUILDKIT=1
BUILD_TARGET=final
ifdef BUILD_IMAGE
BUILD_IMAGE_FLAG=--build-arg $(BUILD_IMAGE)
endif
COMMON_FILES=common
BUILD?=DOCKER_BUILDKIT=1 \
docker build \
$(BUILD_IMAGE_FLAG) \
--build-arg GO_IMAGE=$(GO_IMAGE) \
--build-arg COMMON_FILES=$(COMMON_FILES) \
--build-arg VERSION=$(word 2, $(DEB_VERSION)) \
--build-arg DOCKER_GITCOMMIT=$(GITCOMMIT) \
--build-arg PLATFORM \
--target=$(BUILD_TARGET) \
$(BUILD_OPTS) \
-t debbuild-$@/$(ARCH) \
-f $@/Dockerfile \
.
# Additional flags may be necessary at some point
RUN_FLAGS=
RUN?=docker run --rm \
-e PLATFORM \
-e EPOCH='$(EPOCH)' \
-e DEB_VERSION=$(word 1, $(GEN_DEB_VER)) \
-e VERSION=$(word 2, $(GEN_DEB_VER)) \
-e CLI_GITCOMMIT=$(CLI_GITCOMMIT) \
-e ENGINE_GITCOMMIT=$(ENGINE_GITCOMMIT) \
-v $(CURDIR)/debbuild/$@:/build \
$(RUN_FLAGS) \
debbuild-$@/$(ARCH)
DEBIAN_VERSIONS ?= debian-buster debian-bullseye
UBUNTU_VERSIONS ?= ubuntu-xenial ubuntu-bionic ubuntu-focal ubuntu-groovy
RASPBIAN_VERSIONS ?= raspbian-buster raspbian-bullseye
DISTROS := $(DEBIAN_VERSIONS) $(UBUNTU_VERSIONS) $(RASPBIAN_VERSIONS)
.PHONY: help
help: ## show make targets
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: clean
clean: ## remove build artifacts
[ ! -d debbuild ] || $(CHOWN) -R $(shell id -u):$(shell id -g) debbuild
$(RM) -r debbuild
[ ! -d sources ] || $(CHOWN) -R $(shell id -u):$(shell id -g) sources
$(RM) -r sources
-docker builder prune -f --filter until=24h
.PHONY: deb
deb: ubuntu debian ## build all deb packages except for raspbian
.PHONY: binaries
binaries: BUILD_TARGET=binaries
binaries: BUILD_OPTS=--output type=local,dest=build
binaries: deb
.PHONY: ubuntu
ubuntu: $(UBUNTU_VERSIONS) ## build all ubuntu deb packages
.PHONY: debian
debian: $(DEBIAN_VERSIONS) ## build all debian deb packages
.PHONY: raspbian
raspbian: $(RASPBIAN_VERSIONS) ## build all raspbian deb packages
.PHONY: $(DISTROS)
$(DISTROS): sources/cli.tgz sources/engine.tgz sources/docker.service sources/docker.socket sources/plugin-installers.tgz
@echo "== Building packages for $@ =="
$(BUILD)
# $(RUN)
# $(CHOWN) -R $(shell id -u):$(shell id -g) debbuild/$@
sources/engine.tgz:
mkdir -p $(@D)
docker run --rm -w /v \
-v $(realpath $(CURDIR)/../src/github.com/docker/docker):/engine \
-v $(CURDIR)/$(@D):/v \
alpine \
tar -C / -c -z -f /v/engine.tgz --exclude .git engine
sources/cli.tgz:
mkdir -p $(@D)
docker run --rm -w /v \
-v $(realpath $(CURDIR)/../src/github.com/docker/cli):/cli \
-v $(CURDIR)/$(@D):/v \
alpine \
tar -C / -c -z -f /v/cli.tgz --exclude .git cli
sources/docker.service: ../systemd/docker.service
mkdir -p $(@D)
cp $< $@
sources/docker.socket: ../systemd/docker.socket
mkdir -p $(@D)
cp $< $@
sources/plugin-installers.tgz: $(wildcard ../plugins/*)
docker run --rm -w /v \
-v $(PLUGINS_DIR):/plugins \
-v $(CURDIR)/$(@D):/v \
alpine \
tar -C / -c -z -f /v/plugin-installers.tgz --exclude .git plugins