micronaut-gradle-plugin icon indicating copy to clipboard operation
micronaut-gradle-plugin copied to clipboard

Cannot locate specified Dockerfile on 1.4.3

Open botcoder opened this issue 4 years ago • 6 comments
trafficstars

My company uses a custom Dockerfile for pipeline builds on Linux, and the dockerBuild task, that used to pick it up from there when using id("io.micronaut.application") version "1.4.2"

After upgrading the plugin from v1.4.2 to v1.4.3 (in fact, 1.5.0, but the issue goes back to 1.4.3), the dockerBuild task stopped working with the following error:

com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"Cannot locate specified Dockerfile

Dowgrading to v1.4.2 fixes the issue. There was some major changes from build to layers between versions but I couldn't find quickly what could be the root cause of it. I tried running with --debug but it loops infinitely on gradle 7.0, so back to 1.4.2 for now.

botcoder avatar May 31 '21 15:05 botcoder

@botcoder to be clear. You have your own Dockerfile in the root of the project and in 1.4.2 that was picked up and in 1.4.3+ it is not and it fails with that error, right?

ilopmar avatar May 31 '21 16:05 ilopmar

Yes, exactly. Sorry, I forgot to mention the steps to reproduce:

  1. Create a project using the latest version on micronaut launch, with Kotlin, Kotlin Gradle
  2. Unzip demo.zip and build it
  3. Copy a sample Dockerfile to the project root
FROM amazoncorretto:11.0.8-alpine

ARG PORT=8080
ARG JAR_FILE=./build/libs/*-all.jar

COPY ${JAR_FILE} mn.jar

EXPOSE ${PORT}
ENTRYPOINT ["java", "-jar", "mn.jar", "-Dmicronaut.env.deduction=false", "-Dio.netty.tryReflectionSetAccessible=true", "-Dio.netty.allocator.maxOrder=8"]
  1. Run ./gradlew dockerBuild

The build fails on Linux with "error 500" as described above.

botcoder avatar May 31 '21 17:05 botcoder

Using Micronaut 2.5.4 I can reproduce something similar:

mn create-app nativedemo
cd nativedemo
./gradlew dockerfileNative
cp build/docker/DockerfileNative .
./gradlew dBN
> Task :dockerBuildNative FAILED
Building image using context '/Users/jeffscottbrown/nativedemo/build'.
Using Dockerfile '/Users/jeffscottbrown/nativedemo/DockerfileNative'
Using images 'nativedemo'.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dockerBuildNative'.
> Status 500: {"message":"Cannot locate specified Dockerfile: /Users/jeffscottbrown/nativedemo/DockerfileNative"}

jeffscottbrown avatar Jun 02 '21 19:06 jeffscottbrown

This also happens with 1.5.3 (and 2.0.1)

ilopmar avatar Jun 30 '21 11:06 ilopmar

I just experienced this issue myself, upgrading from 1.3.x to 2.0.3. I believe it is related to https://github.com/micronaut-projects/micronaut-gradle-plugin/commit/9cb1c7276188f9c14b21e7b636500d87764d9364#diff-1688c2b22824bc4aa6b0bfbea6ec2555adcda38a39c352b77dd37706bda4c153L184.

I resolved it with the following configuration in my build.gradle

dockerBuild {
  ...
  inputDir = project.projectDir
}

A possible fix would be to set the inputDir to the project dir when using a project local Dockerfile. The IF statement is already there.

frossbeamish avatar Aug 20 '21 18:08 frossbeamish

The cause is currently gradle plugin uses context folder build inside "build" dir but custom Dockerfile is located in the root

Building image using context '<project-dir>/build/docker'.
Using Dockerfile '<project-dir>/Dockerfile'

You can use next workaround:

// https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/214
task fixIssue214(type: Copy){
    from ('Dockerfile')
    into "${buildDir}/docker"
}

dockerBuild.dockerFile.set(file("${buildDir}/docker/Dockerfile"))
// ^^^

call task fixIssue214 before the build like: "gw clean fixIssue214 dockerBuild"

katoquro avatar Aug 29 '21 18:08 katoquro