testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Unable to pre-fetch an image when using build-args in FROM

Open AB-xdev opened this issue 5 years ago • 7 comments

We are using the following:

new ImageFromDockerfile()
	.withDockerfile(Paths.get("Dockerfile"))
...

Dockerfile

ARG tag=latest
FROM maven:3-openjdk-11 AS build-env
# Build
FROM domain.com/package/image:${tag}
# Copy builded stuff into container

This throws an exception, as it trys to pre-fetch an image:

11:25:48 INFO  [ducttape-0] [ilder.ImageFromDockerfile] Pre-emptively checking local images for 'domain.com/package/image:${tag}', referenced via a Dockerfile. If not available, it will be pulled.  
11:25:48 ERROR [tc-okhttp-stream-1066222696] [nc.ResultCallbackTemplate] Error during callback  
com.github.dockerjava.api.exception.BadRequestException: {"message":"invalid reference format"}

	at com.github.dockerjava.okhttp.OkHttpInvocationBuilder.execute(OkHttpInvocationBuilder.java:283)
	at com.github.dockerjava.okhttp.OkHttpInvocationBuilder.lambda$executeAndStream$4(OkHttpInvocationBuilder.java:317)
	at java.base/java.lang.Thread.run(Thread.java:834)
11:25:48 WARN  [ducttape-0] [ilder.ImageFromDockerfile] Unable to pre-fetch an image (domain.com/package/image:${tag}) depended upon by Dockerfile - image build will continue but may fail. Exception message was: {"message":"invalid reference format"}

It would be nice

  • if the code which pre-fetches/pulls the dependencies would automatically consider the use of args and either uses them to download the image or simply ignores it
  • OR if there is an option to disable the pre-fetching/pulling

AB-xdev avatar Sep 16 '20 11:09 AB-xdev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

stale[bot] avatar Dec 19 '20 07:12 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open...

It would be great if the issue stays open, because the problem still exists.

AB-xdev avatar Jan 07 '21 06:01 AB-xdev

I've also come across this issue when trying to move our tests to using .withDockerfile(Paths.get("Dockerfile")) so we could use .dockerignore files to minimise our build context.

I'll try and contribute a PR if i can get around to it

jarebudev avatar Mar 20 '21 09:03 jarebudev

Would be great to see this resolved. Is anything special missing from the PR? I was willing to contribute one as well, but seeing as how there's one opened already, I'd rather see it merged :+1:

npepinpe avatar Nov 01 '22 09:11 npepinpe

We still face this issue. Can someone please have a look at #6119 to get this fixed?

Donnerbart avatar Oct 04 '23 10:10 Donnerbart

So the problem is still sticking around after 3.5years...

We fixed this a few years ago internally for one of our non public projects and now open sourced these fixes in our own implementation of ImageBuilder. Feel free to use it in the meantime :)

AB-xdev avatar Apr 23 '24 13:04 AB-xdev

I'm happy to rebase my pending PR if someone will finally review it. We also have workarounds in place for this, that I'd really like to get rid of.

Donnerbart avatar Apr 24 '24 02:04 Donnerbart