Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Docker ARG command fails to perform argument substitution in recent buildkit versions #5178

Open
S-Fichtl opened this issue Jul 22, 2024 · 1 comment

Comments

@S-Fichtl
Copy link

Intro to the Bug

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

This used to work just fine but it doesn't seem to work anymore. -> BUG


Reproducing the Bug

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 only a few months ago, and now it doesn't anymore.

With some help on StackOverflow I got it to work by setting DOCKER_BUILDKIT=0. So with this flag set, the above example Dockerfile and buildscripts behave correctly again.

@tonistiigi
Copy link
Member

Second report of #5156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants