Wednesday, February 21, 2018

IBM OpenSources Itself: Build the OpenJ9 JVM into Docker Image from Sources Using Ansible

IBM has opened their products to the open source community. Today I wish to tell you about two of that products:

  • OpenLiberty - open sourced Java EE application server WebSphere Liberty Profile

  • OpenJ9 - open sourced JVM based on OpenJDK and another open source project OMR that contains cross platform components for building reliable, high performance language runtimes (so, not only the Java runtime but runtimes for Python, Ruby and other languages).

OpenJ9 and OMR are opened under the umbrella of Eclipse Foundation.

Let's try to build the JVM. Thanks to the developers, there is a full instruction how to build the project using Docker and the Make utility. The instruction for JDK 8 can be found here: while the instruction for JDK 9 is here: Both instructions contain a part for a build process based on Docker. Really, this is very usable just build a Docker-container which contains all required dependencies: C and C++ libraries, python libraries, a compiler collection, and tools don't have to be installed on the host environment, we can just to isolate them within a container.

Yet to create a container is not enough to get the JVM. Also, a developer has to check out the sources of OpenJDK, OpenJ9 and OMR as well as prepare and run the build. If a Docker-image with a fresh OpenJ9 is required, it also has to be built. I've automized these tasks using RedHat Ansible.

The building block in Ansible is Role. Roles can be reused and shared on the Ansible Galaxy website. The playbook (a "script" in the Ansible world is called "playbook") contains the following roles and each role fulfils the following actions:
  • openj9-build-environment - creates a Docker-container with the build environment
  • openj9-from-sources - checkouts the sources of IBMRuntimes, OMR and OpenJ9, adds required groups and users to the build environment, does make all and archives the JDK
  • openj9-image - builds a target Docker-image which contains the fresh build of OpenJ9
  • openj9-cleanup-build-environment - stops and removes the build environment Docker-container, removes the build environment Docker-image, drops all created folders on the host system.
Currently, the ansible playbook produces only a Docker-image based on Ubuntu 16.4. The Docker-image contains the Eclipse OpenJ9 virtual machine. The owner of the virtual machine is the 'ibmuser' user (configurable) who is a member of the 'ibm' group (configurable). A container created over the image runs as the 'ibmuser' non-privileged user.

If you wish to get your own build of the OpenJ9, the playbook is available as a pull request (has not been merged yet) on GitHub. The same playbook is used to build OpenJ9 JDK9 as well as JDK8, all required parameters could be specified in the buildenv/ansible/inventories/local/hosts file.

To run the build do:
$ ansible-playbook -i inventories/local/hosts openj9-docker-image.yml
Just for demonstration, OpenLiberty says "Hello!" running on a fresh OpenJ9 JDK9 build within a Docker-container:

Would you like to give a 'Like'? Please follow me on Twitter!