Giter VIP home page Giter VIP logo

scala-graalvm-docker's Introduction

scala-graalvm-docker

This project provides a collection of docker images to facilitate the usage of GraalVM by Scala projects, guaranteeing a consistent and reproducible environment where native images can be produced in an automated fashion.

"Make development more productive and run programs faster anywhere." - GraalVM

Goal

Accelerate GraalVM's adoption during develop, test, and release phases of Scala projects.

Available

Scala: 2.11.8 and 2.12.6

SBT: From 0.13.15 until 1.1.5

GraalVM: 1.0.0-RC1

List of tags: cloudscala/scala-graalvm:{tags}

How to use

Automating the development, testing, and release process will vary based on the needs of a project, but the following example could fit all cases. This repo contains a docker-compose-example.yml as an example of how to use an image.

version: '3'

services:
  app:
    image: cloudscala/scala-graalvm:scala-2.12.6-sbt-1.1.5-graalvm-1.0.0-rc1
    command: ./generate-native-image-example.sh
    volumes:
      - .:/app
      - ~/.ivy2:/root/.ivy2
      - ~/.sbt:/root/.sbt
      - ~/.coursier:/root/.coursier 

By opening the console and running docker-compose run app; the docker-compose file must be in the project's root level, docker-compose will pull the version scala-2.12.6-sbt-1.1.5-graalvm-1.0.0-rc1 and we execute the ./generate-native-image-example.sh when the container boots up. Also, notice that the we share the current directory and known artifact folders with the container to avoid having the container's SBT loading all artificats everytime.

The generate-native-image-example.sh:

# Set distribution folder from first argument, otherwise default to `native`
NATIVE_IMAGE_FOLDER=native-image
if [ $# -gt 0 ]; then
	NATIVE_IMAGE_FOLDER=$1
fi

# Create native-image folder if it doesn't exist, and clear the contents
mkdir -p ${NATIVE_IMAGE_FOLDER}
rm -rf ${NATIVE_IMAGE_FOLDER}/*

# Create an .jar using sbt-assembly
sbt -mem 2048 clean assembly

# Move .jar to native-image folder
find "." -name '*.jar' | while read APP_JAR; do
	mv $APP_JAR $NATIVE_IMAGE_FOLDER
done

# Go to native-image folder and generate the executables for each .jar
cd $NATIVE_IMAGE_FOLDER

find "." -name '*.jar' | while read APP_JAR; do
	echo "Processing .jar '$APP_JAR' on $NATIVE_IMAGE_FOLDER folder"
	native-image -J-Xmx2G -J-Xms2G --no-server -H:+ReportUnsupportedElementsAtRuntime -jar ${APP_JAR}
done

Creates a native-image folder in the project folder, triggers SBT's task sbt assembly, moves the created .jar to native-image folder, and at last but not least, generates the native image using GRAALVM native-image command.

Once the executable is ready in the native-image folder, we can run it inside the very same container, by changing the command in the docker-compose to point to ./native-image/{GENERATED-EXECUTABLE-FILE}, or ship it to S3, or create a new docker image and publish to AWS ECR, etc... what to do with the executable is matter of creativity.

Note that we presume that the current Scala project is using sbt-assembly plugin, but any other plugin could be used, like sbt-pack, sbt-native-packager, sbt-onejar, and sbt-proguard.

Spark Job example

The folder spark-job-graalvm-example contains an example where it uses the docker-compose and shell above.

asciicast

References and Inspiration

License

MIT License

Copyright (c) 2018 Vitor S. Vieira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

scala-graalvm-docker's People

Contributors

vitorsvieira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

scala-graalvm-docker's Issues

Cannot fetch artifacts from Sonatype

Because of oracle/graal#378 when I am using scala-graalvm-docker images with CI build with (among others) Sonatype repos, then build might fail.

I found a workaround which works for me:

RUN ORACLE_JRE_URL='http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz' && \
    curl -jkL -H "Cookie: oraclelicense=accept-securebackup-cookie" $ORACLE_JRE_URL | tar -zxvf - --directory $GRAALVM_HOME --wildcards "*/jre/lib/security/cacerts" --strip-components 1

however, it would be nice if these certs were supplied out of the box.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.