Skip to content

Commit

Permalink
Merge pull request #3023 from metacpan/haarg/docker-optim
Browse files Browse the repository at this point in the history
optimize docker setup for better caching
  • Loading branch information
oalders authored Apr 27, 2024
2 parents 88c71bd + 21df985 commit 9ac806c
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@ ARG CPM_ARGS=--with-test

ENV NO_UPDATE_NOTIFIER=1

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN curl -sL https://deb.nodesource.com/setup_18.x | bash \
&& apt-get update \
&& apt-get install -y -f --no-install-recommends libcmark-dev dumb-init nodejs \
&& apt-get clean \
&& npm install -g npm \
&& rm -rf /var/lib/apt/lists/* /root/.npm

COPY . /metacpan-web/
WORKDIR /metacpan-web

RUN npm install --verbose && npm cache clean --force

RUN cpanm --notest App::cpm \
&& cpm install -g Carton \
&& useradd -m metacpan-web -g users \
&& cpm install -g ${CPM_ARGS}\
&& rm -fr /root/.cpanm /root/.perl-cpm /tmp/*

RUN chown -R metacpan-web:users /metacpan-web

USER metacpan-web:users
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt/lists,sharing=private \
--mount=type=cache,target=/root/.npm,sharing=private \
<<EOT /bin/bash -euo pipefail
curl -fsSL https://deb.nodesource.com/setup_21.x | bash -
apt update
apt install -y -f --no-install-recommends nodejs
npm install -g npm
apt install -y -f libcmark-dev dumb-init
EOT

WORKDIR /metacpan-web/
RUN chown metacpan:users /metacpan-web/

COPY --chown=metacpan:users package.json package-lock.json .
RUN \
--mount=type=cache,target=/root/.npm,sharing=private \
<<EOT /bin/bash -euo pipefail
npm install --verbose
npm audit fix
EOT

COPY --chown=metacpan:users cpanfile cpanfile.snapshot .
RUN \
--mount=type=cache,target=/root/.perl-cpm,sharing=private \
<<EOT /bin/bash -euo pipefail
cpm install -g ${CPM_ARGS}
EOT

COPY --chown=metacpan:users . .
RUN mkdir var && chown metacpan:users var

USER metacpan

EXPOSE 5001

Expand Down

0 comments on commit 9ac806c

Please sign in to comment.