Skip to content

Instantly share code, notes, and snippets.

Last active Feb 15, 2020
What would you like to do?
cache elm packages of an elm project; CI can use `ELM_HOME=elm-stuff/.elm` to use the files
FROM node:12.15.0-alpine3.9
RUN apk add --update make curl gzip
RUN curl -L -o elm.gz && \
gzip -d elm.gz && \
chmod +x elm && \
mv elm /usr/local/bin/
# following
COPY elm.json /app/elm.json
RUN mkdir /app/src && printf "module Main exposing (..)\nx = 42" > /app/src/Main.elm
RUN cd /app && ELM_HOME=/app/elm-stuff/.elm elm make src/Main.elm --output /dev/null
# elm packages now cached in `/app/elm-stuff/.elm`
# What to do when Elm Package Registry is down?
# cache the $ELM_HOME directory such that you do not need to talk to
# or to unless a new package dependency was added.
# This target `elm-stuff/.elm` should only re-run when `elm.json` is more recent
# 1. Running `make elm-stuff/.elm` will
# a. spin up Docker and cache the packages used in `elm.json`; all steps are cached
# b. always export the cached packages to local disk on `elm-stuff/.elm`
# 2. From this point onwards, any CI process that need cached packages can
# simply set `ELM_HOME=elm-stuff/.elm`
# NOTE: path `elm-stuff/.elm` was picked so there's no extra subdirectory to gitignore
elm-stuff/.elm: elm.json
tar -cf - Dockerfile elm.json | docker build - -f Dockerfile --iidfile iidfile
docker run --detach --cidfile cidfile `cat iidfile`
mkdir -p elm-stuff
docker cp `cat cidfile`:/app/elm-stuff/.elm elm-stuff/
docker rm -f `cat cidfile`
rm -f cidfile iidfile
touch elm-stuff/.elm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment