-
Notifications
You must be signed in to change notification settings - Fork 657
Description
There seems to be a bug with how the property docker.buildArg.MY_ARG works when used with buildx.
In this example you can comment/uncomment the property docker.buildArg.MY_FILE_NAME to set the buildArg and buildx.platform to activate buildX.
Here are the following combinations and how they behave:
- buildArg property + no buildX = expected success (build arg is used in Dockerfile)
- buildArg property + buildX = unexpected failure (build arg is NOT used in Dockerfile even though it is set)
- no buildArg property + no buildX = expected failure (build arg not set so Dockerfile build fails)
- no buildArg property + buildX = expected failure (build arg not set so Dockerfile build fails)
Then its confirmed that this looks like a bug because if you set the buildArg multiple times via the property docker.buildArg.MY_FILE_NAME and within the plugin configuration block args, you get an error Multiple entries with same key: MY_FILE_NAME=myfile and MY_FILE_NAME=myfile both with buildX and without buildX. This makes sense that it wont let you set duplicate build args but shows that buildX with the property arg should be working but its not.
Here is a minimal example pom.xml and Dockerfile that should succeed but fails because it does not pass the property to the Dockerfile as build arg.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>fabric8-build-arg-example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<docker.buildArg.MY_FILE_NAME>myfile</docker.buildArg.MY_FILE_NAME>
<!-- Comment out to de-activate buildX -->
<buildx.platform>linux/amd64</buildx.platform>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<images>
<image>
<name>${artifactId}:${version}</name>
<build>
<dockerFileDir>${project.basedir}/.</dockerFileDir>
<!-- <args>-->
<!-- <MY_FILE_NAME>myfile</MY_FILE_NAME>-->
<!-- </args>-->
<buildx>
<platforms>
<platform>${buildx.platform}</platform>
</platforms>
</buildx>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
FROM alpine:latest
ARG MY_FILE_NAME
# will only succeed if FILE_NAME resolves
RUN echo 'test' > /tmp/${MY_FILE_NAME}
RUN ls -alh /tmp/${MY_FILE_NAME}