cache elm packages of an elm project; CI can use `ELM_HOME=elm-stuff/.elm` to use the files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:12.15.0-alpine3.9 | |
RUN apk add --update make curl gzip | |
RUN curl -L -o elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz && \ | |
gzip -d elm.gz && \ | |
chmod +x elm && \ | |
mv elm /usr/local/bin/ | |
# following https://github.com/elm/compiler/blob/c8be24eb8e6d15f76532c3be7626c7df424c4628/installers/linux/README.md | |
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What to do when Elm Package Registry is down? | |
# https://discourse.elm-lang.org/t/what-to-do-when-elm-package-registry-is-down/5048/6 | |
# | |
# TLDR: | |
# cache the $ELM_HOME directory such that you do not need to talk to | |
# package.elm-lang.org or to github.com 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