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 args not applied as ARG (external dockerfile openshift-maven) #2860

Closed
Snijder opened this issue Mar 28, 2024 · 3 comments · Fixed by #2895
Closed

Build args not applied as ARG (external dockerfile openshift-maven) #2860

Snijder opened this issue Mar 28, 2024 · 3 comments · Fixed by #2895
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Snijder
Copy link

Snijder commented Mar 28, 2024

Describe the bug

I am trying to specify the image version from the pom which I can then use in an ARG in my dockerfile when building on openshift. (related docs)

Eclipse JKube version

1.16.2

Component

Kubernetes Maven Plugin

Apache Maven version

other (please specify in additional context)

Gradle version

None

Steps to reproduce

  1. Configure a build arg like so: pom.xml.txt
<plugin>
	<groupId>org.eclipse.jkube</groupId>
	<artifactId>openshift-maven-plugin</artifactId>
	<version>1.16.2</version>
	<executions>
		<execution>
			<id>build-main-container</id>
			<phase>package</phase>
			<goals>
				<goal>build</goal>
			</goals>
			<configuration>
				<buildStrategy>docker</buildStrategy>
				<images>
					<image>
						<name>${openshift.registry}/helloworld:%l</name>
						<build>
							<contextDir>${project.basedir}/src/main/docker/</contextDir>
							<dockerFile>Dockerfile</dockerFile>
							<args>
								<IMAGEVERSION>latest</IMAGEVERSION>
							</args>
						</build>
					</image>
				</images>
			</configuration>
		</execution>
	</executions>
</plugin>
  1. Specify the dockerfile under src/main/docker as follows:
ARG IMAGEVERSION
FROM docker.io/alpine:${IMAGEVERSION} as builder

RUN touch test.txt

FROM docker.io/alpine:${IMAGEVERSION}
COPY --from=builder test.txt test.txt

ENTRYPOINT ["ls"]
  1. run mvn clean verify -Dopenshift.namespace=yournamespacehere

Expected behavior

I expect the build arg to be applied and the ARG in the Dockerfile to be filled at build time.

Runtime

OpenShift

Kubernetes API Server version

1.25.3

Environment

Linux, other (please specify in additional context)

Eclipse JKube Logs

[INFO] --- oc:1.16.2:build (build-main-container) @ test ---
[INFO] oc: Using OpenShift build with strategy Docker
[INFO] oc: Using Dockerfile: /home/asdf/Documents/code/frb-common/helloworld/src/main/docker/Dockerfile
[INFO] oc: Using Docker Context Directory: /home/asdf/Documents/code/frb-common/helloworld/src/main/docker
[WARNING] oc: Dockerfile /home/asdf/Documents/code/frb-common/helloworld/src/main/docker/Dockerfile does not contain an ADD or COPY directive to include assembly created at maven. Ignoring assembly.
[INFO] oc: [image-registry.openshift-image-registry.svc:5000/bl-asdfsnijder/helloworld:latest]: Created docker source tar /home/asdf/Documents/code/frb-common/helloworld/target/docker/image-registry.openshift-image-registry.svc/5000/bl-asdfsnijder/helloworld/latest/tmp/docker-build.tar
[INFO] oc: Adding to Secret pullsecret-jkube
[INFO] oc: Using Secret pullsecret-jkube
[INFO] oc: Updating BuildServiceConfig helloworld-s2i for Docker strategy
[INFO] oc: Adding to ImageStream helloworld
[INFO] oc: Starting Build helloworld-s2i
[INFO] oc: Waiting for build helloworld-s2i-11 to complete...
[INFO] oc: Adding cluster TLS certificate authority to trust store
[INFO] oc: time="2024-03-28T12:48:54Z" level=info msg="Not using native diff for overlay, this may cause degraded performance for building images: kernel has CONFIG_OVERLAY_FS_REDIRECT_DIR enabled"
[INFO] oc: I0328 12:48:54.750934       1 defaults.go:112] Defaulting to storage driver "overlay" with options [mountopt=metacopy=on].
[INFO] oc: Caching blobs under "/var/cache/blobs".
[INFO] oc: 
[INFO] oc: Pulling image docker.io/alpine ...
[INFO] oc: Trying to pull docker.io/library/alpine:latest...
[INFO] oc: Getting image source signatures
[INFO] oc: Copying blob sha256:4abcf20661432fb2d719aaf90656f55c287f8ca915dc1c92ec14ff61e67fbaf8
[INFO] oc: Copying config sha256:05455a08881ea9cf0e752bc48e61bbd71a34c029bb13df01e40e3e70e0d007bd
[INFO] oc: Writing manifest to image destination
[INFO] oc: Storing signatures
[INFO] oc: Adding transient rw bind mount for /run/secrets/rhsm
[INFO] oc: time="2024-03-28T12:48:57Z" level=warning msg="missing \"IMAGEVERSION\" build argument. Try adding \"--build-arg IMAGEVERSION=<VALUE>\" to the command line"
[INFO] oc: [1/2] STEP 1/3: FROM docker.io/alpine: AS builder

Sample Reproducer Project

No response

Additional context

Ran on Openshift 4
generatedbuildconfig.yaml.txt
The build config exported from openshift. Notice the args are available as ENV.
#1395 seems related.

@Snijder Snijder added the bug Something isn't working label Mar 28, 2024
@manusa
Copy link
Member

manusa commented Mar 28, 2024

I'm assuming that what you want is to replace the ${IMAGEVERSION} with whatever you define in the pom.xml and not really use an ARG.

For that, then you need to use a Maven property instead:

<properties>
   <IMAGEVERSION>latest</IMAGEVERSION>
</properties>

@Snijder
Copy link
Author

Snijder commented Mar 28, 2024

That works, and I am currently using it to work around it.

However, if I understand the documentation correctly (https://eclipse.dev/jkube/docs/openshift-maven-plugin/#_build_args) we should be able to set a build-arg using the configuration in the pom, but that sets an environment variable instead. Which is not what I was expecting.

@manusa
Copy link
Member

manusa commented Mar 28, 2024

We'll have to dig deeper into this. Not sure if this was accounted for while absorbing the Docker Maven Plugin related code.

@rohanKanojia rohanKanojia moved this to Planned in Eclipse JKube Apr 3, 2024
@sunix sunix self-assigned this Apr 9, 2024
@sunix sunix moved this from Planned to In Progress in Eclipse JKube Apr 9, 2024
@manusa manusa added this to the 1.17.0 milestone Apr 11, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Eclipse JKube Apr 11, 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
3 participants