Skip to content

Commit

Permalink
Merge pull request #93 from neomatrix369/provide-Docker-scripts
Browse files Browse the repository at this point in the history
Adding Dockerfile and bash scripts to build and run Docker containers
  • Loading branch information
olyagpl authored Nov 10, 2021
2 parents 3a38187 + 38afd46 commit 7038afe
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
shared
_dot_gradle_folder
_dot_m2_folder
.git
.gitmodules
.idea
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,46 @@ typings/
# dotenv environment variables file
.env

# macOS related
.DS_Store

# oci, terraform related
**/credentials.rc
terraform.tfstate
terraform.tfstate.backup

# End of https://www.gitignore.io/api/java,node,maven,eclipse,intellij+all
jmeter.log
apache-jmeter*
*.jtl
micronaut-webapp/docker-compose.yml
/hello-graal/Hello
/hello-graal/Hello.build_artifacts.txt
native-list-dir/listdir
native-list-dir/listdir.build_artifacts.txt
java-kotlin-aot/helloworld
java-kotlin-aot/helloworld.build_artifacts.txt
shared
micronaut-nativeimage/hello/
micronaut-webapp/loadTests/results-*
mn-python/env/
functionGraphDemo/Rplot001.svg
native-netty-plot/netty-plot.build_artifacts.txt
native-netty-plot/src/main/resources/META-INF/native-image/*
polyglot-javascript-java-r/Rplot001.svg
polyglot-javascript-java-r/package-lock.json
spring-r/Rplot001.svg
scala-examples/scalac-native/project/
scala-examples/scalac-native/scalac.build_artifacts.txt
graalpython-notebook-example/venv/
micronaut-python/venv/
nohup.out
fastR-examples/*.*
*.whl
.vscode
*.log?
venv/
espresso-jshell/espresso-jshell
espresso-jshell/espresso-jshell.build_artifacts.txt
native-list-dir/extlistdir
native-list-dir/extlistdir.build_artifacts.txt
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ These programs are illustrating diverse capabilities of [GraalVM](http://graalvm

Clone this repository. Every top level folder here contains demo sources and the instructions on how to run that particular code are in its README.md.

In case you wish to run some of the examples (console-based, non-GUI) inside the confinement of a docker container, then please follow then after cloning the repo but before running any of the demos, please do the below:

Build the **GraalVM** demo docker image of choice:
```
$ cd docker-images
$ ./buildDockerImage.sh "java11-21.2.0"
```

Run the GraalVM demo docker container built above:
```
$ ./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"
```

_(One-off: download and install any **VNCViewer**)_
_(Wait for the container to be ready, then run VNCViewer and then log onto http://127.0.0.1:5900 (type it in, in case copy-paste does not work) 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: Valid tags to specify as parameters, can be found [here](https://github.com/graalvm/container/pkgs/container/graalvm-ce). A number of free or commercial [VNCViewers](https://duckduckgo.com/?q=vnc+viewer+download&ia=web) can be found online and are fairly easy to use.


Once the docker container is running, go to the folder of the respective demos, and follow the instructions.

## Tested Compatibility

The demos are normal applications and benchmarks written in Java, Kotlin, JavaScript, etc., so they are compatible with any virtual machine capable of running Java, JavaScript and so on.
Expand Down
139 changes: 139 additions & 0 deletions docker-images/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
ARG DOCKER_USER_NAME
ARG SOURCE_DOCKER_HUB
ARG FULL_GRAALVM_VERSION

FROM ${SOURCE_DOCKER_HUB}:${FULL_GRAALVM_VERSION} as graalvm-jdk-image
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 --from=workload-generator /tmp/wrk/wrk /usr/local/bin
RUN echo "Testing 'wrk':"; wrk || true

# Install other smaller utilities needed during building of image in the slim image
RUN echo; echo "--- Installing wget, curl, vim, unzip in the slim image"; echo
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
wget curl vim unzip gnupg2 \
make gcc g++ libc++-dev \
openssl libssl-dev libcrypto++-dev libz.a \
locales ca-certificates
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/*

# https://www.rosehosting.com/blog/configure-system-locale-on-debian-9/
# https://people.debian.org/~schultmc/locales.html <-- simple steps
RUN echo "--- Installing and setting locales"
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
ENV LANG="en_US.UTF-8"
ENV LANGUAGE="en_US"
RUN locale-gen
RUN echo; echo "LANG=${LANG}"; echo "LANGUAGE=${LANGUAGE}";
RUN echo; echo "List of installed locales:"; locale -a; echo;

# Install gcc and make
RUN echo "gcc version: "; gcc --version
RUN echo "make version: "; make --version

ARG GRAALVM_HOME

# Install and setup GraalVM
COPY --from=graalvm-jdk-image /opt/graalvm-* ${GRAALVM_HOME}

ENV JAVA_HOME=${GRAALVM_HOME}
ENV PATH=${JAVA_HOME}/bin:${PATH}
RUN echo; echo "JAVA_HOME=${JAVA_HOME}"; echo
RUN echo; echo " --- GraalVM version (runtime)"; java -version; echo

# Install some of the needed components using 'gu install'
RUN echo; echo " --- Download & install 'espresso' using gu"; gu install espresso; echo
RUN echo; echo " --- Download & install 'nodejs' using gu"; gu install nodejs; echo
RUN echo; echo " --- Download & install 'python' using gu"; gu install python; echo
RUN echo; echo " --- Download & install 'R' using gu"; gu install R; echo
RUN echo; echo " --- Download & install 'Ruby' using gu"; gu install ruby; echo
RUN echo; echo " --- Download & install 'native-image' using gu"; gu install native-image; echo

# Rebuild Ruby to make the Ruby openssl C extensions to work with the local system libssl (see https://github.com/oracle/truffleruby/blob/master/doc/user/installing-graalvm.md#installing-ruby-and-other-languages)
RUN echo "Rebuilding Ruby to make the Ruby openssl C extensions to work with the local system libssl"

RUN export RUBY_POST_HOOK_SCRIPT="$(find ${GRAALVM_HOME} -name *post_install_hook.sh*)"; \
chmod +x ${RUBY_POST_HOOK_SCRIPT}; \
bash ${RUBY_POST_HOOK_SCRIPT};
# At the moment this is a simple litmus test to verify that the above step has actually worked!
RUN echo "Installing ruby gems to verify if the above installation and rebuilding processes are working..."
RUN gem install rspec galaaz

RUN echo "gcc version: "; gcc --version
RUN echo "make version: "; make --version

# https://github.com/oracle/truffleruby/blob/master/doc/user/ruby-managers.md#chruby
RUN if [ -e "${GRAALVM_HOME}/jre" ]; then ruby_home=$(${GRAALVM_HOME}/jre/languages/ruby/bin/ruby -e 'print RbConfig::CONFIG["prefix"]'); else ruby_home=$(${GRAALVM_HOME}/languages/ruby/bin/ruby -e 'print RbConfig::CONFIG["prefix"]'); fi


# Install Java 8
COPY --from=java:8u111-jdk /usr/lib/jvm /usr/lib/jvm

ENV JDK8_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64"
RUN echo; echo "JDK8_HOME=${JDK8_HOME}"; echo
RUN echo; echo "PATH=${PATH}"; echo
RUN echo " --- Java 8 version:"; ${JDK8_HOME}/bin/java -version; echo

# Install mvn
ARG MAVEN_VERSION
RUN cd /tmp
RUN wget -q -nv https://raw.githubusercontent.com/Drambluker/install-maven/main/install-maven.sh
RUN wget -q -nv "https://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
RUN chmod +x ./install-maven.sh
RUN ./install-maven.sh -f apache-maven-${MAVEN_VERSION}-bin.tar.gz
ENV M2_HOME="/usr/local/apache-maven/apache-maven-${MAVEN_VERSION}/"
ENV PATH=${M2_HOME}/bin:${PATH}
RUN echo " --- Maven version:"; mvn --version; echo

# Install gradle
ARG GRADLE_VERSION
RUN cd /tmp/; wget -q -nv https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip
RUN cd /tmp/; unzip gradle-${GRADLE_VERSION}-bin.zip && mv gradle-${GRADLE_VERSION} /
ENV GRADLE_HOME="/gradle-${GRADLE_VERSION}"
ENV PATH=${GRADLE_HOME}/bin:${PATH}
RUN echo " --- Gradle version:"; gradle --version; echo

# Install jmeter
RUN cd /tmp/; wget -q -nv "https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.4.1.zip"
RUN unzip /tmp/apache-jmeter-5.4.1.zip
ENV JMETER_HOME="${WORKDIR}/apache-jmeter-5.4.1"
ENV PATH=${JMETER_HOME}/bin:${PATH}
RUN echo " --- Jmeter version:"; jmeter --version; echo

# Install scala and sbt
ARG SBT_VERSION
RUN echo; echo "--- Installing scala and sbt in the slim image"; echo
# See https://www.scala-sbt.org/download.html
RUN cd /tmp/; wget -q -nv https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.zip
RUN cd /tmp/; unzip sbt-${SBT_VERSION}.zip; mv sbt /usr/share; ln -s /usr/share/sbt/bin/sbt /usr/bin/sbt
RUN echo "sbt version:"; sbt --version | grep "sbt script version"; echo

ARG SCALA_VERSION
# See https://www.scala-lang.org/download/
RUN cd /tmp/; wget -q -nv https://github.com/lampepfl/dotty/releases/download/${SCALA_VERSION}/scala3-${SCALA_VERSION}.zip
RUN cd /tmp/; unzip scala3-${SCALA_VERSION}.zip; mv scala3-${SCALA_VERSION} /usr/share/scala;
RUN ln -s /usr/share/scala /usr/share/scala-${SCALA_VERSION}; ln -s /usr/share/scala/bin/scala /usr/bin/scala
RUN echo "scala version:"; scala -version; echo

# this location maps to the specific vesion of Scala for e.g. scala-2.12 or 3.0.2
ENV SCALA_HOME="/usr/share/scala"
RUN echo; echo "SCALA_HOME=${SCALA_HOME}"; echo

COPY --from=micronaut-starter-image /root/.micronaut/micronaut-cli /root/.micronaut/micronaut-cli
ENV MICRONAUT_HOME="/root/.micronaut/micronaut-cli"
ENV PATH=${MICRONAUT_HOME}/bin:${PATH}
RUN echo; echo " --- Micronaut version"; mn --version; echo

# Some demo apps require this env variable set
ENV GRAALVM_HOME=${GRAALVM_HOME}
RUN echo; echo "GRAALVM_HOME=${GRAALVM_HOME}"; echo

LABEL maintainer="GraalVM team"
LABEL example_git_repo="https://github.com/graalvm/graalvm-demos"
LABEL graalvm_version=${FULL_GRAALVM_VERSION}
LABEL version=${FULL_GRAALVM_VERSION}
39 changes: 39 additions & 0 deletions docker-images/Dockerfile-gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://www.cloudsavvyit.com/10520/how-to-run-gui-applications-in-a-docker-container/ - latter part of the blog

ARG DOCKER_USER_NAME
ARG FULL_GRAALVM_VERSION
FROM ${DOCKER_USER_NAME}/graalvm-demos:${FULL_GRAALVM_VERSION}

# Install xterm in order to be able to access it when running GUI apps
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
x11vnc xvfb xterm \
xfonts-75dpi xfonts-100dpi xfonts-base \
libfontconfig1 libxrender1 libxtst6 \
libgomp1 zlib1g liblzma5 libc6 \
libbz2-1.0 bzip2 patch \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/*

RUN echo "gcc version: "; gcc --version
RUN echo "make version: "; make --version

# https://askubuntu.com/questions/161652/how-to-change-the-default-font-size-of-xterm#161704
RUN echo "exec xterm -maximized -fa 'Monospace' -fs 18" > \
~/.xinitrc && chmod +x ~/.xinitrc
RUN echo ""; echo "Contents of ~/.xinitrc"; echo ""; cat ~/.xinitrc; echo "";
RUN echo "xterm*font: *-Monospace-*-*-*-18-*" > ~/.Xresources
RUN echo ""; echo "Contents of ~/.Xresources"; echo ""; cat ~/.Xresources; echo "";

# Adding environment variable to support older demos that rely on the GRAALVM_DIR env variable
ENV GRAALVM_DIR="${JAVA_HOME}"
RUN echo "GRAALVM_DIR=${GRAALVM_DIR}"
RUN echo "GRAALVM_HOME=${GRAALVM_HOME}"

LABEL maintainer="GraalVM team"
LABEL example_git_repo="https://github.com/graalvm/graalvm-demos"
LABEL graalvm_version=${FULL_GRAALVM_VERSION}
LABEL version=${FULL_GRAALVM_VERSION}

# manual: https://linux.die.net/man/1/x11vnc
CMD ["x11vnc", "-create", "-forever", "-geometry", "1024x768"]
35 changes: 35 additions & 0 deletions docker-images/Dockerfile-mn
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARG SOURCE_DOCKER_HUB
ARG FULL_GRAALVM_VERSION
FROM ${SOURCE_DOCKER_HUB}:${FULL_GRAALVM_VERSION} as graalvm-jdk-image

FROM buildpack-deps:stretch-scm

# Install smaller utilities needed during building of image in the slim image
RUN echo; echo "--- Installing wget, curl, vim, unzip in the slim image"; echo
RUN apt-get update && \
apt-get install -yq --no-install-recommends unzip git

ARG GRAALVM_HOME

# Install and setup GraalVM
COPY --from=graalvm-jdk-image /opt/graalvm-* ${GRAALVM_HOME}

ENV JAVA_HOME=${GRAALVM_HOME}
ENV PATH=${GRAALVM_HOME}/bin:${PATH}
RUN echo; echo "JAVA_HOME=${JAVA_HOME}"; echo
RUN echo; echo " --- GraalVM version (runtime)"; java -version; echo

# Build and Install micronaut
RUN cd /tmp; git clone https://github.com/micronaut-projects/micronaut-starter.git
RUN cd /tmp/micronaut-starter; ./gradlew micronaut-cli:assembleDist
RUN mkdir -p ~/.micronaut; unzip /tmp/micronaut-starter/starter-cli/build/distributions/micronaut-cli-*.zip -d ~/.micronaut
ENV MICRONAUT_HOME="/root/.micronaut/micronaut-cli"
RUN OLD_NAME=$(ls ~/.micronaut); mv ~/.micronaut/${OLD_NAME} ${MICRONAUT_HOME}
RUN echo "MICRONAUT_HOME=${MICRONAUT_HOME}"; \
ls -lash ${MICRONAUT_HOME}/bin; \
echo; echo "micronaut version:"; ${MICRONAUT_HOME}/bin/mn --version; echo

LABEL maintainer="GraalVM team"
LABEL git_repo="https://github.com/micronaut-projects/micronaut-starter.git"
LABEL graalvm_version=${FULL_GRAALVM_VERSION}
LABEL version=${FULL_GRAALVM_VERSION}
15 changes: 15 additions & 0 deletions docker-images/Dockerfile-wrk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM buildpack-deps:stretch-scm

# Build and Install wrk in the slim image, see https://github-wiki-see.page/m/giltene/wrk2/wiki/Installing-wrk2-on-Linux
RUN echo; echo "--- Installing wrk: workload generator (multiple threads)"; echo
RUN apt-get update
RUN apt-get install -yq --no-install-recommends build-essential libssl-dev git unzip

RUN cd /tmp; git clone https://github.com/wg/wrk.git
RUN cd /tmp/wrk; make
RUN chmod +x /tmp/wrk/wrk; cp /tmp/wrk/wrk /usr/local/bin
RUN echo "Testing 'wrk':"; wrk || true

LABEL maintainer="GraalVM team"
LABEL git_repo="https://github.com/wg/wrk.git"
LABEL version=0.1
Loading

0 comments on commit 7038afe

Please sign in to comment.