forked from redis/docker-library-redis
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.withcross
executable file
·326 lines (252 loc) · 7.68 KB
/
Makefile.withcross
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
.NOTPARALLEL:
MAKEFLAGS += --no-builtin-rules --no-print-directory
ifeq ($(NOP),1)
override NOP:=echo
endif
ifeq ($(filter help,$(MAKECMDGOALS)),help)
_HELP:=1
help:
$(file >/tmp/help,$(HELP))
@cat /tmp/help
@rm -f /tmp/help
endif
#----------------------------------------------------------------------------------------------
STD_MAJORS=7.2 7.0 6.2 6.0 5.0
ifeq ($(VERSION),)
ifeq ($(VERSIONS),)
ifeq ($(STD_VERSIONS),)
STD_VERSIONS=1
endif
endif
endif
ifneq ($(filter help,$(MAKECMDGOALS)),help)
ifeq ($(STD_VERSIONS),1)
override VERSIONS:=$(foreach V,$(STD_MAJORS),$(shell ./deps/readies/bin/github-lastver -r redis/redis -v $(V)))
endif
endif
ifneq ($(VERSIONS),)
ifeq ($(word 2,$(VERSIONS)),)
override VERSION:=$(VERSIONS)
override VERSIONS:=
else
VERSIONS += $(VERSION)
override VERSION:=
endif
else # ! VERSIONS
ifeq ($(patsubst 4%,4,$(VERSION)),4)
MAJOR=6.0
else ifeq ($(patsubst 5%,5,$(VERSION)),5)
MAJOR=5.0
else ifeq ($(patsubst 6.0%,6.0,$(VERSION)),6.0)
MAJOR=6.0
else ifeq ($(patsubst 6.2%,6.2,$(VERSION)),6.2)
MAJOR=6.2
else ifeq ($(patsubst 7.0%,7.0,$(VERSION)),7.0)
MAJOR=7.0
else ifeq ($(patsubst 7.2%,7.2,$(VERSION)),7.2)
MAJOR=7.2
else
ifneq ($(_HELP),1)
$(info Strange Redis version: $(VERSION))
endif
endif
endif
# LATEST=1
# MASTER=1
#----------------------------------------------------------------------------------------------
ARCH:=$(shell ./deps/readies/bin/platform --arch)
ifeq ($(ARCH),x64)
#
else ifeq ($(CROSS),1)
$(error Cannot cross-build on ARM)
endif
#----------------------------------------------------------------------------------------------
OS ?= debian:buster-slim
# OSNICK=buster|stretch|trusty|xenial|bionic|centos6|centos7|centos8|fedora
OSNICK ?= buster
OS.trusty=ubuntu:trusty
OS.xenial=ubuntu:xenial
OS.bionic=ubuntu:bionic
OS.jammy=ubuntu:jammy
OS.focal=ubuntu:focal
OS.hirsute=ubuntu:hirsute
OS.stretch=debian:stretch-slim
OS.buster=debian:buster-slim
OS.bullseye=debian:bullseye-slim
OS.centos6=centos:6
OS.centos7=centos:7
OS.centos8.4=centos:8.4
OS.centos8=quay.io/centos/centos:stream8
OS.centos9=quay.io/centos/centos:stream9
OS.ol7=oraclelinux:7
OS.ol8=oraclelinux:8
OS.amzn2=amazonlinux:2
OS.amzn2022=amazonlinux:2022
OS.alma8=almalinux:8
OS.rocky8=rockylinux:8
OS.fedora=fedora:latest
OS.alpine3=alpine:3
OS.alpineedge=alpine:edge
#OS.rawhide=fedora:latest
OS.rhel7.4=rhel:7.4
OS.mariner2.0=mcr.microsoft.com/cbl-mariner/base/core:2.0
OS.alpine3=alpine:3
OS.alpineedge=alpine:edge
OS.jammy=ubuntu:jammy
OS=$(OS.$(OSNICK))
ifeq ($(OS),)
$(error Probably wrong OSNICK specified ($(OSNICK)))
endif
#----------------------------------------------------------------------------------------------
UID.centos7=997
UID.centos8.4=996
UID.centos8=996
UID.centos9=999
UID.ol7=995
UID.ol8=995
UID.alma8=996
UID.rocky8=994
UID.fedora=989
UID.rhel7.4=800
UID.alpine3=800
UID.alpineedge=800
ifeq ($(UID.$(OSNICK)),)
UID=999
else
UID=$(UID.$(OSNICK))
endif
#----------------------------------------------------------------------------------------------
REPO=redisfab
STEM=$(REPO)/redis
DOCKER ?= docker
BUILD_OPT=--rm --load --progress=plain
# --squash
ifeq ($(ARCH),arm64v8)
BUILD_OPT += --allow security.insecure
endif
ifeq ($(CACHE),0)
CACHE_ARG=--no-cache
endif
#----------------------------------------------------------------------------------------------
ifneq ($(CROSS),1)
define targets # (1=OP, 2=op)
$(1)_TARGETS :=
$(1)_TARGETS += $(2)_native
endef
else # cross
define targets # (1=OP, 2=op)
$(1)_TARGETS :=
$(1)_TARGETS += $(if $(findstring $(X64),1),$(2)_native)
$(1)_TARGETS += $(if $(findstring $(ARM7),1),$(2)_arm32v7)
$(1)_TARGETS += $(if $(findstring $(ARM8),1),$(2)_arm64v8)
$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_arm32v7 $(2)_arm64v8)
endef
endif # cross
#----------------------------------------------------------------------------------------------
ifneq ($(VERSIONS),)
GOALS:=$(filter $(MAKECMDGOALS),build publish)
versions: $(foreach V,$(VERSIONS),version_$(V))
build: versions
publish: build
.PHONY: build publish
define make_version
version_$(1):
@$(MAKE) VERSION=$(1) STD_VERSIONS="" VERSIONS="" $(GOALS)
.PHONY: version_$(1)
endef
$(foreach V,$(VERSIONS),$(eval $(call make_version,$(V))))
else # ! VERSIONS
ifneq ($(_HELP),1)
ifeq ($(VERSION),)
$(error VERSION not specified)
endif
endif
$(eval $(call targets,BUILD,build))
$(eval $(call targets,PUBLISH,publish))
endif
#----------------------------------------------------------------------------------------------
define build_native
build_native:
@./deps/readies/bin/sep
@echo "Building $(STEM):$(VERSION)-$(ARCH)-$(OSNICK) ..."
@$(NOP) $(DOCKER) pull $(OS)
@$(NOP) $(DOCKER) buildx build $(BUILD_OPT) -t $(STEM):$(VERSION)-$(ARCH)-$(OSNICK) -f $(MAJOR)/Dockerfile \
$(CACHE_ARG) \
--build-arg ARCH=$(ARCH) \
--build-arg OS=$(OS) \
--build-arg OSNICK=$(OSNICK) \
--build-arg UID=$(UID) \
--build-arg REDIS_VER=$(VERSION) \
--build-arg REDIS_MAJOR=$(MAJOR) \
.
@$(NOP) $(DOCKER) tag $(STEM):$(VERSION)-$(ARCH)-$(OSNICK) $(STEM):$(MAJOR)-latest-$(ARCH)-$(OSNICK)
.PHONY: build_native
endef
define build_arm # (1=arch)
build_$(1):
@./deps/readies/bin/sep
@echo "Building $(STEM):$(VERSION)-$(ARCH)-$(OSNICK) ..."
@$(NOP) $(DOCKER) build $(BUILD_OPT) -t $(STEM)-xbuild:$(VERSION)-$(1)-$(OSNICK) -f $(MAJOR)/Dockerfile.arm \
--build-arg ARCH=$(1) \
--build-arg OSNICK=$(OSNICK) \
--build-arg UID=$(UID) \
--build-arg REDIS_VER=$(VERSION) \
--build-arg REDIS_MAJOR=$(MAJOR) \
.
@$(NOP) $(DOCKER) tag $(STEM)-xbuild:$(VERSION)-$(1)-$(OSNICK) $(STEM)-xbuild:$(MAJOR)-latest-$(1)-$(OSNICK)
.PHONY: build_$(1)
endef
#----------------------------------------------------------------------------------------------
define publish_native
publish_native:
@$(NOP) $(DOCKER) push $(STEM):$(VERSION)-$(ARCH)-$(OSNICK)
@$(NOP) $(DOCKER) push $(STEM):$(MAJOR)-latest-$(ARCH)-$(OSNICK)
.PHONY: publish_native
endef
define publish_arm # (1=arch)
publish_$(1):
@$(NOP) $(DOCKER) push $(STEM)-xbuild:$(VERSION)-$(1)-$(OSNICK)
@$(NOP) $(DOCKER) push $(STEM)-xbuild:$(MAJOR)-latest-$(1)-$(OSNICK)
.PHONY: publish_$(1)
endef
#----------------------------------------------------------------------------------------------
build: insecure-build $(BUILD_TARGETS)
ifeq ($(ARCH),arm64v8)
insecure-build:
@$(NOP) $(DOCKER) buildx create --use --name insecure-builder --buildkitd-flags '--allow-insecure-entitlement security.insecure' || true
else
insecure-build: ;
endif
$(eval $(call build_native))
ifeq ($(CROSS),1)
$(eval $(call build_arm,arm64v8))
$(eval $(call build_arm,arm32v7))
endif
publish: $(PUBLISH_TARGETS)
$(eval $(call publish_native))
ifeq ($(CROSS),1)
$(eval $(call publish_arm,arm64v8))
$(eval $(call publish_arm,arm32v7))
endif
#----------------------------------------------------------------------------------------------
define HELP
make [build|publish] [X64=1|ARM8=1|ARM7=1] [OSNICK=<nick> | OS=<os>]
[VERSION=<ver> | VERSIONS="<ver>..."]
[STD_VERSIONS=1]
[CROSS=1]
build Build image(s)
publish Push image(s) to Docker Hub
Arguments:
OSNICK=nick nick=buster|stretch|xenial|bionic|centos6|centos7|centos8|fedora
OS=os (optional) OS Docker image name (e.g., debian:buster-slim)
VERSION=ver Redis version
VERSIONS="vers..." Multiple Redis versions
STD_VERSIONS=1 Build latest versions of 6.0 and 6.2 branches
MASTER=1 Build sources from master branch ("edge" version)
LATEST=1 Build the latest version of branch given by VERSION
TEST=1 Run tests after build
CACHE=0 Build without cache
CROSS=1 Perform cross-platform builds (typically, ARM7/8 on x64)
endef
#----------------------------------------------------------------------------------------------
.PHONY: all build publish help insecure-build