I am trying to integrate SonarQube into my CI process. I tried to install SonarScanner in Docker, but it appears it cannot find java tho it can be run
Dockerfile
# Docker, AWS CLI, Terraform, NodeJS
FROM docker:18-dind
RUN echo "1"
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk update
RUN apk add awscli nodejs nodejs-npm wget unzip jq openjdk11
RUN wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip
RUN unzip terraform_0.11.13_linux_amd64.zip
RUN mv terraform /usr/local/bin
RUN npm i -g sequelize sequelize-cli mysql2
RUN wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873.zip
RUN unzip sonar-scanner-cli-4.2.0.1873.zip
RUN ls sonar-scanner-4.2.0.1873
ENV PATH="/sonar-scanner-4.2.0.1873/bin:${PATH}"
RUN which java
ENV JAVA_HOME=/usr/bin
RUN echo $PATH
RUN java --version
RUN ls /sonar-scanner-4.2.0.1873/bin
RUN sonar-scanner --help
The logs
Step 15/20 : RUN which java
---> Running in 96b487f5b44f
/usr/bin/java
Removing intermediate container 96b487f5b44f
---> 5026de427a57
Step 16/20 : ENV JAVA_HOME=/usr/bin
---> Running in 4d7eee221e41
Removing intermediate container 4d7eee221e41
---> 76b9a8b9d803
Step 17/20 : RUN echo $PATH
---> Running in 4278142f7153
/sonar-scanner-4.2.0.1873/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 4278142f7153
---> c3d528bdaa7e
Step 18/20 : RUN java --version
---> Running in 7df7e2d8a441
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-alpine-r0)
OpenJDK 64-Bit Server VM (build 11.0.5+10-alpine-r0, mixed mode)
Removing intermediate container 7df7e2d8a441
---> 0f7162dae25d
Step 19/20 : RUN ls /sonar-scanner-4.2.0.1873/bin
---> Running in b7efb86cd86e
sonar-scanner
sonar-scanner-debug
sonar-scanner-debug.bat
sonar-scanner.bat
Removing intermediate container b7efb86cd86e
---> ff640a70876f
Step 20/20 : RUN sonar-scanner --help
---> Running in 9164ac2e8369
Could not find 'java' executable in JAVA_HOME or PATH.
The command '/bin/sh -c sonar-scanner --help' returned a non-zero code: 1
Notice which java gives /usr/bin/java. So I set JAVA_HOME=/usr/bin. java can run. But sonar-scanner cannot appear to find java ... why is that?
Add JAVA_HOME ENV according to version, as mentioned #cricket_007 the path in alpine for JDK is /usr/lib/jvm/{VERSION}
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
ENV PATH="$JAVA_HOME/bin:${PATH}"
RUN echo $PATH
run docker
docker run --privileged -it --rm sonar-s sonar-scanner --version
output
INFO: Scanner configuration file: /sonar-scanner-4.2.0.1873/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 4.2.0.1873
INFO: Java 11.0.5 Alpine (64-bit)
INFO: Linux 4.14.70-67.55.amzn1.x86_64 amd64
Related
I am new to VisualVM and trying to monitor some application which is deployed on Tomcat 9 CentOS server. I have installed VisualVM on my Windows laptop and trying to remote connect to the JVM on the CentOS server, but nothing is displayed (message on VisualVM: Not supported for this JVM).
Please find below Java version installed on CentOS server:
[root#localhost bin]# java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
Based on the online resource I saw, I need to enable JMX on Tomcat, so I have added the following properties in my setenv.sh (in tomcat/bin folder) file:
export CATALINA_OPTS="\
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=8999 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false"
I have downloaded the latest VisualVM and created a remote host via File->Add Remote Host. Then Add JMX Connection info as follows:
connection:dymmyip:8999
username :user
Password :dummyPassword
uncheck :do not require ssl
When I try to connect, the following screen is displayed:
Can anyone tell me please what I am missing here?
You can add the missing =true in your setenv.sh
export CATALINA_OPTS="\
-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.port=8999 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false"
You have to chmod you setenv.sh too:
$ cd <your-tomcat-dir>/bin
$ chmod a+x setenv.sh
Be sure it is not a firewall issue. Test the connection with telnet dummyip 8999
Be sure using the same JVM on both VisualVM and Tomcat. (Be careful with architecture too: 32 or 64bits)
You can get the last release of VisualVM here.
To install it:
$ [ -f "/usr/bin/visualvm" ] && sudo mv /usr/bin/visualvm{,.old}
$ wget https://github.com/oracle/visualvm/releases/download/2.1.4/visualvm_214.zip
$ unzip visualvm_214.zip
$ sudo mv visualvm_214 /opt/
$ sudo ln -s /opt/visualvm_214/bin/visualvm /usr/bin/
$ visualvm --jdkhome /usr/lib/jvm/java-17-openjdk-amd64
Use the path you want in --jdkhome.
I have Java app and want to generate docker image, I have shell script like this:
#!/bin/sh
java -version
export APPLICATION_DIR=$PWD
for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`
do
export CLASSPATH=$rJarFile:$CLASSPATH
done
export CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
java -Xverify:none -Xmx2048m -Djava.awt.headless=true -DFI_IS_CONFIGSER=N -DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1 -DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties -DFEBA_SYS_PATH=${APPLICATION_DIR}/data
And I try to convert it into Dockerfile like this
# FROM openjdk:8
FROM openjdk:11
RUN javac -version
# Create app directory
WORKDIR /usr/src/app
# Bundle app source
COPY . .
ENV APPLICATION_DIR=/usr/src/app
RUN echo $APPLICATION_DIR
RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export CLASSPATH=$rJarFile:$CLASSPATH; done
RUN echo $CLASSPATH
ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
# Run app
ENTRYPOINT ["java", "-Xverify:none", "-Xmx2048m", "-Djava.awt.headless=true", "-DFI_IS_CONFIGSER=N", "-DFICLIENT_APP_PATH=${APPLICATION_DIR} -DFI_APP_NAME=FIONLINE -DFI_BASE_INSTANCE_ID=1", "-DPRODUCT_BOOTSTRAP_FILE=${APPLICATION_DIR}/data/BootstrapFile.properties", "-DFEBA_SYS_PATH=${APPLICATION_DIR}/data"]
It can be generated, but there's an error when I try to run it like this:
Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: setenv: invalid argument: unknown
I've also changed this script RUN for rJarFile in `ls ${APPLICATION_DIR}/lib/*.jar`; do export into this RUN for rJarFile in ls ${APPLICATION_DIR}/lib/*.jar; do export CLASSPATH=$rJarFile:$CLASSPATH; done, but none of them working. I don't want to make Dockerfile execute the script. Below is logs when i generate and run it.
You cannot update the classpath as you do with:
ENV $CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
instead you can do
ENV CLASSPATH=$APPLICATION_DIR/classes:$CLASSPATH
Also - please consider moving the script into a separate shell script and adding into the container. This would greatly simplify the Dockerfile, for example:
# FROM openjdk:8
FROM openjdk:11
RUN javac -version
# Create app directory
WORKDIR /usr/src/app
# Bundle app source
COPY . .
ENV APPLICATION_DIR=/usr/src/app
RUN echo $APPLICATION_DIR
ENTRYPOINT ["/usr/src/app/start_java.sh"]
and keep your existing script inside start_java.sh
I deployed a Python project on Google App Engine. As the project has a dependency on Java, I used a Docker container configuring two environments: Python + Java.
However, when I make a call to my Python service in GAE it's getting "java command is not found from this Python process. Please ensure Java is installed and PATH is set for java" error.
During the build process of the Docker file I am able to access Java after installing it. But during API execution it is not recognized by Python.
The "app.yaml" file used:
runtime: custom
env: flex
entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker src.main:app
Below are the the Docker file used in Deploy:
### 1. Get Linux
FROM alpine:3.7
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
### 2. Get Java via the package manager
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --virtual=build-dependencies unzip \
&& apk add --no-cache curl \
&& apk add --no-cache openjdk8-jre
#### OPTIONAL : 4. SET JAVA_HOME environment variable, uncomment the line below if you need it
ENV JAVA_HOME="/usr/lib/jvm/java-1.8-openjdk"
RUN export JAVA_HOME
ENV PATH $PATH:$JAVA_HOME/bin
RUN export PATH
RUN find / -name "java"
RUN java -version
FROM python:3.7
EXPOSE 8080
ENV APP_HOME /src
WORKDIR /src
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . /src
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8080"]
Here is a printout of the RUN java -version command during the deploy process:
RUN java -version command
Does anyone know why the error is happening even with Python and Java running on the same service on App Engine?
Are there any additional settings missing?
You are using two FROM in a Dockerfile, so you're effectively doing a multi-stage Docker build, but you are doing it wrong.
A multi-stage build should be something like this:
### 1. Get Linux
FROM alpine:3.7 as build
# here you install with apk and build your Java program
FROM python:3.7
EXPOSE 8080
...
# here you copy what you need from the previous Docker build, though
# since it was Java, which is not installed here anymore because it is
# a python image, you need to consider if you really need a multi-stage
# build
COPY --from=builder /src /src
Otherwise, just remove the second FROM python:3.7 and install it with apk.
I have a Ubuntu server with a WildFly standalone installation configured, here i have a Java app that is accesible on port 80, i want to dockerize it. When create the container, i'm copying the entire WildFly directory from my local storage to the container, when i run the command docker run -d --name dej_website -p 80:80 wildfly_dej_website:2.0 the container start, but when try to access in my local machine localhost doesn't works.
What am i doing wrong? How can i do to access to this container, with the configured server?
This is my dockerfile
FROM centos
#INSTALL JAVA
RUN yum -y install java-11-openjdk
RUN java -version
RUN mkdir /opt/DEJ_Wildfly/
#SET OPT AS WORK DIRECTORY
WORKDIR /opt/DEJ_Wildfly/
#COPY WILDFLY SERVER FILES
COPY wildfly-11.0.0.Final .
#DEFINE ENVIRONMENT VARIABLE
ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/
#EXECUTE SH FILE
CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
CMD tail -f /var/log/lastlog
#EXPOSE 80
This is the log of docker build --tag wildfly_dej_website:2.0 . command:
Sending build context to Docker daemon 597.4MB
Step 1/9 : FROM centos
---> 300e315adb2f
Step 2/9 : RUN yum -y install java-11-openjdk
---> Using cache
---> f333f6149e02
Step 3/9 : RUN java -version
---> Using cache
---> 0110143899c7
Step 4/9 : RUN mkdir /opt/DEJ_Wildfly/
---> Running in 88bc6f0632c1
Removing intermediate container 88bc6f0632c1
---> c0ab7cc8a364
Step 5/9 : WORKDIR /opt/DEJ_Wildfly/
---> Running in 84705355ac2c
Removing intermediate container 84705355ac2c
---> 6986f8229cb0
Step 6/9 : COPY wildfly-11.0.0.Final .
---> 3caf8ec0e5d0
Step 7/9 : ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/
---> Running in b5f649e4e2e0
Removing intermediate container b5f649e4e2e0
---> 27d775c3d0cb
Step 8/9 : CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
---> Running in c7ffddb4bcdf
Removing intermediate container c7ffddb4bcdf
---> 533d3836f94d
Step 9/9 : CMD tail -f /var/log/lastlog
---> Running in f92aca5a63ba
Removing intermediate container f92aca5a63ba
---> 974e6ec6c415
Successfully built 974e6ec6c415
Successfully tagged wildfly_dej_website:2.0
This is the list of containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95ee0139f42c wildfly_dej_website:2.0 "/bin/sh -c 'tail -f…" 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp dej_website
The problem here is in your dockerfile.
You need to add a CMD at the end of your dockerfile to run the command you want and keep it running for the docker file to stay alive and provide you with logs through docker logs command.
Add a line like this to your dockerfile:
RUN ./standalone.sh -b 0.0.0.0
CMD tail -f /var/log/syslog
And to make the port accessible on the local machine you'll need to use -p option when issuing the docker run command like this:
docker run -d -p 127.0.0.1:80:8080 <image>
you can find out more here:
https://docs.docker.com/engine/reference/commandline/run/
I am trying to configure Alpine with Oracle JDK. I have downloaded the JDK and am copying it into my image and using it there.
When I run which java it reports back the correct path /jdk-11.0.10/bin/java but when I try to run any java command it says it is not found.
I tried to reference some info from
https://wiki.alpinelinux.org/wiki/Installing_Oracle_Java
WRT how to do this but I'm not having any luck.
Any input would be appreciated!
FROM alpine
RUN apk add freetype fontconfig paxctl
COPY jdk-11.0.10_linux-x64_bin.tar.gz /
RUN tar -xf jdk-11.0.10_linux-x64_bin.tar.gz
ENV JAVA_HOME /jdk-11.0.10
ENV PATH ${JAVA_HOME}/bin:${PATH}
CMD echo ${PATH}
CMD echo which java
RUN paxctl -c java
RUN paxctl -m java
RUN paxctl -c javac
RUN paxctl -m javac
CMD java -version