|
|
@@ -10,6 +10,13 @@ space := $(empty) $(empty)
|
|
|
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
|
|
|
$(findstring $(2),$(1))),1)
|
|
|
|
|
|
+# Maps platform identifier to the one accepted by Docker CLI.
|
|
|
+dockerify = $(strip $(if $(call eq,$(1),linux/arm32v6),linux/arm/v6,\
|
|
|
+ $(if $(call eq,$(1),linux/arm32v7),linux/arm/v7,\
|
|
|
+ $(if $(call eq,$(1),linux/arm64v8),linux/arm64/v8,\
|
|
|
+ $(if $(call eq,$(1),linux/i386), linux/386,\
|
|
|
+ $(platform))))))
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -23,10 +30,11 @@ COTURN_MAJ_VER = $(strip $(shell echo $(COTURN_VER) | cut -d '.' -f1))
|
|
|
|
|
|
BUILD_REV ?= 0
|
|
|
|
|
|
-NAMESPACES := coturn \
|
|
|
- ghcr.io/coturn \
|
|
|
- quay.io/coturn
|
|
|
NAME := coturn
|
|
|
+OWNER := $(or $(GITHUB_REPOSITORY_OWNER),coturn)
|
|
|
+REGISTRIES := $(strip $(subst $(comma), ,\
|
|
|
+ $(shell grep -m1 'registry: \["' ../../.github/workflows/docker.yml \
|
|
|
+ | cut -d':' -f2 | tr -d '"][')))
|
|
|
ALL_IMAGES := \
|
|
|
debian:$(COTURN_VER)-r$(BUILD_REV)-debian,$(COTURN_VER)-debian,$(COTURN_MIN_VER)-debian,$(COTURN_MAJ_VER)-debian,debian,$(COTURN_VER)-r$(BUILD_REV),$(COTURN_VER),$(COTURN_MIN_VER),$(COTURN_MAJ_VER),latest \
|
|
|
alpine:$(COTURN_VER)-r$(BUILD_REV)-alpine,$(COTURN_VER)-alpine,$(COTURN_MIN_VER)-alpine,$(COTURN_MAJ_VER)-alpine,alpine
|
|
|
@@ -39,14 +47,6 @@ TAGS ?= $(word 1,$(subst |, ,\
|
|
|
VERSION ?= $(word 1,$(subst -, ,$(TAGS)))-$(word 2,$(strip \
|
|
|
$(subst -, ,$(subst $(comma), ,$(TAGS)))))
|
|
|
|
|
|
-PLATFORMS ?= linux/amd64 \
|
|
|
- linux/arm64 \
|
|
|
- linux/arm/v6 \
|
|
|
- linux/arm/v7 \
|
|
|
- linux/ppc64le \
|
|
|
- linux/s390x
|
|
|
-MAIN_PLATFORM ?= $(word 1,$(subst $(comma), ,$(PLATFORMS)))
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
@@ -56,10 +56,14 @@ MAIN_PLATFORM ?= $(word 1,$(subst $(comma), ,$(PLATFORMS)))
|
|
|
|
|
|
image: docker.image
|
|
|
|
|
|
+manifest: docker.manifest
|
|
|
+
|
|
|
push: docker.push
|
|
|
|
|
|
release: git.release
|
|
|
|
|
|
+tags: docker.tags
|
|
|
+
|
|
|
test: test.docker
|
|
|
|
|
|
|
|
|
@@ -69,29 +73,28 @@ test: test.docker
|
|
|
# Docker commands #
|
|
|
###################
|
|
|
|
|
|
-docker-namespaces = $(strip $(if $(call eq,$(namespaces),),\
|
|
|
- $(NAMESPACES),$(subst $(comma), ,$(namespaces))))
|
|
|
-docker-tags = $(subst $(comma), ,$(or $(tags),$(TAGS)))
|
|
|
-docker-platforms = $(strip $(if $(call eq,$(platforms),),\
|
|
|
- $(PLATFORMS),$(subst $(comma), ,$(platforms))))
|
|
|
-
|
|
|
-# Runs `docker buildx build` command allowing to customize it for the purpose of
|
|
|
-# re-tagging or pushing.
|
|
|
-define docker.buildx
|
|
|
- $(eval dockerfile := $(strip $(1)))
|
|
|
- $(eval namespace := $(strip $(2)))
|
|
|
- $(eval tag := $(strip $(3)))
|
|
|
- $(eval git-ref := $(strip $(4)))
|
|
|
- $(eval platform := $(strip $(5)))
|
|
|
- $(eval no-cache := $(strip $(6)))
|
|
|
- $(eval args := $(strip $(7)))
|
|
|
- $(eval github_url := $(strip $(or $(GITHUB_SERVER_URL),https://github.com)))
|
|
|
- $(eval github_repo := $(strip $(or $(GITHUB_REPOSITORY),coturn/coturn)))
|
|
|
+docker-registries = $(strip \
|
|
|
+ $(or $(subst $(comma), ,$(registries)),$(REGISTRIES)))
|
|
|
+docker-tags = $(strip $(or $(subst $(comma), ,$(tags)),$(TAGS)))
|
|
|
+
|
|
|
+
|
|
|
+# Build single-platform Docker image with the given tag.
|
|
|
+#
|
|
|
+# Usage:
|
|
|
+# make docker.image [dockerfile=(debian|alpine)]
|
|
|
+# [tag=($(VERSION)|<docker-tag>)]] [no-cache=(no|yes)]
|
|
|
+# [platform=<os>/<arch>]
|
|
|
+# [ref=<git-ref>]
|
|
|
+
|
|
|
+github_url := $(strip $(or $(GITHUB_SERVER_URL),https://github.com))
|
|
|
+github_repo := $(strip $(or $(GITHUB_REPOSITORY),$(OWNER)/$(NAME)))
|
|
|
+
|
|
|
+docker.image:
|
|
|
cd ../../ && \
|
|
|
- docker buildx build --force-rm $(args) \
|
|
|
- --platform $(platform) \
|
|
|
+ docker buildx build --force-rm \
|
|
|
+ $(if $(call eq,$(platform),),,--platform $(call dockerify,$(platform)))\
|
|
|
$(if $(call eq,$(no-cache),yes),--no-cache --pull,) \
|
|
|
- $(if $(call eq,$(git-ref),),,--build-arg coturn_git_ref=$(git-ref)) \
|
|
|
+ $(if $(call eq,$(ref),),,--build-arg coturn_git_ref=$(ref)) \
|
|
|
--build-arg coturn_github_url=$(github_url) \
|
|
|
--build-arg coturn_github_repo=$(github_repo) \
|
|
|
--label org.opencontainers.image.source=$(github_url)/$(github_repo) \
|
|
|
@@ -99,71 +102,108 @@ define docker.buildx
|
|
|
$(shell git show --pretty=format:%H --no-patch)) \
|
|
|
--label org.opencontainers.image.version=$(subst docker/,,$(strip \
|
|
|
$(shell git describe --tags --dirty --match='docker/*'))) \
|
|
|
- -f docker/coturn/$(dockerfile)/Dockerfile \
|
|
|
- -t $(namespace)/$(NAME):$(tag) ./
|
|
|
+ -f docker/coturn/$(or $(dockerfile),$(DOCKERFILE))/Dockerfile \
|
|
|
+ --load -t $(OWNER)/$(NAME):$(or $(tag),$(VERSION)) ./
|
|
|
+
|
|
|
+
|
|
|
+# Unite multiple single-platform Docker images as a multi-platform Docker image.
|
|
|
+#
|
|
|
+# WARNING: All the single-platform Docker images should be present on their
|
|
|
+# remote registry. This is the limitation imposed by `docker manifest`
|
|
|
+# command.
|
|
|
+#
|
|
|
+# make docker.manifest [amend=(yes|no)] [push=(no|yes)]
|
|
|
+# [of=($(VERSION)|<docker-tag-1>[,<docker-tag-2>...])]
|
|
|
+# [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
|
|
|
+# [registries=($(REGISTRIES)|<prefix-1>[,<prefix-2>...])]
|
|
|
+
|
|
|
+docker.manifest:
|
|
|
+ $(foreach tag,$(subst $(comma), ,$(docker-tags)),\
|
|
|
+ $(foreach registry,$(subst $(comma), ,$(docker-registries)),\
|
|
|
+ $(call docker.manifest.create.do,$(or $(of),$(VERSION)),\
|
|
|
+ $(registry),$(tag))))
|
|
|
+ifeq ($(push),yes)
|
|
|
+ $(foreach tag,$(subst $(comma), ,$(docker-tags)),\
|
|
|
+ $(foreach registry,$(subst $(comma), ,$(docker-registries)),\
|
|
|
+ $(call docker.manifest.push.do,$(registry),$(tag))))
|
|
|
+endif
|
|
|
+define docker.manifest.create.do
|
|
|
+ $(eval froms := $(strip $(1)))
|
|
|
+ $(eval repo := $(strip $(2)))
|
|
|
+ $(eval tag := $(strip $(3)))
|
|
|
+ docker manifest create $(if $(call eq,$(amend),no),,--amend) \
|
|
|
+ $(repo)/$(OWNER)/$(NAME):$(tag) \
|
|
|
+ $(foreach from,$(subst $(comma), ,$(froms)),\
|
|
|
+ $(repo)/$(OWNER)/$(NAME):$(from))
|
|
|
+endef
|
|
|
+define docker.manifest.push.do
|
|
|
+ $(eval repo := $(strip $(1)))
|
|
|
+ $(eval tag := $(strip $(2)))
|
|
|
+ docker manifest push $(repo)/$(OWNER)/$(NAME):$(tag)
|
|
|
endef
|
|
|
|
|
|
|
|
|
-# Pre-build cache for Docker image builds.
|
|
|
+# Manually push single-platform Docker images to container registries.
|
|
|
#
|
|
|
-# WARNING: This command doesn't apply tag to the built Docker image, just
|
|
|
-# creates a build cache. To produce a Docker image with a tag, use
|
|
|
-# `docker.tag` command right after running this one.
|
|
|
+# Usage:
|
|
|
+# make docker.push [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
|
|
|
+# [registries=($(REGISTRIES)|<prefix-1>[,<prefix-2>...])]
|
|
|
+
|
|
|
+docker.push:
|
|
|
+ $(foreach tag,$(subst $(comma), ,$(docker-tags)),\
|
|
|
+ $(foreach registry,$(subst $(comma), ,$(docker-registries)),\
|
|
|
+ $(call docker.push.do,$(registry),$(tag))))
|
|
|
+define docker.push.do
|
|
|
+ $(eval repo := $(strip $(1)))
|
|
|
+ $(eval tag := $(strip $(2)))
|
|
|
+ docker push $(repo)/$(OWNER)/$(NAME):$(tag)
|
|
|
+endef
|
|
|
+
|
|
|
+
|
|
|
+# Tag single-platform Docker image with the given tags.
|
|
|
#
|
|
|
# Usage:
|
|
|
-# make docker.build.cache [DOCKERFILE=(debian|alpine)]
|
|
|
-# [platforms=($(PLATFORMS)|<platform-1>[,<platform-2>...])]
|
|
|
-# [no-cache=(no|yes)]
|
|
|
-# [ref=<git-ref>]
|
|
|
-
|
|
|
-docker.build.cache:
|
|
|
- $(call docker.buildx,$(DOCKERFILE),\
|
|
|
- coturn,\
|
|
|
- build-cache,\
|
|
|
- $(ref),\
|
|
|
- $(shell echo "$(docker-platforms)" | tr -s '[:blank:]' ','),\
|
|
|
- $(no-cache),\
|
|
|
- --output 'type=image$(comma)push=false')
|
|
|
-
|
|
|
-
|
|
|
-# Build Docker image on the given platform with the given tag.
|
|
|
+# make docker.tags [of=($(VERSION)|<docker-tag>)]
|
|
|
+# [tags=($(TAGS)|<docker-tag-1>[,<docker-tag-2>...])]
|
|
|
+# [registries=($(REGISTRIES)|<prefix-1>[,<prefix-2>...])]
|
|
|
+
|
|
|
+docker.tags:
|
|
|
+ $(foreach tag,$(subst $(comma), ,$(docker-tags)),\
|
|
|
+ $(foreach registry,$(subst $(comma), ,$(docker-registries)),\
|
|
|
+ $(call docker.tags.do,$(or $(of),$(VERSION)),$(registry),$(tag))))
|
|
|
+define docker.tags.do
|
|
|
+ $(eval from := $(strip $(1)))
|
|
|
+ $(eval repo := $(strip $(2)))
|
|
|
+ $(eval to := $(strip $(3)))
|
|
|
+ docker tag $(OWNER)/$(NAME):$(from) $(repo)/$(OWNER)/$(NAME):$(to)
|
|
|
+endef
|
|
|
+
|
|
|
+
|
|
|
+# Save single-platform Docker images to a tarball file.
|
|
|
#
|
|
|
# Usage:
|
|
|
-# make docker.image [DOCKERFILE=(debian|alpine)]
|
|
|
-# [tag=($(VERSION)|<tag>)]
|
|
|
-# [platform=($(MAIN_PLATFORM)|<platform>)]
|
|
|
-# [no-cache=(no|yes)]
|
|
|
-# [ref=<git-ref>]
|
|
|
+# make docker.tar [to-file=(.cache/image.tar|<file-path>)]
|
|
|
+# [tags=($(VERSION)|<docker-tag-1>[,<docker-tag-2>...])]
|
|
|
+
|
|
|
+docker-tar-file = $(or $(to-file),.cache/image.tar)
|
|
|
+
|
|
|
+docker.tar:
|
|
|
+ @mkdir -p $(dir $(docker-tar-file))
|
|
|
+ docker save -o $(docker-tar-file) \
|
|
|
+ $(foreach tag,$(subst $(comma), ,$(or $(tags),$(VERSION))),\
|
|
|
+ $(OWNER)/$(NAME):$(tag))
|
|
|
|
|
|
-docker.image:
|
|
|
- $(call docker.buildx,$(DOCKERFILE),\
|
|
|
- coturn,\
|
|
|
- $(or $(tag),$(VERSION)),\
|
|
|
- $(ref),\
|
|
|
- $(or $(platform),$(MAIN_PLATFORM)),\
|
|
|
- $(no-cache),\
|
|
|
- --load)
|
|
|
|
|
|
+docker.test: test.docker
|
|
|
|
|
|
-# Push Docker images to their repositories (container registries),
|
|
|
-# along with the required multi-arch manifests.
|
|
|
+
|
|
|
+# Load single-platform Docker images from a tarball file.
|
|
|
#
|
|
|
# Usage:
|
|
|
-# make docker.push [DOCKERFILE=(debian|alpine)]
|
|
|
-# [namespaces=($(NAMESPACES)|<prefix-1>[,<prefix-2>...])]
|
|
|
-# [tags=($(TAGS)|<tag-1>[,<tag-2>...])]
|
|
|
-# [platforms=($(PLATFORMS)|<platform-1>[,<platform-2>...])]
|
|
|
-# [ref=<git-ref>]
|
|
|
+# make docker.untar [from-file=(.cache/image.tar|<file-path>)]
|
|
|
|
|
|
-docker.push:
|
|
|
- $(foreach namespace,$(docker-namespaces),\
|
|
|
- $(foreach tag,$(docker-tags),\
|
|
|
- $(call docker.buildx,$(DOCKERFILE),\
|
|
|
- $(namespace),\
|
|
|
- $(tag),\
|
|
|
- $(ref),\
|
|
|
- $(shell echo "$(docker-platforms)" | tr -s '[:blank:]' ','),,\
|
|
|
- --push)))
|
|
|
+docker.untar:
|
|
|
+ docker load -i $(or $(from-file),.cache/image.tar)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -178,35 +218,21 @@ docker.push:
|
|
|
# https://github.com/bats-core/bats-core
|
|
|
#
|
|
|
# Usage:
|
|
|
-# make test.docker
|
|
|
-# [tag=($(VERSION)|<tag>)]
|
|
|
-# [platforms=($(MAIN_PLATFORM)|@all|<platform-1>[,<platform-2>...])]
|
|
|
-# [( [build=no]
|
|
|
-# | build=yes [DOCKERFILE=(debian|alpine)]
|
|
|
-# [ref=<git-ref>] )]
|
|
|
-# [with=ipv6]
|
|
|
-
|
|
|
-test-docker-platforms = $(strip $(if $(call eq,$(platforms),),$(MAIN_PLATFORM),\
|
|
|
- $(if $(call eq,$(platforms),@all),$(PLATFORMS),\
|
|
|
- $(docker-platforms))))
|
|
|
+# make test.docker [tag=($(VERSION)|<docker-tag>)]
|
|
|
+# [platform=(linux/amd64|<os>/<arch>)]
|
|
|
+# [with=ipv6]
|
|
|
+
|
|
|
test.docker:
|
|
|
ifeq ($(wildcard node_modules/.bin/bats),)
|
|
|
@make npm.install
|
|
|
endif
|
|
|
- $(foreach platform,$(test-docker-platforms),\
|
|
|
- $(call test.docker.do,$(or $(tag),$(VERSION)),$(platform)))
|
|
|
-define test.docker.do
|
|
|
- $(eval tag := $(strip $(1)))
|
|
|
- $(eval platform := $(strip $(2)))
|
|
|
- $(if $(call eq,$(build),yes),\
|
|
|
- @make docker.image DOCKERFILE=$(DOCKERFILE) \
|
|
|
- no-cache=no tag=$(tag) platform=$(platform) ref=$(ref) ,)
|
|
|
- IMAGE=coturn/$(NAME):$(tag) PLATFORM=$(platform) \
|
|
|
+ IMAGE=$(OWNER)/$(NAME):$(or $(tag),$(VERSION)) \
|
|
|
+ PLATFORM=$(or $(call dockerify,$(platform)),linux/amd64) \
|
|
|
$(if $(call eq,$(with),ipv6),TEST_IPV6=1,) \
|
|
|
node_modules/.bin/bats \
|
|
|
--timing $(if $(call eq,$(CI),),--pretty,--formatter tap) \
|
|
|
+ --print-output-on-failure \
|
|
|
tests/main.bats
|
|
|
-endef
|
|
|
|
|
|
|
|
|
|
|
|
@@ -257,8 +283,9 @@ endif
|
|
|
# .PHONY section #
|
|
|
##################
|
|
|
|
|
|
-.PHONY: image push release test \
|
|
|
- docker.build.cache docker.image docker.push \
|
|
|
+.PHONY: image manifest push release test \
|
|
|
+ docker.image docker.manifest docker.push docker.tags docker.tar \
|
|
|
+ docker.test docker.untar \
|
|
|
git.release \
|
|
|
npm.install \
|
|
|
test.docker
|