From 2b93af70dab6df3686571058e1bfdfcc51a58451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Wed, 18 Dec 2024 18:00:42 +0100 Subject: [PATCH 1/3] Dockerfile/GitHub Actions: update opam-repository for OCaml 5.2.1 --- .github/workflows/ci.yml | 4 ++-- .github/workflows/debug-ci.yml | 4 ++-- Dockerfile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d08ec0581..93b435a1f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - macos-latest - ubuntu-latest ocaml-compiler: - - "5.2.0" + - "5.2" steps: - name: Checkout Repo @@ -35,7 +35,7 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} dune-cache: ${{ matrix.os != 'macos-latest' }} opam-repositories: | - pin: git+https://github.com/ocaml/opam-repository#c45f5bab71d3589f41f9603daca5acad14df0ab0 + pin: git+https://github.com/ocaml/opam-repository#2c9566f0b0de5ab6dad7ce8d22b68a2999a1861f opam-disable-sandboxing: true - name: Install system dependencies (Linux) diff --git a/.github/workflows/debug-ci.yml b/.github/workflows/debug-ci.yml index 0c10658e11..3ba70eb22c 100644 --- a/.github/workflows/debug-ci.yml +++ b/.github/workflows/debug-ci.yml @@ -16,7 +16,7 @@ jobs: - macos-latest - ubuntu-latest ocaml-compiler: - - "5.2.0" + - "5.2" steps: - name: Checkout Repo @@ -28,7 +28,7 @@ jobs: ocaml-compiler: ${{ matrix.ocaml-compiler }} dune-cache: ${{ matrix.os != 'macos-latest' }} opam-repositories: | - pin: git+https://github.com/ocaml/opam-repository#c45f5bab71d3589f41f9603daca5acad14df0ab0 + pin: git+https://github.com/ocaml/opam-repository#2c9566f0b0de5ab6dad7ce8d22b68a2999a1861f opam-disable-sandboxing: true - name: Install system dependencies (Linux) diff --git a/Dockerfile b/Dockerfile index 8698cc0c5e..9113e08e8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN sudo apk -U upgrade --no-cache && sudo apk add --no-cache \ openssl-dev # Branch freeze was opam-repo HEAD at the time of commit -RUN cd ~/opam-repository && git reset --hard c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update +RUN cd ~/opam-repository && git reset --hard 2c9566f0b0de5ab6dad7ce8d22b68a2999a1861f && opam update WORKDIR /home/opam From 804187e1154ccad4f8a2e61a9176c40eb6eaa7ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 12 Dec 2024 09:55:41 +0100 Subject: [PATCH 2/3] Dockerfile: update to Alpine 3.21 and opam 2.3 --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9113e08e8a..271078ba61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM ocaml/opam:alpine-3.19-ocaml-5.2 AS build +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 \ @@ -29,7 +30,8 @@ ENV OCAMLORG_PKG_STATE_PATH=package.state \ OCAMLORG_REPO_PATH=opam-repository RUN touch package.state && ./init-cache package.state -FROM alpine:3.19 + +FROM alpine:3.21 RUN apk -U upgrade --no-cache && apk add --no-cache \ git \ From 9f7b916acfe46506e0ba2dc5f845fe5dfdd868bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 12 Dec 2024 09:56:30 +0100 Subject: [PATCH 3/3] Dockerfile: use BuildKit syntax and features - use mount caches to avoid redownloading apk and opam packages; - use COPY --link for more efficient copy and lighter images; - use BuildKit built-in support for Git clones. --- Dockerfile | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 271078ba61..1e194669d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -17,8 +20,9 @@ RUN cd ~/opam-repository && git reset --hard 2c9566f0b0de5ab6dad7ce8d22b68a2999a 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 . . @@ -33,19 +37,21 @@ 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 data/v2 /v2 +ADD --keep-git-dir --link https://github.com/ocaml-web/html-compiler-manuals /manual +COPY --link data/v2 /v2 RUN git config --global --add safe.directory /var/opam-repository