Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Dockerfile and bash scripts to build and run Docker containers #93

Merged
merged 88 commits into from
Nov 10, 2021

Conversation

neomatrix369
Copy link
Contributor

@neomatrix369 neomatrix369 commented Sep 29, 2021

@olyagpl continuing from PR #31, as per our last conversation: #31 (comment)

Handy Docker scripts to facilitate running the graalvm demos in a clean and isolated environment. The below defaults to GraalVm 21.2.0 Java 11

Build a docker image with GraalVM runtime in it:

   $   cd docker-images
   $   ./buildDockerImage.sh

Run a docker container with GraalVM runtime in it (from the root directory of the project):

   $   ./runDockerImage.sh

Run a docker container with GraalVM runtime in it (from the root directory of the project) for GUI-based apps:

   $   DEMO_TYPE="gui" ./runDockerImage.sh

To build and run examples using another version of GraalVM runtime (i.e. GraalVM 21.2.0 for Java 11), the usage is as follows:

Build a docker image with GraalVM runtime in it:

   $   cd docker-images
   $   ./buildDockerImage.sh "java11-21.2.0"

Run a docker container with GraalVM runtime in it (from the root directory of the project):

   $   ./runDockerImage.sh "java11-21.2.0"

Run a docker container with GraalVM runtime in it (from the root directory of the project) for GUI-based apps:

   $   DEMO_TYPE="gui" ./runDockerImage.sh "java11-21.2.0"

   (Download and run a VNCViewer and then log onto http://127.0.0.1:5900 
    via the VNCViewer to access the GUI interface. You will get an `xterm` screen,
    where you can type in your commands just like the docker console or any other CLI prompt.)

Note: See https://github.com/graalvm/container/pkgs/container/graalvm-ce, for a list of complete tag names to be used at CLI parameters to the above shell-scripts. A number of free or commercial VNC Viewers can be found online and are fairly easy to use.

Thanks to @findepi for providing the GraalVM community with the complete set of lightweight GraalVM docker images. We have now migrated the scripts to use GraalVM's own home built docker images, your images have been helpful so far to test out many of the demos, thank you for that, please take this migration as a positive gesture.

In addition to the version of GraalVM binaries, the graalvm-demo container contains the following at runtime:

  • GraalVM components: espresso, python, nodejs, native-image, llvm, and the other default components that come with the GraalVM binary
  • Java 8 (OpenJDK version)
  • Maven 3.8.1
  • Gradle 7.2
  • Micronaut Starter binary
  • wrk (workload generator) binary
  • jmeter
  • Scala and sbt
  • dependencies in place to be able to run GUI based apps from inside a docker container

…demos with the new one, using findepi's provided docker images

Tested against one example, continue to test against the remaining non-GUI based examples.
@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Sep 29, 2021

Testing build docker container against the below examples:

Below demos run partially but fails to complete other checks, need further investigation:

Below demos are GUI based and might be non-trivial to run inside a docker container atm:

In case, the test fails or cannot be tested, could be due to one or all of these reasons:

  • demo is a GUI based example or may not be trivial to dockerise the demo
  • demo may already come with its own docker or another container-based solution

@olyagpl
Copy link
Member

olyagpl commented Sep 29, 2021

@neomatrix369 , thanks! I'll review asap.

…the docker image name (under version), makes it easier to identify graalvm-demo images
@neomatrix369
Copy link
Contributor Author

@neomatrix369 , thanks! I'll review asap.

Thanks, try to run this on your own machine and see how it works, I will continue to test other examples using the docker container, please don't merge it yet (even if you are happy with the current PR).

@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Sep 29, 2021

@olyagpl we can now build and run any version of GraalVM (community version, provided they are available on findepi/graalvm's docker hub) using the current script - I'm now testing the rest of the demo apps to see if they work well, otherwise I will raise separate issues for the respective apps (and/or raise them on the oracle/graal related repos)

…nodejs component using gu, also listen on port 8088 as per requirements of one of the examples.
- testing simple example hello_graal
- install python using gu
- install maven as part of the graalvm-demos docker image
- set the appropriate paths and add them to the PATH env variable
…VM_HOME - fixes maven build issues.

Add a couple of files to the ignore list.
Add 'wrk' installation step(s) to the Dockerfile.
…e-images, and built the main docker image based on these two dependencies.
…g the scala cache folders to the shared folder
… installed. Also changed the base image, to fix debian source.list related issues.

Replaced old/broken links with new ones.
…s:stretch-scm

Minor updates to other install commands, wget needed the flag to disable certificate checks
…ecessary locale related info for installing gems
…images in both local and remote repositories when attempting to run a container
…e installation and rebuilding of Ruby component and ssl library
…the installation of python packages using graalpython
docker-images/Dockerfile Outdated Show resolved Hide resolved
…tyasai/git-repos/OpenJDK/graal-stuff/graalvm-demos/docker-images for the venv path
…t complain about missing/invalid certificates, also making download more secure.

graalpython: temporarily removing the step to pre-install/pre-bake python packages into the image so container runtime gestation is reduced, atm the graalpython -m command starts the reinstall step again
…o install dependencies before running the demo. This step also helps understand if there is a failure what or why things failed.
…ing pulled, also fix the logic to check for absence of image in the local and remote repo
…mo, dependency required for the R aspect of the build process
FROM ${DOCKER_USER_NAME}/micronaut-starter:${FULL_GRAALVM_VERSION} as micronaut-starter-image
FROM ${DOCKER_USER_NAME}/workload-generator as workload-generator

FROM debian:buster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use debian here instead of e.g. the official GraalVM Docker image from https://github.com/graalvm/container/pkgs/container/graalvm-ce ?
That might make things easier, because we test on OracleLinux in CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, no we can use GraalVM as the base image, thanks for confirming this saves building time.

The original code evolved such that I swayed away from this approach due to some issues but I can revert to your suggestion.

Copy link
Contributor Author

@neomatrix369 neomatrix369 Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you install packages in the Graalvm docker image, apt or aptitude is not available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@neomatrix369 neomatrix369 Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

microdfn isn't able to find g++, libc++-dev, libssl-dev, the latter fixed the TruffleRuby and FastR issues we had with galaaz demos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image I'm building is using an official GraalVM images if you see the buildDockerImage.sh and Dockerfile and Dockerfile-mn in the docker-images/ sub-folder.

In this Dockerfile, it's reusing some files from the offical Docker images, but transplanting on debian:buster.
That's absolutely not guaranteed to work, it feels pretty hacky honestly. For instance the files in the official images might already be tweaked to run on OracleLinux, for instance https://github.com/graalvm/container/blob/326e236ee937de37769e0709505dafdb7a6a9f78/community/Dockerfile.java11#L44-L53.

I'm checking with @ezzarghili, I think there is a way to install rpm's for each component/language, and that should automatically install all required system dependencies. They are currently working on having 21.3 Docker images with those rpm packages.
Maybe we can even have a Docker image with all components pre-installed, that sounds ideal for this use-case, isn't it?

IMHO trying to minimize dependencies below what is marked as requirement for each component is not a good thing and will just into problems, e.g., I think nobody is happy to help you debug if you on purpose skipped some documented dependency.

I don't understand the concern about image size here. It's a repo of demos with all languages, of course the image will be big, and I don't think it's much of an issue.


I understand it's easier for you for now to use debian-based images and you don't want to change everything right now.
But if we get something like Docker images with rpms or already all components we should use that, instead of hardcoding and manually finding system dependencies in yet another place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we get something like Docker images with rpms or already all components we should use that, instead of hardcoding and manually finding system dependencies in yet another place.

I agree with using them - as this would be ideal and makes it consistent. If a standard image/config for Docker or anything of that sort is available, I would just like to use it as it would work out-of-the-box as you mentioned earlier.

I don't fully agree about your comment about "hacky" in this context, I will agree it's less optimum or less efficient, but it's done in the absence of the standard image or the know-how about it.

I will say the same about the docs, they are not necessary if you have config files and single-line commands to create images using those config files (I see you have these in different places in some form or shape). Incorporating existing config or images and building on top of them is more appropriate. That idea is still in the files/scripts in the script, maybe it's not visible, reusing components is definitely the way to go.

What has happened here is actually a bit of reinvention of the wheel, which is debatable if it could have been avoided but now we learning from what's available, happy to adapt them. This will also reduce the calls to various teams for help in case something does not work - I do not wish to do this either, it can hold up the process on this end as well.

After all of this, there is still chances of something not working but then those are much less. Also, peer review helps iron out these glitches, and it's a one-off because when this works it will always work unless the upstream regresses or something specific has been changed downstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can even have a Docker image with all components pre-installed, that sounds ideal for this use-case, isn't it?

This is something I would have been doing in my second refactor round for these scripts, but if this is already in the planning then I can wait and adapt those images and build on top of them - thanks for letting me know I will keep an eye for it

Copy link
Contributor Author

@neomatrix369 neomatrix369 Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand it's easier for you for now to use debian-based images and you don't want to change everything right now.

Only for now, but it's on my mental list to change it. But I'm always happy to change the docker and shell scripts -- if we can reduce all the lines written to a few lines then that's a better solution and reusing existing images could be a way towards that.

Copy link
Contributor Author

@neomatrix369 neomatrix369 Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a repo of demos with all languages, of course the image will be big, and I don't think it's much of an issue.

Thinking of this again, you are right, I'll take that back -- image size should not be an issue, especially to avoid inconsistency and be able to reproduce issues on the same image type. A whole chain of things can happen if images differ in signature, and be hard to trackback or investigate, as the number of moving parts are increasing.

…ge, and as a result removing the -no-check-certificate flag from wget and curl commands, as this is not necessary and also good to not use them anymore
…ying the layer from a ready-to-use graalvm docker image
@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Oct 20, 2021

Thanks for your feedback @eregon I really appreciate it

Especially you are nitpicking and finding cruft, which I would also like to remove from the scripts and config files -- a second pair of eyes surely helps 🙏 🎉

@olyagpl
Copy link
Member

olyagpl commented Nov 10, 2021

We will gradually improve and make things less and less manual as we go along. I'm merging this PR.
Thanks Mani and everyone involved!

@olyagpl olyagpl merged commit 7038afe into graalvm:master Nov 10, 2021
@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Nov 11, 2021

Thanks @olpaw for the https://github.com/graalvm/graalvm-demos/tree/master/native-hello-module demo example, I have tested it in our Docker container for GraalVM 21.3.0, and it works fine.

You can also try it on this demo or other ones by doing this:

$ git clone https://github.com/graalvm/graalvm-demos/
$ ./runDockerImage.sh "java11-21.3.0"

### At the prompt inside the container do:
root@.....:/graalvm-demos# cd native-hello-module

### perform all the steps for the demo
root@.....:/graalvm-demos#

@neomatrix369
Copy link
Contributor Author

I'm checking with @ezzarghili, I think there is a way to install rpm's for each component/language, and that should automatically install all required system dependencies. They are currently working on having 21.3 Docker images with those rpm packages.
Maybe we can even have a Docker image with all components pre-installed, that sounds ideal for this use-case, isn't it?

@eregon As I'm getting ready to continue from this point on again, I wanted to check if the above thing you mentioned sometime back is available with the latest GraalVM 21.3 docker images? I have just built a 21.3 docker image for GraalVM demos. If not, it's fine, I can build on top of the GraalVM docker image (as you were suggesting earlier) and maybe it needs fewer dependencies - which could be to our advantage.

@neomatrix369
Copy link
Contributor Author

Hey @ezzarghili would you be able to help me out with this query #93 (comment) as you manage all things docker for the GraalVM team

@eregon
Copy link
Member

eregon commented Nov 16, 2021

Yes, @ezzarghili should be the best contact about this and in general if you have any issue related to these Docker images, https://github.com/graalvm/container is the place to report them.
That repository still needs a README, cc @abdelhaira

@ezzarghili
Copy link
Member

Public yum rpms already exist on https://yum.oracle.com/repo/OracleLinux/OL7/graalvm/community/x86_64/index.html and https://yum.oracle.com/repo/OracleLinux/OL8/graalvm/community/x86_64/index.html
If you use one of the compact (rpm based images) available you should be able to use microdnf (ol8) or yum (ol7) to install the packages you, the repos should be already configured for you.

https://github.com/graalvm/container/pkgs/container/jdk is the minimal image to build on, but there is also the native-image and nodejs ones.

Please keep in mind that for experimental languages (graalpython, truffleruby...) the rpms are only available for Year.N.0 releases (i.e 21.3.0 but not 21.3.1+).

@eregon
Copy link
Member

eregon commented Nov 17, 2021

I've tried the above and to give an idea how it works:

$ docker run --rm -it ghcr.io/graalvm/jdk:java17-21.3.0 bash
bash-4.4# microdnf install graalvm21-ce-11-ruby-devel-21.3.0
Downloading metadata...
Downloading metadata...
Downloading metadata...
Package                                                                                           Repository                            Size
Installing:                                                                                                                                 
 graalvm21-ce-11-jdk-21.3.0-1.el8.x86_64                                                          ol8_graalvm_community             205.7 MB
 graalvm21-ce-11-llvm-21.3.0-1.el8.x86_64                                                         ol8_graalvm_community              41.9 MB
 graalvm21-ce-11-llvm-toolchain-21.3.0-1.el8.x86_64                                               ol8_graalvm_community              32.7 MB
 graalvm21-ce-11-ruby-21.3.0-1.el8.x86_64                                                         ol8_graalvm_community              55.1 MB
 graalvm21-ce-11-ruby-devel-21.3.0-1.el8.x86_64                                                   ol8_graalvm_community               4.7 kB
 keyutils-libs-devel-1.5.10-6.el8.x86_64                                                          ol8_baseos_latest                  48.8 kB
 krb5-devel-1.18.2-8.3.el8_4.x86_64                                                               ol8_baseos_latest                 572.8 kB
 libcom_err-devel-1.45.6-1.el8.x86_64                                                             ol8_baseos_latest                  39.1 kB
 libkadm5-1.18.2-8.3.el8_4.x86_64                                                                 ol8_baseos_latest                 190.8 kB
 libpkgconf-1.4.2-1.el8.x86_64                                                                    ol8_baseos_latest                  35.6 kB
 libselinux-devel-2.9-5.el8.x86_64                                                                ol8_baseos_latest                 204.6 kB
 libsepol-devel-2.9-2.el8.x86_64                                                                  ol8_baseos_latest                  87.7 kB
 libverto-devel-0.3.0-5.el8.x86_64                                                                ol8_baseos_latest                  18.2 kB
 openssl-devel-1:1.1.1g-15.el8_3.x86_64                                                           ol8_baseos_latest                   2.4 MB
 pcre2-devel-10.32-2.el8.x86_64                                                                   ol8_baseos_latest                 619.3 kB
 pcre2-utf16-10.32-2.el8.x86_64                                                                   ol8_baseos_latest                 234.2 kB
 pcre2-utf32-10.32-2.el8.x86_64                                                                   ol8_baseos_latest                 225.6 kB
 pkgconf-1.4.2-1.el8.x86_64                                                                       ol8_baseos_latest                  38.9 kB
 pkgconf-m4-1.4.2-1.el8.noarch                                                                    ol8_baseos_latest                  17.4 kB
 pkgconf-pkg-config-1.4.2-1.el8.x86_64                                                            ol8_baseos_latest                  15.5 kB
 zlib-devel-1.2.11-17.el8.x86_64                                                                  ol8_baseos_latest                  58.9 kB
...
(so system dependencies are installed automatically)

Needed because by default language launchers are not in PATH to avoid potential conflicts with system executables:
bash-4.4# export PATH=/usr/lib64/graalvm/graalvm21-ce-java17/bin:$PATH

bash-4.4# ruby -v
truffleruby 21.3.0, like ruby 2.7.4, GraalVM CE Native [x86_64-linux]

You need to be careful to match the graalvm and java versions, otherwise you'll end up installing another graalvm in that image, i.e., installing another graalvm*11-jdk-* package.

@eregon
Copy link
Member

eregon commented Nov 17, 2021

Currently it's necessary to manually run the post-install hook for ruby, but it shouldn't (filed internally as GR-35132).
So

bash-4.4# /usr/lib64/graalvm/graalvm21-ce-java17/languages/ruby/lib/truffle/post_install_hook.sh

after that microdnf install

And currently you also need to set the locale manually: ENV LANG=en_US.UTF-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants