Docker: added a way to generate multiple versions of an image.

This commit is contained in:
Konstantin Pavlov
2023-05-05 17:19:55 -07:00
parent 7a77f48a25
commit 6e548cbb30

View File

@@ -10,61 +10,61 @@ PATCHLEVEL ?= 1
EXPORT_DIR := $(VERSION) EXPORT_DIR := $(VERSION)
MODULES ?= go jsc node perl php python ruby minimal MODULES ?= go jsc node perl php python ruby
VARIANT ?= bullseye VARIANT ?= bullseye
VERSION_minimal ?= VERSIONS_minimal ?=
CONTAINER_minimal ?= debian:$(VARIANT)-slim CONTAINER_minimal ?= debian:$(VARIANT)-slim
CONFIGURE_minimal ?= CONFIGURE_minimal ?=
INSTALL_minimal ?= version INSTALL_minimal ?= version
RUN_minimal ?= /bin/true RUN_minimal ?= /bin/true
VERSION_go ?= 1.20 VERSIONS_go ?= 1.20
VARIANT_go ?= $(VARIANT) VARIANT_go ?= $(VARIANT)
CONTAINER_go ?= golang:$(VERSION_go)-$(VARIANT_go) $(foreach goversion, $(VERSIONS_go), $(eval CONTAINER_go$(goversion) = golang:$(goversion)-$(VARIANT_go)))
CONFIGURE_go ?= go --go-path=$$GOPATH CONFIGURE_go ?= go --go-path=$$GOPATH
INSTALL_go ?= go-install-src libunit-install INSTALL_go ?= go-install-src libunit-install
RUN_go ?= /bin/true RUN_go ?= /bin/true
VERSION_jsc ?= 11 VERSIONS_jsc ?= 11
VARIANT_jsc ?= jammy VARIANT_jsc ?= jammy
CONTAINER_jsc ?= eclipse-temurin:$(VERSION_jsc)-jdk-$(VARIANT_jsc) $(foreach jscversion, $(VERSIONS_jsc), $(eval CONTAINER_jsc$(jscversion) = eclipse-temurin:$(jscversion)-jdk-$(VARIANT_jsc)))
CONFIGURE_jsc ?= java --jars=/usr/share/unit-jsc-common/ CONFIGURE_jsc ?= java --jars=/usr/share/unit-jsc-common/
INSTALL_jsc ?= java-shared-install java-install INSTALL_jsc ?= java-shared-install java-install
RUN_jsc ?= /bin/true RUN_jsc ?= /bin/true
VERSION_node ?= 18 VERSIONS_node ?= 18
VARIANT_node ?= $(VARIANT) VARIANT_node ?= $(VARIANT)
CONTAINER_node ?= node:$(VERSION_node)-$(VARIANT_node) $(foreach nodeversion, $(VERSIONS_node), $(eval CONTAINER_node$(nodeversion) = node:$(nodeversion)-$(VARIANT_node)))
CONFIGURE_node ?= nodejs --node-gyp=/usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp CONFIGURE_node ?= nodejs --node-gyp=/usr/local/lib/node_modules/npm/bin/node-gyp-bin/node-gyp
INSTALL_node ?= node node-install libunit-install INSTALL_node ?= node node-install libunit-install
RUN_node ?= /bin/true RUN_node ?= /bin/true
VERSION_perl ?= 5.36 VERSIONS_perl ?= 5.36
VARIANT_perl ?= $(VARIANT) VARIANT_perl ?= $(VARIANT)
CONTAINER_perl ?= perl:$(VERSION_perl)-$(VARIANT_perl) $(foreach perlversion, $(VERSIONS_perl), $(eval CONTAINER_perl$(perlversion) = perl:$(perlversion)-$(VARIANT_perl)))
CONFIGURE_perl ?= perl CONFIGURE_perl ?= perl
INSTALL_perl ?= perl-install INSTALL_perl ?= perl-install
RUN_perl ?= /bin/true RUN_perl ?= /bin/true
VERSION_php ?= 8.2 VERSIONS_php ?= 8.2
VARIANT_php ?= cli-$(VARIANT) VARIANT_php ?= cli-$(VARIANT)
CONTAINER_php ?= php:$(VERSION_php)-$(VARIANT_php) $(foreach phpversion, $(VERSIONS_php), $(eval CONTAINER_php$(phpversion) = php:$(phpversion)-$(VARIANT_php)))
CONFIGURE_php ?= php CONFIGURE_php ?= php
INSTALL_php ?= php-install INSTALL_php ?= php-install
RUN_php ?= ldconfig RUN_php ?= ldconfig
VERSION_python ?= 3.11 VERSIONS_python ?= 3.11
VARIANT_python ?= $(VARIANT) VARIANT_python ?= $(VARIANT)
CONTAINER_python ?= python:$(VERSION_python)-$(VARIANT_python) $(foreach pythonversion, $(VERSIONS_python), $(eval CONTAINER_python$(pythonversion) = python:$(pythonversion)-$(VARIANT_python)))
CONFIGURE_python ?= python --config=/usr/local/bin/python3-config CONFIGURE_python ?= python --config=/usr/local/bin/python3-config
INSTALL_python ?= python3-install INSTALL_python ?= python3-install
RUN_python ?= /bin/true RUN_python ?= /bin/true
VERSION_ruby ?= 3.2 VERSIONS_ruby ?= 3.2
VARIANT_ruby ?= $(VARIANT) VARIANT_ruby ?= $(VARIANT)
CONTAINER_ruby ?= ruby:$(VERSION_ruby)-$(VARIANT_ruby) $(foreach rubyversion, $(VERSIONS_ruby), $(eval CONTAINER_ruby$(rubyversion) = ruby:$(rubyversion)-$(VARIANT_ruby)))
CONFIGURE_ruby ?= ruby CONFIGURE_ruby ?= ruby
INSTALL_ruby ?= ruby-install INSTALL_ruby ?= ruby-install
RUN_ruby ?= gem install rack RUN_ruby ?= gem install rack
@@ -72,26 +72,26 @@ RUN_ruby ?= gem install rack
default: default:
@echo "valid targets: all build dockerfiles clean" @echo "valid targets: all build dockerfiles clean"
MODVERSIONS = $(foreach module,$(MODULES),$(module)$(VERSION_$(module))) MODVERSIONS = $(foreach module, $(MODULES), $(foreach modversion, $(shell for v in $(VERSIONS_$(module)); do echo $$v; done | sort -r), $(module)$(modversion))) minimal
modname = $(shell echo $1 | /usr/bin/tr -d '.01234567890-') modname = $(shell echo $1 | /usr/bin/tr -d '.01234567890-')
dockerfiles: $(addprefix Dockerfile., $(MODVERSIONS)) dockerfiles: $(addprefix Dockerfile., $(MODVERSIONS))
build: $(addprefix build-,$(MODVERSIONS)) build: $(addprefix build-, $(MODVERSIONS))
Dockerfile.%: ../../version template.Dockerfile Dockerfile.%: ../../version template.Dockerfile
@echo "===> Building $@" @echo "===> Building $@"
cat template.Dockerfile | sed \ cat template.Dockerfile | sed \
-e 's,@@VERSION@@,$(VERSION),g' \ -e 's,@@VERSION@@,$(VERSION),g' \
-e 's,@@PATCHLEVEL@@,$(PATCHLEVEL),g' \ -e 's,@@PATCHLEVEL@@,$(PATCHLEVEL),g' \
-e 's,@@CONTAINER@@,$(CONTAINER_$(call modname, $*)),g' \ -e 's,@@CONTAINER@@,$(CONTAINER_$*),g' \
-e 's,@@CONFIGURE@@,$(CONFIGURE_$(call modname, $*)),g' \ -e 's,@@CONFIGURE@@,$(CONFIGURE_$(call modname, $*)),g' \
-e 's,@@INSTALL@@,$(INSTALL_$(call modname, $*)),g' \ -e 's,@@INSTALL@@,$(INSTALL_$(call modname, $*)),g' \
-e 's,@@RUN@@,$(RUN_$(call modname, $*)),g' \ -e 's,@@RUN@@,$(RUN_$(call modname, $*)),g' \
> $@ > $@
build-%: Dockerfile.% build-%: Dockerfile.%
docker pull $(CONTAINER_$(call modname, $*)) docker pull $(CONTAINER_$*)
docker build --no-cache -t unit:$(VERSION)-$* -f Dockerfile.$* . docker build --no-cache -t unit:$(VERSION)-$* -f Dockerfile.$* .
library: library:
@@ -99,16 +99,23 @@ library:
@echo "" @echo ""
@echo "Maintainers: Unit Docker Maintainers <docker-maint@nginx.com> (@nginx)" @echo "Maintainers: Unit Docker Maintainers <docker-maint@nginx.com> (@nginx)"
@echo "GitRepo: https://github.com/nginx/unit.git" @echo "GitRepo: https://github.com/nginx/unit.git"
@for mod in $(MODVERSIONS); do \ @previous=""; \
for mod in $(MODVERSIONS); do \
echo ""; \ echo ""; \
TAGS="$$mod $${mod%%.*} $$( echo $$mod | tr -d '.0123456789-' )"; \ modname="$$( echo $$mod | tr -d '.0123456789-' )"; \
TAGS="$$mod $${mod%%.*} $$modname" ; \
TAGS="$$(echo $$TAGS | tr " " "\n" | sort -u -r | tr "\n" "," | sed "s/,/, /g")"; \ TAGS="$$(echo $$TAGS | tr " " "\n" | sort -u -r | tr "\n" "," | sed "s/,/, /g")"; \
echo "Tags: $(VERSION)-$$mod, $${TAGS%, }"; \ if [ "$$previous" == "$$modname" ]; then \
echo "Tags: $(VERSION)-$$mod, $$mod"; \
else \
echo "Tags: $(VERSION)-$$mod, $${TAGS%, }"; \
fi; \
echo "Architectures: amd64, arm64v8"; \ echo "Architectures: amd64, arm64v8"; \
echo "GitFetch: refs/heads/branches/packaging"; \ echo "GitFetch: refs/heads/branches/packaging"; \
echo "GitCommit: $(shell git describe --always --abbrev=0 HEAD)"; \ echo "GitCommit: $(shell git describe --always --abbrev=0 HEAD)"; \
echo "Directory: pkg/docker"; \ echo "Directory: pkg/docker"; \
echo "File: Dockerfile.$$mod"; \ echo "File: Dockerfile.$$mod"; \
previous=$$(echo $$mod | tr -d '.0123456789-'); \
done done
all: $(addprefix Dockerfile., $(MODVERSIONS)) all: $(addprefix Dockerfile., $(MODVERSIONS))