-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
211 lines (187 loc) · 7.73 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
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
SHELL = /bin/sh
ifeq (, $(shell which jq))
$(error "jq not found!")
endif
ifeq (, $(shell which nproc))
$(error "nproc not found!")
endif
# Override these if you like
ERLANG_VERSIONS :=
ERLANG_ITERATION := 1
ELIXIR_VERSIONS :=
ELIXIR_ITERATION := 1
MONGOOSEIM_VERSIONS :=
MONGOOSEIM_ITERATION := 1
PLATFORMS := linux/amd64 linux/arm64
DEBIAN_VERSIONS :=
UBUNTU_VERSIONS :=
CENTOS_VERSIONS :=
ALMALINUX_VERSIONS :=
AMAZONLINUX_VERSIONS :=
ROCKYLINUX_VERSIONS :=
FEDORA_VERSIONS :=
CACHE_FROM = type=local,src=cache/$(OS)/$(OS_VERSION)
CACHE_TO = type=local,dest=cache/$(OS)/$(OS_VERSION)
OUTPUT = type=local,dest=build/$(OS)/$(OS_VERSION)
# Consult github remote to get latest maintenance tags
override ERLANG_MAINTS = \
$(shell git ls-remote --tags --sort=-version:refname https://github.com/erlang/otp 'OTP-[2-9][0-9]*' | \
grep "$$(git ls-remote --heads https://github.com/erlang/otp 'maint-[2-9][0-9]*' | awk '{print $$1}')" | \
grep -Eo '[0-9]+\.[0-9.]+')
override ELIXIR_LATEST = \
$(shell curl --fail https://api.github.com/repos/elixir-lang/elixir/releases?per_page=1 | jq -r '.[] | .tag_name')
override MONGOOSEIM_LATEST = \
$(shell curl --fail https://api.github.com/repos/esl/MongooseIM/releases?per_page=1 | jq -r '.[] | .tag_name')
override DEBIANS = $(foreach v,$(DEBIAN_VERSIONS),debian_$(v))
override UBUNTUS = $(foreach v,$(UBUNTU_VERSIONS),ubuntu_$(v))
override CENTOSES = $(foreach v,$(CENTOS_VERSIONS),centos_$(v))
override ALMALINUXES = $(foreach v,$(ALMALINUX_VERSIONS),almalinux_$(v))
override AMAZONLINUXES = $(foreach v,$(AMAZONLINUX_VERSIONS),amazonlinux_$(v))
override ROCKYLINUXES = $(foreach v,$(ROCKYLINUX_VERSIONS),rockylinux_$(v))
override FEDORAS = $(foreach v,$(FEDORA_VERSIONS),fedora_$(v))
override ERLANG_IMAGE_TAGS = $(DEBIANS) $(UBUNTUS) $(CENTOSES) $(ALMALINUXES) $(AMAZONLINUXES) $(ROCKYLINUXES) $(FEDORAS)
override ELIXIR_IMAGE_TAGS = debian_buster centos_8
override ERLANG_BUILDS = $(foreach erlang,$(ERLANG_VERSIONS),$(foreach image_tag,$(ERLANG_IMAGE_TAGS),$(foreach platform,$(subst /,-,$(PLATFORMS)),erlang_$(erlang)_$(image_tag)_$(platform))))
override ELIXIR_BUILDS = $(foreach elixir,$(ELIXIR_VERSIONS),$(foreach image_tag,$(ELIXIR_IMAGE_TAGS),elixir_$(elixir)_$(image_tag)))
override LATEST_DEBIAN := buster
override LATEST_UBUNTU := focal
override LATEST_CENTOS := 8
override LATEST_FEDORA := 34
override FULL_DEBIAN := bullseye buster stretch
override FULL_UBUNTU := focal bionic xenial trusty
override FULL_CENTOS := 8 7
override FULL_FEDORA := 34 33
override ELIXIR_OTP := 22.3.4.9-1
override DEFAULT_ELIXIR := 12.2_$(ELIXIR_OTP)
.PHONY: custom
custom: $(ERLANG_BUILDS) $(ELIXIR_BUILDS)
ERLANG_VERSIONS = $(ERLANG_MAINTS)
ELIXIR_VERSIONS = $(ELIXIR_LATEST)
DEBIAN_VERSIONS = $(LATEST_DEBIAN)
UBUNTU_VERSIONS = $(LATEST_UBUNTU)
CENTOS_VERSIONS = $(LATEST_CENTOS)
FEDORA_VERSIONS = $(LATEST_FEDORA)
.PHONY: latest
latest: $(ERLANG_BUILDS) $(ELIXIR_BUILDS)
ERLANG_VERSIONS = $(ERLANG_MAINTS)
ELIXIR_VERSIONS = $(DEFAULT_ELIXIR)
DEBIAN_VERSIONS = $(FULL_DEBIAN)
UBUNTU_VERSIONS = $(FULL_UBUNTU)
CENTOS_VERSIONS = $(FULL_CENTOS)
FEDORA_VERSIONS = $(FULL_FEDORA)
.PHONY: full
full: $(ERLANG_BUILDS) $(ELIXIR_BUILDS)
ERLANG_VERSIONS =
ELIXIR_VERSIONS = $(DEFAULT_ELIXIR)
DEBIAN_VERSIONS = $(LATEST_DEBIAN)
UBUNTU_VERSIONS = $(LATEST_UBUNTU)
CENTOS_VERSIONS = $(LATEST_CENTOS)
FEDORA_VERSIONS = $(LATEST_FEDORA)
.PHONY: single
single: $(ERLANG_BUILDS)
erlang_%: ERLANG_VERSION = $(strip $(subst latest, $(word 1,$(ERLANG_MAINTS)), $(word 2,$(subst _, ,$@))))
# erlang_%: ERLANG_VERSION = $(strip $(subst latest, 25.0.3, $(word 2,$(subst _, ,$@))))
erlang_%: OS = $(word 3,$(subst _, ,$@))
erlang_%: OS_VERSION = $(word 4,$(subst _, ,$@))
erlang_%: IMAGE = $(OS):$(OS_VERSION)
erlang_%: PLATFORM = $(subst -,/,$(word 5,$(subst _, ,$@)))
erlang_%: BUILDER = esl-buildx-erlang
erlang_%: JOBS = $(shell nproc)
.PHONY: erlang_%
erlang_%:
@echo "Building erlang $(ERLANG_VERSION) for $(OS) $(OS_VERSION) $(PLATFORM) with dockerfile builder/erlang_$(OS).Dockerfile and image $(IMAGE)"
@docker buildx create --name "$(BUILDER)" --platform "$(PLATFORM)" >/dev/null 2>&1 || true
@echo "Builder created"
@date +%s > [email protected]
@docker buildx build \
--platform "$(PLATFORM)" \
--builder "$(BUILDER)" \
--build-arg jobs="$(JOBS)" \
--build-arg gpg_pass="$(GPG_PASS)" \
--build-arg gpg_key_id="$(GPG_KEY_ID)" \
--build-arg image="$(IMAGE)" \
--build-arg TARGETPLATFORM="$(PLATFORM)" \
--build-arg os="$(OS)" \
--build-arg os_version="$(OS_VERSION)" \
--build-arg erlang_version="$(ERLANG_VERSION)" \
--build-arg erlang_iteration="$(ERLANG_ITERATION)" \
--cache-from="$(CACHE_FROM)" \
--cache-to="$(CACHE_TO)" \
--output "$(OUTPUT)" \
--file "builders/erlang_$(OS).Dockerfile" \
.
@date +%s > [email protected]
elixir_%: ELIXIR_VERSION = $(strip $(subst v, ,$(subst latest, $(ELIXIR_LATEST), $(word 2,$(subst _, ,$@)))))
elixir_%: ERLANG_VERSION = $(strip $(subst latest, $(word 1, $(ERLANG_MAINTS)), $(word 3,$(subst _, ,$@))))
elixir_%: OS = $(word 4,$(subst _, ,$@))
elixir_%: OS_VERSION = $(word 5,$(subst _, ,$@))
elixir_%: PLATFORM = $(subst -,/,$(word 6,$(subst _, ,$@)))
elixir_%: IMAGE = $(OS):$(OS_VERSION)
elixir_%: BUILDER = esl-buildx-elixir
elixir_%: JOBS = $(shell nproc)
.PHONY: elixir_%
elixir_%:
@echo "Building elixir $(ELIXIR_VERSION) against erlang $(ERLANG_VERSION) for $(OS) $(OS_VERSION) $(PLATFORM) with dockerfile builder/elixir_$(OS).Dockerfile"
@docker buildx create --name "$(BUILDER)" >/dev/null 2>&1 || true
@echo "Builder created"
@date +%s > [email protected]
@docker buildx build \
--platform "$(PLATFORM)" \
--builder "$(BUILDER)" \
--build-arg jobs="$(JOBS)" \
--build-arg image="$(IMAGE)" \
--build-arg os="$(OS)" \
--build-arg os_version="$(OS_VERSION)" \
--build-arg gpg_key_id="$(GPG_KEY_ID)" \
--build-arg gpg_pass="$(GPG_PASS)" \
--build-arg TARGETPLATFORM="$(PLATFORM)" \
--build-arg erlang_version="$(ERLANG_VERSION)" \
--build-arg elixir_version="$(ELIXIR_VERSION)" \
--build-arg elixir_iteration="$(ELIXIR_ITERATION)" \
--file "builders/elixir_$(OS).Dockerfile" \
--cache-from="$(CACHE_FROM)" \
--cache-to="$(CACHE_TO)" \
--output "$(OUTPUT)" \
.
@date +%s > [email protected]
mongooseim_%: MONGOOSEIM_VERSION = $(strip $(subst v, ,$(subst latest, $(MONGOOSEIM_LATEST), $(word 2,$(subst _, ,$@)))))
mongooseim_%: ERLANG_VERSION = $(strip $(subst latest, $(word 1, $(ERLANG_MAINTS)), $(word 3,$(subst _, ,$@))))
mongooseim_%: OS = $(word 4,$(subst _, ,$@))
mongooseim_%: OS_VERSION = $(word 5,$(subst _, ,$@))
mongooseim_%: PLATFORM = $(subst -,/,$(word 6,$(subst _, ,$@)))
mongooseim_%: IMAGE = $(OS):$(OS_VERSION)
mongooseim_%: BUILDER = esl-buildx-elixir
mongooseim_%: JOBS = $(shell nproc)
.PHONY: mongooseim_%
mongooseim_%:
@echo "Building mongooseim $(MONGOOSEIM_VERSION) against erlang $(ERLANG_VERSION) for $(OS) $(OS_VERSION) $(PLATFORM) with dockerfile builder/mongooseim_$(OS).Dockerfile"
@docker buildx create --name "$(BUILDER)" >/dev/null 2>&1 || true
@echo "Builder created"
@date +%s > [email protected]
@docker buildx build \
--platform "$(PLATFORM)" \
--builder "$(BUILDER)" \
--build-arg jobs="$(JOBS)" \
--build-arg image="$(IMAGE)" \
--build-arg os="$(OS)" \
--build-arg os_version="$(OS_VERSION)" \
--build-arg gpg_key_id="$(GPG_KEY_ID)" \
--build-arg gpg_pass="$(GPG_PASS)" \
--build-arg TARGETPLATFORM="$(PLATFORM)" \
--build-arg erlang_version="$(ERLANG_VERSION)" \
--build-arg mongooseim_version="$(MONGOOSEIM_VERSION)" \
--build-arg mongooseim_iteration="$(MONGOOSEIM_ITERATION)" \
--file "builders/mongooseim_$(OS).Dockerfile" \
--cache-from="$(CACHE_FROM)" \
--cache-to="$(CACHE_TO)" \
--output "$(OUTPUT)" \
.
@date +%s > [email protected]
.PHONY: clean
clean:
@rm -f *.log *.start *.end
@rm -rf build/
.PHONY: destroy
destroy: clean
@rm -rf cache/
@docker buildx ls | grep docker-container | grep -Eo 'esl-buildx-[a-zA-Z0-9.-]+' | xargs -n1 docker buildx rm