Transmode / gradle-docker

A Gradle plugin to build Docker images from the build script.
Apache License 2.0
647 stars 142 forks source link

Fix DockerTask.getBaseImage() and add Java 9 base image #135

Closed franzbecker closed 6 years ago

franzbecker commented 6 years ago

The DockerTask.getBaseImage() method is currently not implemented correctly.

I had the following setup:

sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9

docker {
    baseImage = "openjdk:9-jre"
}

and it still failed with:

Caused by: java.lang.IllegalArgumentException: No Java base image for the supplied target 1.9 found.
        at se.transmode.gradle.plugins.docker.JavaBaseImage.imageFor(JavaBaseImage.java:42)
        at se.transmode.gradle.plugins.docker.JavaBaseImage$imageFor.call(Unknown Source)
        at se.transmode.gradle.plugins.docker.DockerTask.determineBaseImage(DockerTask.groovy:81)

This is due to the fact that the base image for the specified Java version is still retrieved (and fails). In this case there is no need to retrieve it as an explicit base image is specified.

codecov-io commented 6 years ago

Codecov Report

Merging #135 into master will increase coverage by 0.93%. The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #135      +/-   ##
===========================================
+ Coverage     58.16%   59.1%   +0.93%     
  Complexity       82      82              
===========================================
  Files             9       9              
  Lines           306     313       +7     
  Branches         24      25       +1     
===========================================
+ Hits            178     185       +7     
  Misses          116     116              
  Partials         12      12
Impacted Files Coverage Δ Complexity Δ
.../transmode/gradle/plugins/docker/DockerTask.groovy 70.45% <100%> (+4.66%) 15 <4> (ø) :arrow_down:
...transmode/gradle/plugins/docker/JavaBaseImage.java 76.92% <100%> (+1.92%) 3 <0> (ø) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 48636f4...23d4e54. Read the comment docs.

bjornmagnusson commented 6 years ago

Thanks for the contribution, looks good to me.

gunkelolaf commented 6 years ago

even though this pullrequest is merged, no new version was released @bjornmagnusson could you please release a new version?

philbrock commented 4 years ago

For anyone stuck with this issue and awaiting a new release, the workaround is to supply a partial Dockerfile that just defines whatever baseImage you're after.

e.g. in your docker task definition: dockerfile='docker/Dockerfile'

And the contents of that docker/Dockerfile: FROM openjdk:11-jre