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

docker.buildArg.* properties not taken into account in OpenShift plugins #2904

Closed
sunix opened this issue Apr 12, 2024 · 1 comment · Fixed by #2996
Closed

docker.buildArg.* properties not taken into account in OpenShift plugins #2904

sunix opened this issue Apr 12, 2024 · 1 comment · Fixed by #2996
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sunix
Copy link
Member

sunix commented Apr 12, 2024

Describe the bug

The JKube Openshift Maven plugin fails to recognize specified Docker build-arg when they are injected into a Dockerfile from Maven properties. This issue manifests specifically when using Maven properties and does not occur with the XML/Gradle DSL configuration since #2895.
This issue occurs despite the JKube documentation confirming that build arguments can be specified either via the plugin configuration or as Maven properties.

Eclipse JKube version

SNAPSHOT

Component

OpenShift Maven Plugin

Apache Maven version

None

Gradle version

None

Steps to reproduce

  1. Set Up the Dockerfile:
    Place the following content in src/main/docker/Dockerfile:

    ARG FILE_EXTENSION
    FROM docker.io/alpine:latest as builder
    RUN touch test.${FILE_EXTENSION}
    
    FROM docker.io/alpine:latest
    COPY --from=builder /test.txt /test.txt
    
    ENTRYPOINT ["ls"]
  2. Configure the JKube Plugin:
    Insert the JKube Openshift Maven plugin configuration into your pom.xml:

    <plugin>
        <groupId>org.eclipse.jkube</groupId>
        <artifactId>openshift-maven-plugin</artifactId>
        <version>1.17-SNAPSHOT</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 the Build Argument:
    Define the build argument for the Docker image in your pom.xml:

    <properties>
        <docker.buildArg.FILE_EXTENSION>txt</docker.buildArg.FILE_EXTENSION>
    </properties>
  4. Execute the Build Command:
    Execute the build using the following Maven command:

    mvn oc:build
    
  5. Error Observation:
    The build process fails, yielding the following output:

    [INFO] oc: --> abd4c9e7124f
    [INFO] oc: [1/2] STEP 3/3: RUN touch test.${FILE_EXTENSION}
    [INFO] oc: --> ee9fcbe057df
    [INFO] oc: [2/2] STEP 1/5: FROM docker.io/alpine
    [INFO] oc: [2/2] STEP 2/5: COPY --from=builder test.txt test.txt
    [ERROR] oc: Failed to execute the build [Unable to build the image using the OpenShift build service]
    [ERROR] oc: Failed to tail build log: %s: java.lang.IllegalStateException: java.io.IOException: channel already closed with exception
    

Expected behavior

The docker.buildArg.FILE_EXTENSION property should be properly processed, enabling the substitution of ${FILE_EXTENSION} in the Dockerfile and ensuring the successful build of the Docker image with the specified configurations.

Runtime

OpenShift

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
@rohanKanojia rohanKanojia self-assigned this Apr 26, 2024
@rohanKanojia
Copy link
Member

I think this issue is happening because we're only modifying Image Build Config in case of docker build strategy.

Code for extracting build args from properties is here in BuildService:

private Map<String, String> addBuildArgsFromProperties(Properties properties) {

This gets called by DockerBuildService that is one of the implementations of AbstractImageBuildService . Other implementations are OpenShiftBuildService, JibBuildService, BuildPackBuildService.

This issue can be fixed by moving the logic upwards before build is delegated to Build Strategy specific Build Service implementations. Maybe it can be moved in DefaultGeneratorManager.generateAndMerge where we initialize and filter image configurations?:

// Init and validate Image configurations. These images will contain the valid configurations.
final ImageNameFormatter imageNameFormatter = new ImageNameFormatter(genCtx.getProject(), genCtx.getBuildTimestamp());
for (ImageConfiguration imageConfiguration : filteredImages) {
imageConfiguration.setName(imageNameFormatter.format(imageConfiguration.getName()));
if (imageConfiguration.getBuild() != null) {
BuildConfiguration updatedBuildConfig = mergeGlobalConfigParamsWithSingleImageBuildConfig(imageConfiguration.getBuild());
imageConfiguration.setBuild(updatedBuildConfig);

rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Apr 29, 2024
…ass BuildArgResolverUtil

Related to eclipse-jkube#2904

It's better to move code for resolving build args from different sources to a dedicated class.
It doesn't look like BuildService is the right place for this. This way
we can also use it from other BuildServices of other build strategies.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Apr 30, 2024
…ass BuildArgResolverUtil

Related to eclipse-jkube#2904

It's better to move code for resolving build args from different sources to a dedicated class.
It doesn't look like BuildService is the right place for this. This way
we can also use it from other BuildServices of other build strategies.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/jkube that referenced this issue Apr 30, 2024
…ass BuildArgResolverUtil

Related to eclipse-jkube#2904

It's better to move code for resolving build args from different sources to a dedicated class.
It doesn't look like BuildService is the right place for this. This way
we can also use it from other BuildServices of other build strategies.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
manusa pushed a commit that referenced this issue Apr 30, 2024
…ass BuildArgResolverUtil

Related to #2904

It's better to move code for resolving build args from different sources to a dedicated class.
It doesn't look like BuildService is the right place for this. This way
we can also use it from other BuildServices of other build strategies.

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
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
3 participants