fnproject/fdk-java

error running java in fn-java-fdk-build:jdk9-latest docker image

Closed this issue · 3 comments

Hi,

I tried to run a java function in fn, but I got the following error

$sudo fn run
Building image xxx/xxx:0.0.10
Sending build context to Docker daemon  72.19kB
Step 1/11 : FROM fnproject/fn-java-fdk-build:jdk9-latest as build-stage
jdk9-latest: Pulling from fnproject/fn-java-fdk-build
3f84388a3335: Already exists
5af7807a0ec3: Already exists
09d580f15c0b: Already exists
23a3b03fc984: Already exists
08022c1872b4: Already exists
ea733b0154e4: Pull complete
eb337c138275: Pull complete
713f0a7fd50b: Pull complete
0d5d9b25d97b: Pull complete
b6d0604a0963: Pull complete
a1faa3b40025: Pull complete
62988b881ae7: Pull complete
a117f344a64f: Pull complete
6f7ed3e6370c: Pull complete
Digest: sha256:13ef2b43fce6cb13c15993f6baa159ebc4b207a2429b247e07089fe9ef8fd9ab
Status: Downloaded newer image for fnproject/fn-java-fdk-build:jdk9-latest
 ---> f9d235fdddf7
Step 2/11 : WORKDIR /function
 ---> aad0e2e2c2be
Removing intermediate container 8018a01ad48c
Step 3/11 : ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
 ---> Running in 6d3948c5ff0b
 ---> 3d4ef0541bfe
Removing intermediate container 6d3948c5ff0b
Step 4/11 : ADD pom.xml /function/pom.xml
 ---> bf7c5e14fb0d
Step 5/11 : RUN mvn package dependency:copy-dependencies -DincludeScope=runtime -DskipTests=true -Dmdep.prependGroupId=true -DoutputDirectory=target --fail-never
 ---> Running in 628bf9f836b8
/docker-java-home/bin/java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
The command 'mvn package dependency:copy-dependencies -DincludeScope=runtime -DskipTests=true -Dmdep.prependGroupId=true -DoutputDirectory=target --fail-never' returned a non-zero code: 127
ERROR: error running docker build: exit status 127

The images that I've downloaded:

$sudo docker images
REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
<none>                                               <none>              bf7c5e14fb0d        19 minutes ago      407MB
fnproject/fn-java-fdk-build                          jdk9-latest         f9d235fdddf7        6 hours ago         407MB
fnproject/functions                                  latest              839b553dbbe7        2 days ago          143MB

When you dig into the fnproject/fn-java-fdk-build:jdk9-latest, actually I've found that the same error.

$sudo docker run -ti fnproject/fn-java-fdk-build:jdk9-latest /bin/bash
root@a7c1451c7413:/# ls
bin   dev               etc   lib    lib64   media  opt   root  sbin  sys  usr
boot  docker-java-home  home  lib32  libx32  mnt    proc  run   srv   tmp  var
root@a7c1451c7413:/# /docker-java-home/bin/java
/docker-java-home/bin/java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
root@a7c1451c7413:/#

I think there is something wrong with the image.

Hi

I was able to run the java command by manually adding /usr/lib/jvm/java-9-openjdk-amd64/lib:/usr/lib/jvm/java-9-openjdk-amd64/lib/jlito LD_LIBRARY_PATH

$sudo docker run -ti --entrypoint=/bin/bash fnproject/fn-java-fdk-build:latest
root@dad121887778:/# export LD_LIBRARY_PATH=/usr/lib/jvm/java-9-openjdk-amd64/lib:/usr/lib/jvm/java-9-openjdk-amd64/lib/jli
root@dad121887778:/# /usr/lib/jvm/java-9-openjdk-amd64/bin/java -version
openjdk version "9-Debian"
OpenJDK Runtime Environment (build 9-Debian+0-9b181-4)
OpenJDK 64-Bit Server VM (build 9-Debian+0-9b181-4, mixed mode)
root@dad121887778:/#

But if I run fn run with --env option, the problem still exist.

$sudo fn run --env LD_LIBRARY_PATH=/usr/lib/jvm/java-9-openjdk-amd64/lib:/usr/lib/jvm/java-9-openjdk-amd64/lib/jli
Building image xxx/xxx:0.0.10
Sending build context to Docker daemon  72.19kB
Step 1/11 : FROM fnproject/fn-java-fdk-build:jdk9-latest as build-stage
 ---> f9d235fdddf7
Step 2/11 : WORKDIR /function
 ---> Using cache
 ---> aad0e2e2c2be
Step 3/11 : ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
 ---> Using cache
 ---> 3d4ef0541bfe
Step 4/11 : ADD pom.xml /function/pom.xml
 ---> Using cache
 ---> bf7c5e14fb0d
Step 5/11 : RUN mvn package dependency:copy-dependencies -DincludeScope=runtime -DskipTests=true -Dmdep.prependGroupId=true -DoutputDirectory=target --fail-never
 ---> Running in 4e4308bf4ef5
/docker-java-home/bin/java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
The command 'mvn package dependency:copy-dependencies -DincludeScope=runtime -DskipTests=true -Dmdep.prependGroupId=true -DoutputDirectory=target --fail-never' returned a non-zero code: 127
ERROR: error running docker build: exit status 127

Hi,

I've figured out the reason is that the fn build command does not pass the env option when generating Dockerfile.
I have work-around for this issue, by adding a customized dockerfile along with the func.yaml.

.
├── Dockerfile
├── func.yaml
├── hello.iml
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── example
    │               └── fn
    │                   ├── HelloFunction.java
    └── test
        └── java
            └── com
                └── example
                    └── fn
                        └── HelloFunctionTest.java

The content of Dockerfile:

FROM fnproject/fn-java-fdk-build:jdk9-latest as build-stage
WORKDIR /function
ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
ADD pom.xml /function/pom.xml
RUN ["mvn", "package", "dependency:copy-dependencies", "-DincludeScope=runtime", "-DskipTests=true", "-Dmdep.prependGroupId=true", "-DoutputDirectory=target", "--fail-never"]
ADD src /function/src
RUN ["mvn", "package"]
FROM fnproject/fn-java-fdk:jdk9-latest
ENV LD_LIBRARY_PATH=/usr/lib/jvm/java-9-openjdk-amd64/lib:/usr/lib/jvm/java-9-openjdk-amd64/lib/jli
WORKDIR /function
COPY --from=build-stage /function/target/*.jar /function/app/
CMD ["com.example.fn.HelloFunction::testMethod"]

Simply added one line:

ENV LD_LIBRARY_PATH=/usr/lib/jvm/java-9-openjdk-amd64/lib:/usr/lib/jvm/java-9-openjdk-amd64/lib/jli

This works as expected.

fn run is no longer supported, so closing this.