Skip to content

Instantly share code, notes, and snippets.

@pjullah
Last active May 16, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjullah/3fa105adb0a9f234647e3d213bdae070 to your computer and use it in GitHub Desktop.
Save pjullah/3fa105adb0a9f234647e3d213bdae070 to your computer and use it in GitHub Desktop.
Example of working with Docker, Boot, and Compojure

Background

https://www.reddit.com/r/Clojure/comments/4j7lyx/docker/

http://www.compoundtheory.com/ - article on Dockerising Clojure

I've been setting up an environment to test out an alternative to CORS for an application I'm developing using Nginx as a reverse proxy in front of three Clojure services. In doing so I needed to setup the backend servers to serve requests. But there was hitch. I was using a Dockerised Nginx which was linking to web service containers. Again, that is working fine. I want to be able to live edit the code. In order to do this, I needed to containerise my project, while in development. I took inspiration from adzerk-oss/boot-clj-docker-image - well copied most of the Dockerfile they provided to help me out. I extended their file with WORKDIR /app and ran it like:

$ GIT_SHA=$(git rev-parse --short HEAD); docker build -f Dockerfile.repl -t repl-clj:${GIT_SHA} .
$ docker run -it -v $(pwd):/app repl-clj:9763420 repl

The Docker file now looks like;

FROM debian:wheezy
MAINTAINER Dave Yarwood <dave@adzerk.com>

ENV DEBIAN_FRONTEND noninteractive

# Oracle Java 8

RUN apt-get update \
    && apt-get install -y curl wget openssl ca-certificates \
    && cd /tmp \
    && wget -qO jdk8.tar.gz \
       --header "Cookie: oraclelicense=accept-securebackup-cookie" \
       http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz \
    && tar xzf jdk8.tar.gz -C /opt \
    && mv /opt/jdk* /opt/java \
    && rm /tmp/jdk8.tar.gz \
    && update-alternatives --install /usr/bin/java java /opt/java/bin/java 100 \
    && update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 100 \
    && wget -O /usr/bin/boot https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh \
    && chmod +x /usr/bin/boot

ENV JAVA_HOME /opt/java

# Boot

ENV BOOT_HOME /.boot
ENV BOOT_AS_ROOT yes
ENV BOOT_LOCAL_REPO /m2
ENV BOOT_JVM_OPTIONS=-Xmx2g

WORKDIR /app

# download & install deps, cache REPL and web deps
#RUN /usr/bin/boot web -s doesnt/exist repl -e '(System/exit 0)' && rm -rf target

ENTRYPOINT ["/usr/bin/boot"]

Doh. As I'm reading this, I should just of extended their Dockerfile with my own - exactly as they advised in the project readme.

Anyway, once at the repl, I can do things that by build.boot file allows.

boot.user => (dev)
boot.user => (dev/reset)

I've just run the Docker image again, wow, it's installing all of the deps again, of course it does. Gonna need a way around that, but for the moment, it gets me passed my currect problem.

Things left to do;

  • Connect to the repl from the host
  • Find a way of loading packages at build time, not run time. The origonal Adzerk file did /usr/bin/boot web -s doesnt/exist repl -e '(System/exit 0)' && rm -rf target which I guess achieves what I'm after, but need to understand what it's doing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment