PAUL MENA
PAUL MENA

Reputation: 117

Why is Gerrit in Docker not finding JAVA_HOME?

I've installed Gerrit into a Docker container, along with dependencies httpd and postgres. The docker-compose.yml file looks like this:

version: '3.1'

services:
  gerrit:
    image: gerritcodereview/gerrit
    environment:
      - CANONICAL_WEB_URL=http://ooi-pmo-prd02.whoi.edu:8080/
    volumes:
      - ./gerrit/etc:/var/gerrit/etc/
      - ./gerrit/git:/var/gerrit/git/
      - ./gerrit/index:/var/gerrit/index/
      - ./gerrit/cache:/var/gerrit/cache/
    ports:
      - "29418:29418"
    links:
      - postgres
    depends_on:
      - postgres

  apache:
    image: httpd
    volumes:
      - ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
      - ./httpd/.htpasswd:/usr/local/apache2/conf/.htpasswd
    ports:
      - "8080:80"

  postgres:
    image: postgres:9.6
    environment:
      - POSTGRES_USER=gerrit2
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=reviewdb
    volumes:
      - ./postgres/:/var/lib/postgresql/data

Apache and Postgres start up without issues, but Java fails to start on account of not being able to find a valid JDK or JRE, as if it's not seeing the JAVA_HOME environment variable or the javaHome option in my gerrit.config file (below):

[gerrit]
        basePath = git
        canonicalWebUrl = http://ooi-pmo-prd02.whoi.edu:8080/
        serverId = 85d6f505-5412-4eef-9f26-e844e9efd258
[database]
        type = postgresql
        hostname = localhost
        database = reviewdb
        username = gerrit2
[index]
        type = LUCENE
[auth]
        type = HTTP
        logoutUrl = http://aa:[email protected]:8080/logout
        httpHeader =
[sendemail]
        smtpServer = localhost
        smtpUser = gerrit2
[container]
        user = root
        javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
[httpd]
        listenUrl = http://ooi-pmo-prd02.whoi.edu:8080/
[cache]
        directory = cache
[sshd]
        listenAddress = *:29418
[user]
        name = gerrit2
        email = [email protected]

Upon startup, gerrit fails right away with this error:

pmena@ooi-pmo-prd02=> docker logs gerrit_gerrit_1
Running Gerrit ...
Cannot find a JRE or JDK. Please ensure that the JAVA_HOME environment
variable or container.javaHome in /var/gerrit/etc/gerrit.config is
set to a valid >=1.8 JRE location

And this is despite the fact that JAVA_HOME matches the JRE specified above - and it's valid:

pmena@ooi-pmo-prd02=> echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
pmena@ooi-pmo-prd02=> ls -l /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
total 4
drwxr-xr-x. 2 root root  172 Apr  9 14:04 bin
drwxr-xr-x. 9 root root 4096 Apr  9 14:02 lib
pmena@ooi-pmo-prd02=> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Is there some trick to getting Gerrit to "see" Java when it's running in a Docker container?

Upvotes: 1

Views: 1293

Answers (2)

geosmart
geosmart

Reputation: 666

docker-compose with image: gerritcodereview/gerrit:3.1.2

I exec -it to the gerrit get the java_home

bash-4.2$ ls -hl  /usr/lib/jvm/
total 0
drwxr-xr-x. 3 root root 17 Dec 14  2019 java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
lrwxrwxrwx. 1 root root 21 Dec 14  2019 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Dec 14  2019 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx. 1 root root 35 Dec 14  2019 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx. 1 root root 51 Dec 14  2019 jre-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64 -> java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
lrwxrwxrwx. 1 root root 29 Dec 14  2019 jre-openjdk -> /etc/alternatives/jre_openjdk

so you can set container in gerrit.config

[container]
  user = gerrit
  javaOptions = -Dfile.encoding=UTF-8
  javaHome = "/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre"

Upvotes: 1

PAUL MENA
PAUL MENA

Reputation: 117

By typing docker run --rm -it --entrypoint /bin/cat gerritcodereview/gerrit /var/gerrit/etc/gerrit.config I was able to find what gerrit was expecting for its Java configuration, which I entered under the [container] section of the gerrit.config file. To confirm that I was using the correct "javaHome", I did the following within the Gerrit container:

pmena@ooi-pmo-prd02=> docker run --rm -it --entrypoint /bin/bash gerritcodereview/gerrit
bash-4.2$ ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 73 Nov 15  2019 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/bin/java
bash-4.2$ ls -l /etc/alternatives/jre
lrwxrwxrwx. 1 root root 64 Nov 15  2019 /etc/alternatives/jre -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre

Upvotes: 0

Related Questions