Specifically for this guide we want to have the same Dockerfile work for Maven and Gradle (I know it's slightly artificial, but we always try and support both)
In the Maven plugin as soon as you use an external Dockerfile everything else is ignored
So maybe I prefer your approach slightly, but we still have to work around one or the other
Matthias Grüter
@mattgruter
Ok, I see. Looking at the guide right now.
So you're copying your jar file into the docker stageDir (build/docker) manually.
Dave Syer
@dsyer
Yes
And that also means we have to define a custom task
Matthias Grüter
@mattgruter
Wouldn't something like:
copy {
from jar
into stageDir
}
work?
Dave Syer
@dsyer
and that it has to be deferred with "<<"
I'm not a gradler. Happy to take edits.
Where does that go?
Inside the task definition?
Matthias Grüter
@mattgruter
Yes, instead of the new File(stageDir, jar.archiveName).bytes = jar.archivePath.bytes
Dave Syer
@dsyer
Trying it...
Dave Syer
@dsyer
I don't think that worked
the image it builds has the same ID as docker/java
Actually that's a problem with the "<<" (cc @gregturn)
Matthias Grüter
@mattgruter
Exactly. The dockerfile, applicationName and push properties have to be defined in the configuration phase of the build not the execution phase (with the "<<" you push everything into the execution phase)
Dave Syer
@dsyer
Yeah. I'm unhacking that now.
Then the copy{} works, thanks
Matthias Grüter
@mattgruter
This should work:
task buildDocker(type: Docker, dependsOn: jar) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
Dave Syer
@dsyer
@gregturn thought he found a problem that meant he had to defer to execution
It works for me though
_
Actually that doesn't
You have to "dependsOn: build"
(which I assumed would be the default - haven't tried that yet)
How come I have to explicitly create a java.io.File() for the dockerfile BTW?
Yeah you need "dependsOn: build"
but the copy actually doesn't work
doFirst
Missed that
I hate gradle sometimes
Do you think we could make this use case more mainstream in the plugin? That would help idiots like me.