Skip to content

Commit

Permalink
Rework Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Oct 26, 2024
1 parent 716664a commit 9241e29
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
57 changes: 25 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
FROM ocaml/opam:alpine-3.3_ocaml-4.03.0 as builder
FROM alpine:3.20 AS builder

RUN sudo apk add m4 expect make binutils gcc
RUN opam depext conf-m4.1
RUN opam install "core_kernel>=v0.9.0" "ocamlfind>=1.7.3" ppx_deriving "menhir>=20170607"
RUN apk update && apk add bash opam m4 expect make binutils gcc musl-dev shadow

RUN sudo mkdir -m a=rwx /silly-ml
RUN useradd -m opam
WORKDIR /silly-ml
COPY Makefile .
COPY _tags .
COPY myocamlbuild.ml .
COPY repl.expect .
COPY *.sh ./
RUN chown opam:opam /silly-ml
USER opam

RUN opam init --bare --no-setup --disable-sandboxing
RUN opam switch create 4.03.0

RUN opam install --yes "core_kernel>=v0.9.0" "ocamlfind>=1.7.3" ppx_deriving "menhir>=20170607"

COPY Makefile _tags myocamlbuild.ml .
COPY src src
RUN sudo mkdir -m a=rwx examples
ADD examples/*.silly-ml examples/
ADD examples/*.exit-code examples/

RUN sudo mkdir -m a=rwx runtime
ADD runtime/include runtime/include/
ADD runtime/*.asm runtime/
ADD runtime/*.c runtime/
ADD runtime/*.h runtime/
ADD runtime/*.sh runtime/
ADD runtime/*.expected runtime/
ADD runtime/*.env runtime/
ADD runtime/Makefile runtime/

RUN eval `opam config env` && make test

FROM alpine:3.3
COPY --chown=opam runtime runtime

RUN opam exec make

COPY repl.expect *.sh .
COPY --chown=opam examples examples

RUN opam exec make test

FROM alpine:3.20
RUN apk update && apk add binutils
WORKDIR /root/
COPY --from=builder /silly-ml/repl.native .
COPY --from=builder /silly-ml/compiler.native .
COPY --from=builder /silly-ml/runtime/libruntime.a .
CMD ["./repl.native"]
WORKDIR /silly-ml
COPY --from=builder /silly-ml/*.native /silly-ml/runtime/libruntime.a .
CMD ["/silly-ml/repl.native"]
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ OCB := ocamlbuild $(OCB_FLAGS)

SRC=$(shell ls src/*.ml src/*.mly src/*.mll)

.PHONY: build
build: compiler.native repl.native runtime/libruntime.a

.PHONY: repl
repl: repl.native
rlwrap ./$<
Expand Down Expand Up @@ -38,11 +41,10 @@ debug: compiler.native
gdb a.out

.PHONY: examples
examples: $(foreach e, $(shell ls examples/*.silly-ml), $(e)-run)
examples: $(foreach e, $(wildcard examples/*.silly-ml), $(e)-run)

examples/%.silly-ml-run: examples/%.silly-ml compiler.native runtime/libruntime.a
./run-example.sh $<

.PHONY: runtime/libruntime.a
runtime/libruntime.a:
$(MAKE) -C runtime libruntime.a

0 comments on commit 9241e29

Please sign in to comment.