Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active October 15, 2019 07:32
Show Gist options
  • Save cellularmitosis/66e024439cdefbc43375a4988882af11 to your computer and use it in GitHub Desktop.
Save cellularmitosis/66e024439cdefbc43375a4988882af11 to your computer and use it in GitHub Desktop.
"Hello, world" in Clojure compiled with GraalVM running in Docker

Blog 2019/7/18

<- previous | index | next ->

"Hello, world" in Clojure compiled with GraalVM running in Docker

Create a new minimal Clojure project using leiningen:

$ lein new minimal hello
$ cd hello

Edit project.clj to look like this:

(defproject hello "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.0"]]
  :profiles {:dev {:dependencies [[org.clojure/test.check "0.9.0"]]}} :main hello.core)

Edit src/hello/core.clj to look like this:

(ns hello.core
  (:gen-class))

(defn -main []
  (println "Hello, clombda!"))

According to this you also need to run this:

$ lein change :main set hello.core

Build a native image:

$ docker run --rm "-v$(pwd):/clj" "-v${HOME}/.m2:/root/.m2" spieden/clombda:latest

Create a Dockerfile:

FROM renanpalmeira/graalvm-alpine
COPY target/clombda/package/clj-native /root/
CMD ["/root/clj-native"]

Build a docker image:

$ docker build -t hello .

Run it:

$ docker run hello
Hello, clombda!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment