Skip to content

Instantly share code, notes, and snippets.

@rizo
Last active January 30, 2020 10:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizo/d73c0bacc5446eeb75ebe0e985d6d301 to your computer and use it in GitHub Desktop.
Save rizo/d73c0bacc5446eeb75ebe0e985d6d301 to your computer and use it in GitHub Desktop.
Dockerfile for esy projects.
# Build image
FROM node:10.13-alpine as build
# Prepare the environment to install esy.
RUN apk add --no-cache \
ca-certificates wget \
bash curl perl-utils \
git patch gcc g++ musl-dev make m4
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
RUN wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk
RUN apk add --no-cache glibc-2.28-r0.apk
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
RUN npm install -g --unsafe-perm esy@0.4.3
RUN esy --version
WORKDIR /root
# Copy _only_ project description files.
COPY --chown=root:nogroup package.json esy.lock /root/
# If you have sub-packages referenced with `link` in `package.json` add them here.
# This is compatible with dune's composable (ie monorepo) builds.
#RUN mkdir -p /root/some-sub-package
#COPY --chown=root:nogroup some-sub-package/package.json some-sub-package/esy.lock /root/some-sub-package/
# Install and build the dependencies.
# In this case `esy build` will only build the dependencies from the package description because we
# haven't copied any project source and dune files.
RUN esy install
RUN esy build
# Add the full project tree with sources and dune files.
# This will build the actual project and reuse the prebuilt dependencies from the previous step.
COPY --chown=root:nogroup . /root/
RUN esy build
# We install all public libs/bins for export.
RUN esy dune install --prefix=/root/_export
# Run image
FROM alpine:3.6
WORKDIR /mnt/local
ENV PATH /mnt/local/bin:$PATH
# Copy the exported files from the build stage.
COPY --from=build /root/_export /mnt/local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment