Skip to content

minhtuannguyen/cljocker

Repository files navigation

cljocker

Build Status Coverage Status Dependencies Status Downloads

Clojars Project

A simple DSL to define and generate Dockerfile

Examples

To generate a Dockerfile from spec:

(:require [cljocker.hh.dsl.docker :as d])
            
(defn- heap [heap] (str "-Xmx=" heap "m "))
(defn- port [port] (str "-Dport=" port))

(-> [:from     "java:8"
                :run      (lazy-seq ["mkdir" "-p" "/var/opt/folder"])
                :user     "nobody"
                :add      ["from" "to"]
                :workdir  "/var/opt/folder"
                :cmd      ["java" (heap 512) (port 512) ["-jar" "artifact.jar"]]]
    (d/new-dockerfile)
    (d/write! "path/to/dockerfile"))    

The content of the generated Dockerfile will be:

FROM java:8
RUN mkdir -p /var/opt/folder
USER nobody
ADD from to
WORKDIR /var/opt/folder
CMD java  -Xmx=512m  -Dport=512  -jar artifact.jar    

To validate a dockerfile spec:

(:require [cljocker.hh.dsl.docker :as d])
            
(is (= [:valid]
       (-> [:from "image" :cmd "echo"]
           (d/new-dockerfile)
           (d/validate))))   
       
(is (= [:invalid "first instruction must be FROM"]
       (-> [:cmd "echo"]
           (d/new-dockerfile)
           (d/validate))))

License

Copyright © 2016 Distributed under the Eclipse Public License