GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.88k stars 1.44k forks source link

After build a image using kaniko the java compiler cannot be find be maven on a jenkins node #1671

Open qalinn opened 3 years ago

qalinn commented 3 years ago

Actual behavior After the build image using kaniko on a jenkins node maven cannot find the javac.

Expected behavior After the build of an image using kaniko you must be able to continue use maven and java on a container. To Reproduce Steps to reproduce the behavior:

  1. Create a docker image with java, maven and kaniko 1.6.0 inside. In my case I have created a jenkins agent:
    FROM gcr.io/kaniko-project/executor:v1.6.0 as kaniko 
    FROM jenkins/inbound-agent:4.7-1-jdk11 
    USER root 
    ENV JAVA_OPTS -XX:-UsePerfData 
    RUN apt-get update && apt-get install -y --no-install-recommends apt-transport-https ca-certificates gnupg2 software-properties-common maven 
    COPY --from=kaniko /kaniko /kaniko 
    RUN cp /kaniko/executor /kaniko/kaniko-executor 
    COPY ./config.json /kaniko/.docker/ 
    ENV PATH=$PATH:/kaniko 
    ENV DOCKER_CONFIG=/kaniko/.docker/ 
    WORKDIR /kaniko
  2. Run a container based on the previous docker file.
  3. Build a java project using maven inside of the container previously created.
  4. Build a docker file using kaniko inside of the container previously created.
  5. Try to build again the java project using maven.
  6. The maven has complained cannot find the javac. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
  7. Before to run kaniko build I have executed the following commands:
    + which javac
    /usr/local/openjdk-11/bin/javac
    **+ javac --version
    Picked up _JAVA_OPTIONS: -Djdk.net.URLClassPath.disableClassPathURLCheck=true
    javac 11.0.10**
    [Pipeline] sh
    + echo ---1-------
    + ls -la /usr/local/openjdk-11/
    total 44
    drwxr-xr-x  1 root root 4096 Mar 12 23:13 .
    drwxr-xr-x  1 root root 4096 Mar 12 23:13 ..
    drwxrwxr-x  2 root root 4096 Jan 12 11:31 bin
    drwxrwxr-x  4 root root 4096 Jan 12 11:31 conf
    drwxrwxr-x  4 root root 4096 Jan 12 11:31 demo
    drwxrwxr-x  3 root root 4096 Jan 12 11:31 include
    drwxrwxr-x  2 root root 4096 Jan 12 11:31 jmods
    drwxrwxr-x 73 root root 4096 Jan 12 11:31 legal
    drwxrwxr-x  1 root root 4096 Jan 12 11:31 lib
    drwxrwxr-x  4 root root 4096 Jan 12 11:31 man
    -rw-rw-r--  1 root root 1220 Jan 12 11:31 release
    + ls -la /usr/local/openjdk-11/bin/javac
    **-rwxrwxr-x 1 root root 13173 Jan 12 11:31 /usr/local/openjdk-11/bin/javac**
  8. After the kaniko build I have executed the same commands:
    which javac
    /usr/local/openjdk-11/bin/javac
    [Pipeline] sh
    + echo ---2-------
    + ls -la /usr/local/openjdk-11/
    total 68
    drwxr-xr-x 1 root root 4096 Jun 15 00:13 .
    drwxr-xr-x 1 root root 4096 Jun 15 00:12 ..
    drwxrwxr-x 1 root root 4096 Jun 15 00:13 bin
    drwxrwxr-x 1 root root 4096 Jun 15 00:13 conf
    drwxrwxr-x 4 root root 4096 Jan 12 11:31 demo
    drwxrwxr-x 3 root root 4096 Jan 12 11:31 include
    drwxrwxr-x 2 root root 4096 Jan 12 11:31 jmods
    drwxrwxr-x 1 root root 4096 Jan 12 11:31 legal
    drwxrwxr-x 1 root root 4096 Jun 15 00:13 lib
    drwxrwxr-x 1 root root 4096 Jun 15 00:13 man
    -rw-rw-r-- 1 root root  999 Apr  9 14:24 release
    + ls -la /usr/local/openjdk-11/bin/javac
    -rwxrwxr-x 1 root root 13173 Jan 12 11:31 /usr/local/openjdk-11/bin/javac
    + javac --version
    Picked up _JAVA_OPTIONS: -Djdk.net.URLClassPath.disableClassPathURLCheck=true
    Error occurred during initialization of boot layer
    java.lang.module.FindException: Module jdk.compiler not found
  9. The javac seems to be there but the maven cannot see.
  10. I have tried without kaniko and is working.
  11. For build kaniko image I have used the following command:
    kaniko-executor --force --context=. --dockerfile=Dockerfile --use-new-run=true \
                            --cache \
                            --cache-repo=repo/all-repos-cache \
                            --no-push \
                            --destination=repo/image
  12. Is the same results without cache flag. Additional Information

    • Dockerfile FROM openjdk:11-jre VOLUME /tmp COPY fileA /root/somefolder/fileA COPY some.jar some.jar COPY app.jar app.jar RUN mkdir -p /root/localFolder/local/system ; \ echo "READY" > /root/localFolder/local/system/status.trigger;
      ENTRYPOINT ["java", "some params" "-jar", "/app.jar"]

    • Build Context Please provide or clearly describe any files needed to build the Dockerfile (ADD/COPY commands)

    • Kaniko Image (fully qualified with digest)

    Triage Notes for the Maintainers

    Description Yes/No
    Please check if this a new feature you are proposing
    • - [ ]
    Please check if the build works in docker but not in kaniko
    • - [x]
    Please check if this error is seen when you use --cache flag
    • - [x]
    Please check if your dockerfile is a multistage dockerfile
    • - [ ]
qalinn commented 3 years ago

Any help will be appreciated.