Skip to content

Commit 4b7f710

Browse files
committed
Use BuildKit syntax in Dockerfile
Should speed up builds a bit.
1 parent ffee796 commit 4b7f710

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

Dockerfile

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,60 @@
1-
FROM ocaml/opam:alpine-3.20-ocaml-5.2 as build
1+
# syntax=docker/dockerfile:1
2+
FROM ocaml/opam:alpine-3.20-ocaml-5.2 AS build
3+
RUN sudo ln -sf /usr/bin/opam-2.3 /usr/bin/opam && opam init --reinit -ni
24

35
# Install system dependencies
4-
RUN sudo apk update && sudo apk add --update libev-dev openssl-dev gmp-dev oniguruma-dev inotify-tools curl-dev autoconf
6+
RUN sudo apk add --no-cache \
7+
autoconf \
8+
curl-dev \
9+
gmp-dev \
10+
inotify-tools \
11+
libev-dev \
12+
oniguruma-dev \
13+
openssl-dev
514

615
# Branch freeze was opam-repo HEAD at the time of commit
7-
RUN cd opam-repository && git pull origin c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update
16+
RUN cd ~/opam-repository && git fetch -q origin master && git reset --hard 11bdbee61114a1cfa080b764e71c72a5760a93f0 && opam update
817

918
WORKDIR /home/opam
1019

11-
# Install Opam dependencies
12-
ADD ocamlorg.opam ocamlorg.opam
13-
RUN opam install . --deps-only
20+
# Install opam dependencies
21+
COPY --chown=opam --link ocamlorg.opam .
22+
RUN --mount=type=cache,target=/home/opam/.opam/download-cache,sharing=locked,uid=1000,gid=1000 \
23+
opam install . --deps-only
1424

1525
# Build project
16-
COPY --chown=opam:opam . .
26+
COPY --chown=opam . .
1727
RUN opam exec -- dune build @install --profile=release
1828

1929
# Launch project in order to generate the package state cache
20-
RUN cd opam-repository && git checkout master && git pull origin master && opam update
21-
ENV OCAMLORG_REPO_PATH opam-repository
22-
ENV OCAMLORG_PKG_STATE_PATH package.state
30+
RUN cd ~/opam-repository && git checkout master && opam update
31+
ENV OCAMLORG_REPO_PATH=opam-repository
32+
ENV OCAMLORG_PKG_STATE_PATH=package.state
2333
RUN touch package.state && ./init-cache package.state
2434

25-
FROM alpine:3.20 as run
35+
FROM alpine:3.20 AS run
2636

27-
RUN apk update && apk add --update libev gmp git
37+
RUN apk add --no-cache \
38+
git \
39+
gmp \
40+
libev
2841

29-
RUN chmod -R 755 /var
42+
COPY --from=build --link /home/opam/package.state /var/package.state
43+
COPY --from=build --link /home/opam/opam-repository /var/opam-repository
44+
COPY --from=build --link /home/opam/_build/default/src/ocamlorg_web/bin/main.exe /bin/server
3045

31-
COPY --from=build /home/opam/package.state /var/package.state
32-
COPY --from=build /home/opam/opam-repository /var/opam-repository
33-
COPY --from=build /home/opam/_build/default/src/ocamlorg_web/bin/main.exe /bin/server
46+
COPY --link playground/asset playground/asset
3447

35-
COPY playground/asset playground/asset
36-
37-
RUN git clone https://github.com/ocaml-web/html-compiler-manuals /manual
48+
ADD --keep-git-dir --link https://github.com/ocaml-web/html-compiler-manuals /manual
3849

3950
RUN git config --global --add safe.directory /var/opam-repository
4051

41-
ENV OCAMLORG_REPO_PATH /var/opam-repository/
42-
ENV OCAMLORG_MANUAL_PATH /manual
43-
ENV OCAMLORG_PKG_STATE_PATH /var/package.state
44-
ENV DREAM_VERBOSITY info
45-
ENV OCAMLORG_HTTP_PORT 8080
52+
ENV OCAMLORG_REPO_PATH=/var/opam-repository/
53+
ENV OCAMLORG_MANUAL_PATH=/manual
54+
ENV OCAMLORG_PKG_STATE_PATH=/var/package.state
55+
ENV DREAM_VERBOSITY=info
56+
ENV OCAMLORG_HTTP_PORT=8080
4657

4758
EXPOSE 8080
4859

49-
ENTRYPOINT /bin/server
60+
ENTRYPOINT ["/bin/server"]

0 commit comments

Comments
 (0)