I am using a single Dockerfile to build images for different Ubuntu versions. Those images are then used in CI to build software targeting those different Ubuntu versions.
Sometimes, there are of course some differences between Ubuntu versions, e.g. I’m installing different compilers. The code I use looks something like this
FROM $baseimage AS base_image
ARG distro
ARG ${distro}=" "
...
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${focal:+10}${jammy:+14} 10
And this used to work just fine but it doesn’t seem to work anymore.
First of all, this uses simple bash functionality. To reproduce locally simple do in the terminal
$export bar="BAR"
$export $bar=" "
$echo "test ${BAR:+barr} ${FOO:-notfooo}"
test barr notfooo
This works just fine in the terminal, but the Dockerfile doesn’t work like this anymore.
So here’s a minimal image to reproduce with full Dockerfile and build commands
Dockerfile:
ARG baseimage
ARG distro
ARG ${distro}=" "
FROM $baseimage AS base_image
ARG distro
ARG ${distro}=" "
RUN echo "arg is ${distro}" > /test.log
RUN echo "distro is ${focal:+Focal}${jammy:+Jammy} ${focal:-not Focal}${jammy:-not Jammy}" >> /test.log
CMD sleep infinity
build commands
baseimage='ubuntu:focal'
distro='focal'
docker build . -t testimage:${distro} --build-arg distro=${distro} --build-arg baseimage=${baseimage} -f Dockerfile --target base_image
In this case, when using focal
as test argument, I’d expect the log file contents to be
arg is focal
distro is Focal not Jammy
However, instead it’s
arg is focal
distro is not Focalnot Jammy
I don’t know what exactly changed to make it stop working, but I assume a recent docker upgrade (I’m on Ubuntu 22.04 here for building those images). But this used to work, and now it doesn’t anymore.
Does anyone know how to get this functionality back?
6