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
|
#
# Docker-related targets
#
# Intended for internal use to publish Docker images to docker hub. Likely need to run
# "docker login" before any push commands.
#
# Examples:
#
# Publish to Dockerhub "freeradius-server"
# make DOCKER_VERSION=3.2.0 DOCKER_BUILD_ARGS="--no-cache" docker-publish
#
# Build and push "freeradius-dev" image to Dockerhub (e.g. CI on every commit):
# make DOCKER_VERSION=latest DOCKER_COMMIT=v3.2.x DOCKER_TAG="freeradius-dev-3.2.x" DOCKER_BUILD_ARGS="--no-cache" docker-push
#
# Push to local repository:
# make DOCKER_VERSION=3.2.0 DOCKER_TAG="our-freeradius-build" DOCKER_REGISTRY="docker.somewhere.example" docker-publish
#
# See what is going to happen:
# make Q=": " ...
#
#
# Variables:
#
# Which version to tag as, e.g. "3.2.0". If this is not an actual release
# version, DOCKER_COMMIT _must_ also be set.
DOCKER_VERSION := $(RADIUSD_VERSION_STRING)
#
# Commit hash/tag/branch to build, if not set then HEAD will be used.
DOCKER_COMMIT :=
#
# Build args, most likely "--no-cache"
DOCKER_BUILD_ARGS :=
#
# Tag name, likely "freeradius-server" for releases, or "freeradius-dev" for nightlies.
DOCKER_TAG := freeradius-server
#
# Repository name
DOCKER_REPO := freeradius
#
# Registry to push to
DOCKER_REGISTRY :=
#
# Location of Docker-related files
DOCKER_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
DIST_DIR := $(DOCKER_DIR)/dists
#
# List of images we can build
DOCKER_IMAGES:=$(sort $(patsubst $(DIST_DIR)/%,%,$(wildcard $(DIST_DIR)/*)))
DOCKER_DEFAULT_UBUNTU := ubuntu22
DOCKER_DEFAULT_ALPINE := alpine
ifeq "${VERBOSE}" ""
Q=@
else
Q=
endif
ifneq "$(DOCKER_REPO)" ""
override DOCKER_REPO := $(DOCKER_REPO)/
endif
ifneq "$(DOCKER_REGISTRY)" ""
override DOCKER_REGISTRY := $(DOCKER_REGISTRY)/
endif
#
# Print some useful help
#
.PHONY: docker.help.images
docker.help.images:
@echo Available images: $(DOCKER_IMAGES)
.PHONY: docker.help
docker.help: docker.help.images
@echo ""
@echo "Make targets:"
@echo " docker-ubuntu - build main ubuntu image"
@echo " docker-alpine - build main alpine image"
@echo " docker.regen - regenerate all Dockerfiles from templates"
@echo ""
@echo "Make targets per image:"
@echo " docker.IMAGE.build - build image"
@echo " docker.IMAGE.regen - regenerate Dockerfile"
@echo ""
@echo "Arguments:"
@echo ' DOCKER_BUILD_ARGS="--no-cache" - extra build args'
@echo ' DOCKER_REGISTRY="docker.example.com" - registry to build for'
@echo ' DOCKER_REPO="freeradius" - docker repo name'
@echo ' DOCKER_TAG="freeradius-server" - docker tag name'
@echo ' DOCKER_COMMIT="HEAD" - commit/ref to build from'
@echo ' DOCKER_VERSION="$(DOCKER_VERSION)" - version for docker image name'
#
# Rules for each OS
#
define ADD_DOCKER_RULES
$$(DIST_DIR)/${1}/Dockerfile: $(DOCKER_DIR)/m4/Dockerfile.m4 $(DOCKER_DIR)/m4/Dockerfile.deb.m4 $(DOCKER_DIR)/m4/Dockerfile.rpm.m4 $(DOCKER_DIR)/m4/Dockerfile.alpine.m4 $(DOCKER_DIR)/docker.mk
$$(Q)echo REGEN ${1}/Dockerfile
$$(Q)m4 -I $(DOCKER_DIR)/m4 -D D_NAME=${1} -D D_TYPE=docker $$< > $$@
DOCKER_DOCKERFILES += $$(DIST_DIR)/${1}/Dockerfile
.PHONY: docker.${1}.regen
docker.${1}.regen: $$(DIST_DIR)/${1}/Dockerfile
.PHONY: docker.${1}.build
docker.${1}.build:
@echo BUILD ${1} $(DOCKER_COMMIT)
$(Q)docker buildx build \
$(DOCKER_BUILD_ARGS) \
--progress=plain \
--build-arg=release=$(DOCKER_COMMIT) \
-t $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-${1} \
-f $(DIST_DIR)/${1}/Dockerfile \
.
endef
$(foreach IMAGE,$(DOCKER_IMAGES), \
$(eval $(call ADD_DOCKER_RULES,$(IMAGE))))
.PHONY: docker.regen
docker.regen: $(DOCKER_DOCKERFILES)
#
# Rules to rebuild Docker images
#
.PHONY: docker-ubuntu
docker-ubuntu: docker.$(DOCKER_DEFAULT_UBUNTU).build
$(Q)docker image tag \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-$(DOCKER_DEFAULT_UBUNTU) \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)
.PHONY: docker-alpine
docker-alpine: docker.$(DOCKER_DEFAULT_ALPINE).build
$(Q)docker image tag \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-$(DOCKER_DEFAULT_ALPINE) \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-alpine
.PHONY: docker
docker: docker-ubuntu docker-alpine
#
# Push main ubuntu and alpine images (all below are separate for CI jobs)
#
.PHONY: docker-push-ubuntu
docker-push-ubuntu:
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)
.PHONY: docker-push-alpine
docker-push-alpine:
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-alpine
.PHONY: docker-push
docker-push: docker-push-ubuntu docker-push-alpine
#
# Tag main "latest" images
#
.PHONY: docker-tag-latest-ubuntu
docker-tag-latest-ubuntu:
$(Q)docker tag $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION) $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest
$(Q)docker tag $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION) $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-3.2
.PHONY: docker-tag-latest-alpine
docker-tag-latest-alpine:
$(Q)docker tag $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-alpine $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-alpine
$(Q)docker tag $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)-alpine $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-3.2-alpine
.PHONY: docker-tag-latest
docker-tag-latest: docker-tag-latest-ubuntu docker-tag-latest-alpine
#
# Push main "latest" images
#
.PHONY: docker-push-latest-ubuntu
docker-push-latest-ubuntu: docker-push-ubuntu docker-tag-latest-ubuntu
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-3.2
.PHONY: docker-push-latest-alpine
docker-push-latest-alpine: docker-push-alpine docker-tag-latest-alpine
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-alpine
$(Q)docker push $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):latest-3.2-alpine
.PHONY: docker-push-latest
docker-push-latest: docker-push-latest-ubuntu docker-push-latest-alpine
#
# Convenience target to do everything
#
.PHONY: docker-publish
docker-publish: docker docker-push-latest
#
# Used for multi-arch CI job. "docker manifest" rather than "docker buildx
# --platforms=...,..." so that we can parallelise the build in GH Actions.
#
.PHONY: docker-ci-manifest
docker-ci-manifest:
$(Q)docker manifest create \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION) \
$(foreach ARCH,$(DOCKER_ARCHS),--amend $(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(ARCH)-$(DOCKER_VERSION))
$(Q)docker manifest push \
$(DOCKER_REGISTRY)$(DOCKER_REPO)$(DOCKER_TAG):$(DOCKER_VERSION)
|