Skip to content

Commit

Permalink
Dockerfile: use BuildKit syntax and features
Browse files Browse the repository at this point in the history
- use mount caches to avoid redownloading apk packages;
- use COPY --link for more efficient copy and lighter images;
- use Buildkit built-in support for Git clones.
  • Loading branch information
MisterDA committed Dec 20, 2024
1 parent 5d01a4b commit c3e4a9c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# syntax=docker/dockerfile:1
FROM ocaml/opam:alpine-3.21-ocaml-5.2 AS build
RUN sudo ln -sf /usr/bin/opam-2.3 /usr/bin/opam && opam init --reinit -ni

# Install system dependencies
RUN sudo apk -U upgrade --no-cache && sudo apk add --no-cache \
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
sudo ln -s /var/cache/apk /etc/apk/cache && \
sudo apk -U upgrade && sudo apk add \
autoconf \
curl-dev \
gmp-dev \
Expand All @@ -17,8 +20,9 @@ RUN cd ~/opam-repository && git reset --hard de786e28dbea73843ad5e5f0290a4e81fba
WORKDIR /home/opam

# Install opam dependencies
COPY --chown=opam ocamlorg.opam .
RUN opam install . --deps-only
COPY --chown=opam --link ocamlorg.opam .
RUN --mount=type=cache,target=/home/opam/.opam/download-cache,sharing=locked,uid=1000,gid=1000 \
opam install . --deps-only

# Build project
COPY --chown=opam . .
Expand All @@ -33,18 +37,20 @@ RUN touch package.state && ./init-cache package.state

FROM alpine:3.21

RUN apk -U upgrade --no-cache && apk add --no-cache \
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
ln -s /var/cache/apk /etc/apk/cache && \
apk -U upgrade && apk add \
git \
gmp \
libev

COPY --from=build /home/opam/package.state /var/package.state
COPY --from=build /home/opam/opam-repository /var/opam-repository
COPY --from=build /home/opam/_build/default/src/ocamlorg_web/bin/main.exe /bin/server
COPY --from=build --link /home/opam/package.state /var/package.state
COPY --from=build --link /home/opam/opam-repository /var/opam-repository
COPY --from=build --link /home/opam/_build/default/src/ocamlorg_web/bin/main.exe /bin/server

COPY playground/asset playground/asset
COPY --link playground/asset playground/asset

RUN git clone https://github.com/ocaml-web/html-compiler-manuals /manual
ADD --keep-git-dir --link https://github.com/ocaml-web/html-compiler-manuals /manual

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

Expand Down

0 comments on commit c3e4a9c

Please sign in to comment.