Skip to content

Commit

Permalink
Recreate PR #2861: Dockerfile cleanup (#2866)
Browse files Browse the repository at this point in the history
* Dockerfile: fix style

- don't cache packages to lighten the image.

* Update Dockerfile

Co-authored-by: Antonin Décimo <[email protected]>

* Update Dockerfile

Co-authored-by: Antonin Décimo <[email protected]>

* Don't fetch before building the switch

* Remove unwanted line

---------

Co-authored-by: Antonin Décimo <[email protected]>
Co-authored-by: Antonin Décimo <[email protected]>
Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
  • Loading branch information
4 people authored Dec 18, 2024
1 parent ad6bcb5 commit 1f6805e
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
FROM ocaml/opam:alpine-3.19-ocaml-5.2 as build
FROM ocaml/opam:alpine-3.19-ocaml-5.2 AS build

# Install system dependencies
RUN sudo apk update && sudo apk add --update libev-dev openssl-dev gmp-dev oniguruma-dev inotify-tools curl-dev autoconf
RUN sudo apk -U upgrade --no-cache && sudo apk add --no-cache \
autoconf \
curl-dev \
gmp-dev \
inotify-tools \
libev-dev \
oniguruma-dev \
openssl-dev

# Branch freeze was opam-repo HEAD at the time of commit
RUN cd opam-repository && git pull origin c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update
RUN cd ~/opam-repository && git reset --hard c45f5bab71d3589f41f9603daca5acad14df0ab0 && opam update

WORKDIR /home/opam

# Install Opam dependencies
ADD ocamlorg.opam ocamlorg.opam
# Install opam dependencies
COPY --chown=opam ocamlorg.opam .
RUN opam install . --deps-only

# Build project
COPY --chown=opam:opam . .
COPY --chown=opam . .
RUN opam exec -- dune build @install --profile=release

# Launch project in order to generate the package state cache
RUN cd opam-repository && git checkout master && git pull origin master && opam update
ENV OCAMLORG_REPO_PATH opam-repository
ENV OCAMLORG_PKG_STATE_PATH package.state
RUN cd ~/opam-repository && git checkout master && git pull origin master && opam update
ENV OCAMLORG_PKG_STATE_PATH=package.state \
OCAMLORG_REPO_PATH=opam-repository
RUN touch package.state && ./init-cache package.state

FROM alpine:3.19 as run
FROM alpine:3.19

RUN apk update && apk add --update libev gmp git

RUN chmod -R 755 /var
RUN apk -U upgrade --no-cache && apk add --no-cache \
git \
gmp \
libev

COPY --from=build /home/opam/package.state /var/package.state
COPY --from=build /home/opam/opam-repository /var/opam-repository
Expand All @@ -38,12 +46,12 @@ RUN git clone https://github.com/ocaml-web/html-compiler-manuals /manual

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

ENV OCAMLORG_REPO_PATH /var/opam-repository/
ENV OCAMLORG_MANUAL_PATH /manual
ENV OCAMLORG_PKG_STATE_PATH /var/package.state
ENV DREAM_VERBOSITY info
ENV OCAMLORG_HTTP_PORT 8080
ENV DREAM_VERBOSITY=info \
OCAMLORG_HTTP_PORT=8080 \
OCAMLORG_MANUAL_PATH=/manual \
OCAMLORG_PKG_STATE_PATH=/var/package.state \
OCAMLORG_REPO_PATH=/var/opam-repository/

EXPOSE 8080

ENTRYPOINT /bin/server
ENTRYPOINT ["/bin/server"]

0 comments on commit 1f6805e

Please sign in to comment.