common: Automatize UPSTREAM_DISTRO name based on image name

Similar to what is already done with DISTRO, which points to given image
of ours based on name. This time we do the same with upstream images,
such as debian:stretch or centos:centos8.

This way, for instance calling docker_images_require
"osmo-bsc-latest-centos8" would try to build the
osmo-bsc-latest/Dockerfile file starting from a centos8 image.

Change-Id: I33cb21aa024396974559fd98f9f3c64e2c351eda
This commit is contained in:
Pau Espin 2020-11-18 16:45:28 +01:00 committed by laforge
parent b83c28fc34
commit 78ae9377a7
21 changed files with 61 additions and 26 deletions

View File

@ -1,6 +1,7 @@
ARG USER
ARG REGISTRY=docker.io
FROM ${REGISTRY}/centos:centos8
ARG UPSTREAM_DISTRO=centos:centos8
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
# dnf-utils: for repoquery
RUN dnf install -y \
@ -9,4 +10,3 @@ RUN dnf install -y \
# Make additional development libraries available
RUN yum config-manager --set-enabled PowerTools

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/centos:centos8
ARG UPSTREAM_DISTRO=centos:centos8
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
# Let package metadata expire after 60 seconds instead of 48 hours
RUN echo "metadata_expire=60" >> /etc/dnf/dnf.conf && cat /etc/dnf/dnf.conf

View File

@ -1,6 +1,7 @@
ARG USER
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
COPY Release.key /tmp/Release.key

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -12,10 +12,18 @@ docker_depends() {
docker_distro_from_image_name() {
case "$1" in
osmo-*-centos8) echo "centos8"; ;;
osmo-*-centos8) echo "centos8" ;;
centos8-*) echo "centos8" ;;
*) echo "debian-stretch" ;;
esac
}
docker_upstream_distro_from_image_name() {
case "$1" in
osmo-*-centos8) echo "centos:centos8"; ;;
centos8-*) echo "centos:centos8" ;;
*) echo "debian:stretch" ;;
esac
}
docker_dir_from_image_name() {
@ -27,15 +35,20 @@ docker_dir_from_image_name() {
# Make sure required images are available and build them if necessary.
# $*: image names (e.g. "debian-stretch-build", "osmo-mgw-master", "osmo-mgw-master-centos8")
# The images are automatically built from the Dockerfile of the subdir of the same name. If there is a
# distribution name at the end of the image name (e.g. osmo-mgw-master-centos8), it gets removed from the subdir
# where the Dockerfile is taken from (e.g. osmo-mgw-master/Dockerfile) and DISTRO is passed accordingly
# (e.g. DISTRO=centos8). This allows one Dockerfile for multiple distributions, without duplicating configs for
# each distribution. Dependencies listed in docker_depends() are built automatically too.
# The images are automatically built from the Dockerfile of the subdir of
# the same name. If there is a distribution name at the end of the image
# name (e.g. osmo-mgw-master-centos8), it gets removed from the subdir
# where the Dockerfile is taken from (e.g. osmo-mgw-master/Dockerfile)
# and UPSTREAM_DISTRO and DISTRO are passed accordingly (e.g.
# UPSTREAM_DISTRO=centos:centos8 DISTRO=centos8). This allows one
# Dockerfile for multiple distributions, without duplicating configs for
# each distribution. Dependencies listed in docker_depends() are built
# automatically too.
docker_images_require() {
local i
local from_line
local pull_arg
local upstream_distro_arg
local distro_arg
local depends
local dir
@ -49,6 +62,7 @@ docker_images_require() {
# Trigger image build (cache will be used when up-to-date)
if [ -z "$NO_DOCKER_IMAGE_BUILD" ]; then
upstream_distro_arg="$(docker_upstream_distro_from_image_name "$i")"
distro_arg="$(docker_distro_from_image_name "$i")"
dir="$(docker_dir_from_image_name "$i")"
@ -62,6 +76,7 @@ docker_images_require() {
echo "Building image: $i (export NO_DOCKER_IMAGE_BUILD=1 to prevent this)"
make -C "../$dir" \
PULL="$pull_arg" \
UPSTREAM_DISTRO="$upstream_distro_arg" \
DISTRO="$distro_arg" \
IMAGE="$REPO_USER/$i" \
|| exit 1

View File

@ -33,6 +33,7 @@ OSMO_SGSN_BRANCH?=master
OSMO_SIP_BRANCH?=master
OSMO_STP_BRANCH?=master
PULL?=
UPSTREAM_DISTRO?=debian:stretch
DISTRO?=debian-stretch
RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-release-support
@ -61,6 +62,7 @@ docker-build: .release
--build-arg USER=$(USERNAME) \
--build-arg REGISTRY=$(REGISTRY_HOST) \
--build-arg OSMO_TTCN3_BRANCH=$(OSMO_TTCN3_BRANCH) \
--build-arg UPSTREAM_DISTRO=$(UPSTREAM_DISTRO) \
--build-arg DISTRO=$(DISTRO) \
--build-arg LIBOSMOCORE_BRANCH=$(LIBOSMOCORE_BRANCH) \
--build-arg OSMO_BB_BRANCH=$(OSMO_BB_BRANCH) \

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Daniel Willmann <dwillmann@sysmocom.de>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>

View File

@ -1,5 +1,6 @@
ARG REGISTRY=docker.io
FROM ${REGISTRY}/debian:stretch
ARG UPSTREAM_DISTRO=debian:stretch
FROM ${REGISTRY}/${UPSTREAM_DISTRO}
MAINTAINER Harald Welte <laforge@gnumonks.org>