Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1022 Bytes

04-minimal-app.md

File metadata and controls

51 lines (37 loc) · 1022 Bytes

A minimal Clojure webapp

Structure

mkdir -p hey-clj/src/hey

project.clj

(defproject hey "0.0.1"
  :dependencies [[org.clojure/clojure "1.9.0"]
                 [ring/ring-core "1.6.3"]
                 [ring/ring-jetty-adapter "1.6.3"]]
  :main hey.core)

hey.core

(ns hey.core
  (:gen-class)
  (:require [ring.adapter.jetty :as jetty]))

(defn handler [my-name request]
  {:status 200
   :headers {"Content-Type" "text/html"}
   :body (format "Hello %s from Clojure, Docker, and Kubernetes." my-name)})

(defn -main [& args]
  (let [my-name (or (System/getenv "MY_NAME") 
                     "World")]
    (jetty/run-jetty (partial handler my-name) {:port 3000})))

Run it locally, without an environment variable

$ lein run

Run it locally, with an environment variable

$ MY_NAME=Monty lein run

Next: Create the Docker Image

If you need to take down your cluster, see Cleanup