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

Build Failure When Injecting Docker Build Args into Dockerfile 'FROM' Statement #2901

Closed
sunix opened this issue Apr 12, 2024 · 0 comments · Fixed by #2915
Closed

Build Failure When Injecting Docker Build Args into Dockerfile 'FROM' Statement #2901

sunix opened this issue Apr 12, 2024 · 0 comments · Fixed by #2915
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sunix
Copy link
Member

sunix commented Apr 12, 2024

Describe the bug

According to the documentation on https://eclipse.dev/jkube/docs/kubernetes-maven-plugin/#property-buildargs, it should be possible to pass build arguments from properties using the format: <docker.buildArg.myBuildArg>myValue</docker.buildArg.myBuildArg>. This method functions correctly except when the build arguments are used within the 'FROM' statement of a Dockerfile. In such cases, JKube attempts to pre-pull the image without incorporating the specified build arguments, leading to a failure in the build process.

Eclipse JKube version

1.16.2

Component

Kubernetes Maven Plugin

Apache Maven version

None

Gradle version

None

Steps to reproduce

  1. Prepare the Dockerfile:
    Save the following content in src/main/docker/Dockerfile:

    ARG IMAGEVERSION
    FROM docker.io/alpine:${IMAGEVERSION} as builder
    ARG IMAGEVERSION
    RUN touch test-${IMAGEVERSION}.txt
    
    FROM docker.io/alpine:${IMAGEVERSION}
    COPY --from=builder /test-${IMAGEVERSION}.txt /test.txt
    
    ENTRYPOINT ["ls"]
  2. Configure JKube Plugin in pom.xml:
    Add the JKube Kubernetes Maven plugin configuration to your pom.xml:

    <plugin>
        <groupId>org.eclipse.jkube</groupId>
        <artifactId>kubernetes-maven-plugin</artifactId>
        <version>1.16.2</version>
        <configuration>
          <buildStrategy>docker</buildStrategy>
          <images>
            <image>
              <name>helloworld:%l</name>
              <build>
                <contextDir>${project.basedir}/src/main/docker/</contextDir>
                <dockerFile>Dockerfile</dockerFile>
              </build>
            </image>
          </images>
        </configuration>
    </plugin>
  3. Define Build Argument in pom.xml:
    Specify the Docker build argument for the image version:

    <properties>
        <docker.buildArg.IMAGEVERSION>latest</docker.buildArg.IMAGEVERSION>
    </properties>
  4. Execute the Build:
    Run the following command in your project directory:

    mvn k8s:build
    
  5. Observe the Error:
    The build fails with the following error message:

    [ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.17-SNAPSHOT:build (default-cli) on project jkube-maven-sample-node-selector: Failed to execute the build: Error while trying to build the image: Unable to check image [docker.io/alpine:${IMAGEVERSION}] : {"message":"invalid reference format"} (Bad Request: 400) -> [Help 1]
    

Expected behavior

The build should complete without errors

Runtime

other (please specify in additional context)

Kubernetes API Server version

1.25.3

Environment

Linux

Eclipse JKube Logs

No response

Sample Reproducer Project

No response

Additional context

No response

@sunix sunix added the bug Something isn't working label Apr 12, 2024
@manusa manusa added this to the 1.17.0 milestone Apr 15, 2024
@sunix sunix self-assigned this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants