Travis CI - Run LWJGL Tests in Non-Headless Environment? - java

I'm trying to run some tests on Travis CI that require a server that's, err... Not headless. As you can tell, I know so little about the area I don't even know the right terminology to use.
The tests use LibGDX and LWJGL. They work fine on my desktop (Windows 8 and Ubuntu), but unsurprisingly fail in Travis CI:
Could not initialize class org.lwjgl.Sys
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setVSync(LwjglGraphics.java:446)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:118)
Can I do anything with Travis CI to make it think it has a proper display? Even if this is not possible with Travis CI, is there a generic approach that I could perhaps take with another VM I have more control over?

This can be done with xvfb. In your travis.yml, add this:
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
You will have to install xvfb if you don't already have it. You may also have to install the other libs/packages needed by your tests on the VM (for e.g. for web app tests, you would need a browser).

Starting a virtual framebuffer (xvfb) on Travis CI is not enough. If you need OpenGL > 1.4 you also need to install libgl1-mesa-swx11, libgl1-mesa-swx11-dev.
In my travis.yml I setup OpenGL and start xvfb with:
- sudo apt-get install -qq --force-yes mesa-utils libgl1-mesa-swx11 libgl1-mesa-swx11-dev xvfb
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1400x900x24 -ac +extension GLX +render
the whole file is at:
https://github.com/mwohlf/pluto/blob/master/.travis.yml

Related

Ubuntu Libgdx problem - No X11 DISPLAY variable was set

My problem is with X11 variable - when Im trying to launch gdx-setup.jar i get output:
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set,
or no headful library support was found,
but this program performed an operation which requires it,
at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:166)
at java.desktop/java.awt.Window.<init>(Window.java:553)
at java.desktop/java.awt.Frame.<init>(Frame.java:428)
at java.desktop/java.awt.Frame.<init>(Frame.java:393)
at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
at com.badlogic.gdx.setup.GdxSetupUI.<init>(GdxSetupUI.java:101)
at com.badlogic.gdx.setup.GdxSetup.main(GdxSetup.java:620)
Im running ubuntu on my local laptop (NO SSH).
System details
I've tried commands:
sudo apt-get update --fix-missing
sudo apt-get update
sudo apt-get clean
sudo apt-get autoremove
sudo dpkg reconfigure -a
sudo apt install -f
It didnt help at all...
When Im running AWT from intellij I can see GUI normally and there's no exception.
Ive followed there instructions while installing libgdx:https://tutorialforlinux.com/2022/11/14/step-by-step-libgdx-ubuntu-22-04-installation-guide/2/
echo $DISPLAY
output:0
Installed: xorg-x11
Double clicking on jar causes with no response... Ive marked jar as executable
You can specify one of many installed java versions when running from intellij. When running from the command line its just a single one.I think your default java probably -actually truly is- headless. Follow this guide here to change your default command line java. I mean the error is specifically that if fails the headless check.
Follow here to switch the default cmd line java version.
https://computingforgeeks.com/how-to-set-default-java-version-on-ubuntu-debian/
Its not unusual to have headless because thats all server side stuff needs.

Headless exception while GUI testing (java swing) with gitlab-ci

I've a virtual server running a gitlab runner.
I've now added some GUI unit tests which run nicely on my pc but not on the virtual server.
It always exits with:
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
Any idea how to get this running with gitlab-ci?
Edit:
My virtual server is running centos 7
This im my current .gitlab-ci.yml
image: kaiwinter/docker-java8-maven
#maven:3-jdk-7
before_script:
- "Xvfb :99 &"
- "export DISPLAY=:99"
maven_build:
stage: build
script:
- "mvn clean package"
- "cat target/site/jacoco/index.html"
Now, the headlessexception is gone but basically all unit tests are failing due to awt exceptions like:
Could not initialize class java.awt.image.IndexColorModel
Edit2:
I've added the headless option as suggested:
image: kaiwinter/docker-java8-maven
#maven:3-jdk-7
before_script:
- "Xvfb :99 &"
- "export DISPLAY=:99"
maven_build:
stage: build
script:
- "mvn clean package -Djava.awt.headless=true"
- "cat target/site/jacoco/index.html"
Now I get the headless exceptions again...
You try using xvfb program like in this post http://elementalselenium.com/tips/38-headless.
I have used xvfb to run browser from text terminal. Your case is basically the same.
The problem is that your program expects to be run in window environment, but you are running it from text terminal.
Finally I've found a solution!
I've created a DOCKER image which is prepared for GUI testing (using xvfb, thanks vbuhlev):
https://github.com/thorstenwagner/docker-java8-maven
In the .gitlab-ci.yml I've added the following lines:
before_script:
- "Xvfb :99 &"
- "export DISPLAY=:99"
You need to enable Headless Mode:
maven_build:
stage: build
script:
- "mvn clean package -Djava.awt.headless=true"

