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

ARG still not working properly in FROM #1372

Closed
ThatDockerUser opened this issue Sep 14, 2020 · 7 comments · Fixed by #1373
Closed

ARG still not working properly in FROM #1372

ThatDockerUser opened this issue Sep 14, 2020 · 7 comments · Fixed by #1373
Assignees

Comments

@ThatDockerUser
Copy link

Description

This was already discussed extensively since 2017 at #859 and partially fixed by #1299 with a new release today. I tested it, and there are several cases where it still does not work.

MWE pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>dmp-test</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <java.version>1.8</java.version>
        <resource.delimiter>@</resource.delimiter>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <busybox.version>latest</busybox.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.34.0</version>
                <configuration>
                    <images>
                        <image>
                            <alias>${project.artifactId}</alias>
                            <name>${project.artifactId}:${project.version}</name>
                            <build>
                                <contextDir>${project.basedir}</contextDir>
                                <args>
                                    <busyboxVersion>${busybox.version}</busyboxVersion>
                                    <busyboxVersionName>${busybox.version}</busyboxVersionName>
                                </args>
                            </build>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I want to use busyboxVersion, as supplied by Maven, in my Dockerfile, so I do this:

ARG busyboxVersion
FROM busybox:${busyboxVersion}

But upon building, I get this:

[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 83 milliseconds
[ERROR] DOCKER> Unable to check image [busybox:${busyboxVersion}] : {"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400) [{"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400)]

Apparently, the ARG is not resolved, although this is the correct format as per the documentation. So, I change it to this:

ARG busyboxVersion
FROM busybox:$busyboxVersion

And get this:

[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 122 milliseconds
[ERROR] DOCKER> Unable to check image [busybox:] : {"message":"no such image: busybox:: invalid reference format"} (Bad Request: 400) [{"message":"no such image: busybox:: invalid reference format"} (Bad Request: 400)]

The ARG is now resolved, but has no content. Hence, I test this:

ARG busyboxVersion
FROM busybox:latest
ARG busyboxVersionName
LABEL busyboxVersion=${busyboxVersion}
LABEL busyboxVersionName=${busyboxVersionName}

The image is now built (since the version is again hard-coded), but upon inspecting it in Docker, I get this:

"Labels": {
    "busyboxVersion": "",
    "busyboxVersionName": "latest"
}

Once again, the ARG was resolved to an empty string, while the second ARG was interpreted correctly. I further this test like so:

FROM busybox:latest
ARG busyboxVersion
ARG busyboxVersionName
LABEL busyboxVersion=${busyboxVersion}
LABEL busyboxVersionName=${busyboxVersionName}

Now inspecting the Docker image, everything is alright:

"Labels": {
    "busyboxVersion": "latest",
    "busyboxVersionName": "latest"
}

Info

  • d-m-p version : 0.34.0
  • Maven version (mvn -v) :
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Program Files\apache-maven-3.6.3\bin\..
Java version: 11.0.7, vendor: AdoptOpenJDK, runtime: C:\Program Files\AdoptOpenJDK\jdk-11.0.7.10-hotspot
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
  • Docker version : 19.03.12
  • If it's a bug, how to reproduce : see above
  • If it's a feature request, what is your use case : -
  • Sample project : see above
@ThatDockerUser
Copy link
Author

Ping @rohanKanojia and @rhuss who extensively worked on the related issue.

@rohanKanojia
Copy link
Member

@ThatDockerUser : Where is value of busyboxVersion picked from?

@ThatDockerUser
Copy link
Author

ThatDockerUser commented Sep 14, 2020

@rohanKanojia From the POM, via the <args> configuration (see the MWE). busyboxVersion and busyboxVersionName have the same value, taken from the busybox.version property.

@rohanKanojia
Copy link
Member

I wasn't aware of this <args> field in buildconfiguration. Right now plugin only considers args in Dockerfile. Let me fix it.

@rohanKanojia rohanKanojia self-assigned this Sep 14, 2020
@ThatDockerUser
Copy link
Author

Thanks for taking this on, I will also note here that the variable format with the braces does not work irrespective of the POM usage, such as in this:

ARG busyboxVersion=latest
FROM busybox:${busyboxVersion}
[INFO] DOCKER> [dmp-test:1.0.0-SNAPSHOT] "dmp-test": Created docker-build.tar in 160 milliseconds
[ERROR] DOCKER> Unable to check image [busybox:${busyboxVersion}] : {"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400) [{"message":"no such image: busybox:${busyboxVersion}: invalid reference format"} (Bad Request: 400)]

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Sep 15, 2020
…nfiguration

Refactored `DockerFileUtil.extractBaseImages` to accept a HashMap of
Build args which would be passed from BuildService in order to resolve
ARG values which are provided from plugin configuration
@rohanKanojia
Copy link
Member

I'm checking this case when you build with a Dockerfile like this:

ARG busyboxVersion
FROM busybox:latest
ARG busyboxVersionName
LABEL busyboxVersion=${busyboxVersion}
LABEL busyboxVersionName=${busyboxVersionName}

Even when I build this with plain docker, it doesn't seem to be resolved. I think it's more of a docker behavior rather than plugin's, maybe arg was no longer in build scope after passing from:

docker build --build-arg busyboxVersion=latest --build-arg busyboxVersionName=latest -t busybox_ltest:latest .

...

docker : $ docker inspect 9d951b5ac865 | grep -A3 "Labels"
            "Labels": {
                "busyboxVersion": "",
                "busyboxVersionName": "latest"
            }
--
            "Labels": {
                "busyboxVersion": "",
                "busyboxVersionName": "latest"
            }
docker : $ 

rohanKanojia added a commit to rohanKanojia/docker-maven-plugin that referenced this issue Sep 15, 2020
…nfiguration

Refactored `DockerFileUtil.extractBaseImages` to accept a HashMap of
Build args which would be passed from BuildService in order to resolve
ARG values which are provided from plugin configuration
@ThatDockerUser
Copy link
Author

ThatDockerUser commented Sep 22, 2020

Maybe that is also a bug within Docker, but any ARG configured prior to the FROM remains valid in the FROM. The PR addresses this, so I hope it can be merged and released soon.

rhuss added a commit that referenced this issue Sep 27, 2020
…on (#1373)

Refactored `DockerFileUtil.extractBaseImages` to accept a HashMap of
Build args which would be passed from BuildService in order to resolve
ARG values which are provided from plugin configuration

Co-authored-by: Roland Huß <roland@ro14nd.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants