diff --git a/tools/mirage-compile/.gitignore b/tools/mirage-compile/.gitignore new file mode 100644 index 000000000..052e350ae --- /dev/null +++ b/tools/mirage-compile/.gitignore @@ -0,0 +1,3 @@ +*.hash +functoria +mirage diff --git a/tools/mirage-compile/Dockerfile b/tools/mirage-compile/Dockerfile new file mode 100644 index 000000000..6ebfa314b --- /dev/null +++ b/tools/mirage-compile/Dockerfile @@ -0,0 +1,18 @@ +FROM ocaml/opam:alpine-3.5_ocaml-4.04.0 +RUN git -C /home/opam/opam-repository pull origin master && opam update -u + +RUN opam pin add -n functoria https://github.com/samoht/functoria.git#output +RUN opam pin add -n mirage https://github.com/samoht/mirage.git#static +RUN opam pin add -n mirage-net-fd https://github.com/mirage/mirage-net-fd.git +RUN opam pin add -n charrua-client https://github.com/yomimono/charrua-client.git#state-halfway +RUN opam depext -uiy ocamlfind topkg-care ocamlbuild lwt mirage-types-lwt mirage +RUN opam depext -uiy charrua-client cohttp conduit mirage-unix +RUN opam depext -uiy mirage-net-fd ptime mirage-logs + +RUN sudo mkdir -p /src +RUN sudo chown -R opam /src +WORKDIR /src + +COPY compile.sh /usr/bin/ + +ENTRYPOINT ["/usr/bin/compile.sh"] diff --git a/tools/mirage-compile/Makefile b/tools/mirage-compile/Makefile new file mode 100644 index 000000000..2e463671a --- /dev/null +++ b/tools/mirage-compile/Makefile @@ -0,0 +1,33 @@ +.PHONY: tag push + +BASE=ocaml/opam:alpine-3.5_ocaml-4.04.0 +IMAGE=mirage-compile + +default: push + +hash: Dockerfile compile.sh + docker pull $(BASE) + tar cf - $^ | docker build -t $(IMAGE):build - + docker run --rm --entrypoint=/bin/sh $(IMAGE):build -c \ + '{ dpkg-query -W; \ + opam list; \ + cat /usr/bin/compile.sh; \ + } | sha1sum' | sed 's/ .*//' > hash + +push: hash + docker pull mobylinux/$(IMAGE):$(shell cat hash) || \ + (docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \ + docker push mobylinux/$(IMAGE):$(shell cat hash)) + docker rmi $(IMAGE):build + rm -f hash + +tag: hash + docker pull mobylinux/$(IMAGE):$(shell cat hash) || \ + docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) + docker rmi $(IMAGE):build + rm -f hash + +clean: + rm -f hash $(HASHES) + +.DELETE_ON_ERROR: diff --git a/tools/mirage-compile/compile.sh b/tools/mirage-compile/compile.sh new file mode 100755 index 000000000..fdfcadc03 --- /dev/null +++ b/tools/mirage-compile/compile.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +set -e + +usage() { + echo "Usage: -o file" + exit 1 +} + +[ $# = 0 ] && usage + +while [ $# -gt 0 ] +do + flag="$1" + case "$flag" in + -o) + [ $# -eq 1 ] && usage + out="$2" + mkdir -p "$(dirname $2)" + shift + ;; + *) + echo "Unknown option $1" + exit 1 + esac + shift +done + +[ -z "$out" ] && usage + +package=$(basename "$out") + +dir="/src" + +# untar input +tar xf - -C $dir + +( + cd $dir + opam config exec -- mirage configure -o $out -t unix + opam config exec -- make depend + opam config exec -- make + mv $(readlink $out) $out +) > /src/logs 2>&1 + +cd $dir && tar -cf - $out + +exit 0