Building a docker image doesnt stop because of minecraft server continuing to run

So I have been trying to learn docker for a few days now and set a first goal for me.
I want to run a spigot server inside a docker container and later on the road combine that with a BungeeCord network.
I have run into problem.
My dockerfile runs without problems but once it reaches the point where it starts the minecraft server, the images stops building.
I think this is due to the server continuing to run and not returning a code 0 to show docker to keep on running.
Am I wrong with my idea, and if not, how can I fix the problem?
Here is my Dockerfile:
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install openjdk-7-jre icedtea-7-plugin -y
RUN apt-get install wget -y
RUN mkdir mc_server && cd mc_server/
RUN wget http://getspigot.org/spigot18/spigot_server.jar
RUN java -Xms1536m -Xmx1536m -Dcom.mojang.eula.agree=true -jar spigot_server.jar nogui
This way the server starts up but docker never finishes building.
I hope I made my problem clear.
Greetings,
Joel
Replace that last RUN with CMD.
RUN / ADD / .. are used to build the static container environment where you want to run your application in. Everything that happens before running the actual application.
CMD and ENTRYPOINT define what's supposed to happen inside the container once you docker run it. This is where the startup script / call goes for the program.
The result of the Dockerfile is similar to a computer that's shut down but has everything installed on the harddrive including a script that autostarts the application. Turn it on and everything starts to run.
PS: https://hub.docker.com/search/?q=spigot&page=1&isAutomated=0&isOfficial=0&starCount=0&pullCount=0 there are several existing images

Extend docker container

I am new to Docker and I have a question regarding possibility to extend docker image after pulling it from docker repository. I need specifically docker image with ubuntu 14.04, java and R. I see there are images separately with the three of them. My question is where is the Dockerfile of newly pulled images so I can extend them?
docker pull command just pull a pre-built image. There isn't Dockerfile on your local machine. But you can find the original Dockerfile from Docker Hub. If you use itzg/ubuntu-openjdk-7 image you can access it's online repository.
https://registry.hub.docker.com/u/itzg/ubuntu-openjdk-7/
Dockerfile is available on Dockerfile tab(Only "Automated Build" repositories have Dockefile tab on Docker Hub).
FROM ubuntu:trusty
MAINTAINER itzg
ENV APT_GET_UPDATE 2014-07-19
RUN apt-get update
RUN apt-get install -y openjdk-7-jre-headless
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
Below is another Dockerfile from edwindj/docker-r.
FROM ubuntu:trusty
MAINTAINER Edwin de Jonge
RUN apt-get update
RUN apt-get install -y r-base
There is no method to automatically merge two or more Dockerfiles, but you can combine these two Dockerfile like below.
FROM ubuntu:trusty
RUN apt-get update
# Install java
RUN apt-get install -y openjdk-7-jre-headless
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
# Install R
RUN apt-get install -y r-base
And build it with docker build command.
$ docker build nacyot/ubuntu-java-r .
Try to java and R command on the container which based on nacyot/ubuntu-java-r image.
$ docker run -it nacyot/ubuntu-java-r cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"
$ docker run -it nacyot/ubuntu-java-r java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
$ docker run -it nacyot/ubuntu-java-r R --version
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.
It works fine.
There is no magic, but you can extend and bulid (almost) any images which have packages you need at first hand by referencing Dockerfiles on Docker Hub.
Dockerfiles are made to build image but you the inverse operation isn't possible.
If you want to extend an existing image you have 2 solution.
Run your image in a container, do the change and then commit to a new image. https://docs.docker.com/reference/commandline/cli/
Write a Dockerfile with the image you want as base. (1st line of Dockerfile should be FROM myimage) https://docs.docker.com/reference/builder/
The Repository is your namespace, essentially. So you need to pull the image, which you did. The file is located in the container, if you think about it.
List all the images--sudo docker images --Will show you the location of the file.
List item -- run a shell within a docker container. $ sudo docker run "your filename"
Now we are inside Docker container. We can list all the files using ls command.
Create your own directory if needed, but to answer your question you can stop at #3.
From here you could add the image to your own registry, and then pull it from there which honestly makes like easier.
For simplicity you honestly would only need to do numbers 1 and possibly 2 for
sure. When I tried it, #2 was also one I did but that lists the files
to add to your own registry when you create your own directory.
Check out this "tutorial" if needed: Docker Repository Tutorial
Also check out the documentation! Docker Documentation
Sure you can.
You can download a docker image, change it and generate (AKA commit) a new image with a new name (and tag).
To change the container you can either do it manually or with Dockerfile.
I not sure that I can give you all steps in a single answer, but if you follow this little guide I believe that you can get the idea in 10 minutes or less: https://docs.docker.com/userguide/dockerimages/#creating-our-own-images
Merging several images is not possible automatic, but often, the Dockerfiles are easy to follow to create your own version with both R and Java (if thats what you want).
Some upstream containers also uses the ONBUILD https://docs.docker.com/reference/builder/#onbuild entry in their dockerfiles to have something run only when their image is included in another via the FROM entry.
If you find one java container you are happy with, just create your own image with a dockerfile and FROM java-something on top. Then add R. All the docker run ... parameters that you use (entrypoints and cmd) will still work even if you include the container via FROM.
If you need to hack on the existing container thats also possible. Take a look at something I created to enable oauth on the gitlab container (before they officially did it) # https://github.com/xeor/dockerfiles/tree/master/gitlab. There I'm expanding the original image and adding my own set of config tweeks..

java.lang.NoClassDefFoundError: Could not initialize class java.awt.Component

When I run MATLAB install script in Ubuntu, I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class java.awt.Component
longer output is available here
I know that it's a Java problem and could potentially be fixed by changing the classpath or something like that but I don't exactly know how.
Any Ideas?
For me this error was fixed when I installed the JRE on my system:
apt-get install default-jre
on Ubuntu 12.04, instead of having MATLAB use its own.
I've been battling this problem for the whole evening as well but I stumbled onto a solution that works for me at least.
After trying to install using the silent installer I got a different error with a bit more information. It turned out that a library was missing (libXtst.so.6). I was able to install that on my Ubuntu system with:
apt-get install libxtst6
After that I tried running the GUI installer (over X forwarding) and it looks like it's going to work now.
For MATLAB R2012a Student Edition, in Ubuntu 14.04, I had to install these prerequisites first:
sudo apt-get install default-jre libxtst6:i386 libXext6:i386 libxi6:i386 libncurses5:i386 libxt6:i386 libxpm4:i386 libxmu6:i386 libxp6:i386
Next I installed/activated per MATLAB's instructions (sudo ./install). I answered "yes" when the installer asked to add a symbolic link in /usr/local/bin/
Finally, when launching MATLAB, I have to specify that it run in 32-bit mode:
matlab -glnx86
I assembled those steps from this answer: https://askubuntu.com/questions/363878/how-to-install-32-bit-matlab-in-ubuntu-64-bit
and the Ubuntu MATLAB guide:
https://help.ubuntu.com/community/MATLAB
Optional
I didn't want to type the -glnx86 option each time I launch MATLAB, so I replaced the matlab symbolic link in /usr/local/bin/ with a script that automatically specifies the -glnx86 option:
ls -l /usr/local/bin/matlab #note the destination of the symbolic link
sudo mv /usr/local/bin/matlab /usr/local/bin/matlab.bak
#ensure the first path below matches your symbolic link's destination
echo '/usr/local/MATLAB/R2012a_Student/bin/matlab -glnx86 "$#"' | sudo tee /usr/local/bin/matlab
sudo chmod +x /usr/local/bin/matlab
With that, I can type 'matlab' and it launches properly. (The "$#" in the script forwards all input arguments to matlab.) There's probably a more elegant way to accomplish this, but it worked.
I also encountered a "/lib/libc.so.6: not found" error on matlab startup, which I fixed by following this answer.
Installing gnome (sudo apt-get install gnome) fixed this problem for me. I'm sure this was total overkill, but the required libraries are now available.

Categories