Skip to content

Commit b082aa9

Browse files
committed
refresh Dockerfile for better caching
Update the Dockerfile to better use caching by separating the prereq building. Also switch the server to uwsgi rather than using the Mojolicious wrapper. It provided little benefit and caused numerous problems, and we haven't been using it in production for a while.
1 parent 8e44077 commit b082aa9

File tree

2 files changed

+114
-20
lines changed

2 files changed

+114
-20
lines changed

Dockerfile

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,101 @@
1-
# hadolint ignore=DL3007
2-
FROM metacpan/metacpan-base:latest
3-
4-
COPY cpanfile cpanfile.snapshot /metacpan-api/
5-
WORKDIR /metacpan-api
6-
7-
# CPM installations of dependencies does not install or run tests. This is
8-
# because the modules themselves have been tested, and the metacpan use of the
9-
# modules is tested by the test suite. Removing the tests, reduces the overall
10-
# size of the images.
11-
RUN mkdir /CPAN \
12-
&& apt-get update \
13-
&& apt-get satisfy -y --no-install-recommends 'rsync (>= 3.2.3)' 'jq (>= 1.6)' \
14-
&& apt-get clean \
15-
&& rm -rf /var/lib/apt/lists/* \
16-
&& cpm install --global \
17-
&& git config --global --add safe.directory /metacpan-api \
18-
&& rm -fr /root/.cpanm /root/.perl-cpm /var/cache/apt/lists/* /tmp/*
1+
ARG SLIM_BUILD
2+
ARG MAYBE_BASE_BUILD=${SLIM_BUILD:+server-base-slim}
3+
ARG BASE_BUILD=${MAYBE_BASE_BUILD:-server-base}
4+
5+
################### Web Server Base
6+
FROM metacpan/metacpan-base:main-20250531-090128 AS server-base
7+
FROM metacpan/metacpan-base:main-20250531-090129-slim AS server-base-slim
8+
9+
################### CPAN Prereqs
10+
FROM server-base AS build-cpan-prereqs
11+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
12+
13+
WORKDIR /app/
14+
15+
COPY cpanfile cpanfile.snapshot ./
16+
RUN \
17+
--mount=type=cache,target=/root/.perl-cpm,sharing=private \
18+
<<EOT
19+
cpm install --show-build-log-on-failure --resolver=snapshot
20+
EOT
21+
22+
################### Web Server
23+
# false positive
24+
# hadolint ignore=DL3006
25+
FROM ${BASE_BUILD} AS server
26+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
27+
28+
WORKDIR /app/
29+
30+
COPY app.psgi log4perl* metacpan_server.* metacpan_server_local.* ./
31+
COPY es es
32+
COPY bin bin
33+
COPY lib lib
34+
COPY root root
35+
36+
COPY --from=build-cpan-prereqs /app/local local
37+
38+
ENV PERL5LIB="/app/local/lib/perl5"
39+
ENV PATH="/app/local/bin:${PATH}"
40+
ENV METACPAN_SERVER_HOME=/app
1941

2042
VOLUME /CPAN
2143

22-
EXPOSE 5000
44+
USER metacpan
45+
46+
CMD [ \
47+
"/uwsgi.sh", \
48+
"--http-socket", ":8000" \
49+
]
50+
51+
EXPOSE 8000
52+
53+
HEALTHCHECK --start-period=3s CMD [ "curl", "--fail", "http://localhost:8000/healthcheck" ]
54+
55+
################### Development Server
56+
FROM server AS develop
57+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
58+
59+
ENV COLUMNS=120
60+
ENV PLACK_ENV=development
61+
62+
USER root
63+
64+
COPY cpanfile cpanfile.snapshot ./
65+
66+
RUN \
67+
--mount=type=cache,target=/root/.perl-cpm \
68+
<<EOT
69+
cpm install --show-build-log-on-failure --resolver=snapshot --with-develop
70+
chown -R metacpan:users ./
71+
EOT
72+
73+
USER metacpan
74+
75+
################### Test Runner
76+
FROM develop AS test
77+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
78+
79+
ENV PLACK_ENV=
80+
81+
USER root
82+
83+
RUN \
84+
--mount=type=cache,target=/root/.perl-cpm \
85+
<<EOT
86+
cpm install --show-build-log-on-failure --resolver=snapshot --with-test
87+
EOT
88+
89+
COPY .perlcriticrc .perltidyrc perlimports.toml precious.toml .editorconfig metacpan_server_testing.* ./
90+
COPY t t
91+
COPY test-data test-data
92+
93+
RUN chown metacpan t/var
94+
95+
USER metacpan
96+
CMD [ "prove", "-l", "-r", "-j", "2", "t" ]
97+
98+
################### Production Server
99+
FROM server AS production
23100

24-
CMD [ "/wait-for-it.sh", "${PGDB}", "--", "${API_SERVER}", "./bin/api.pl" ]
101+
USER metacpan

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
api-server:
3+
build:
4+
context: .
5+
target: develop
6+
volumes:
7+
- './:/app/'
8+
- '/app/local'
9+
ports:
10+
- '8001:8000'
11+
environment:
12+
# default is 120, shorten to work with compose label
13+
COLUMNS: 96
14+
develop:
15+
watch:
16+
- path: ./cpanfile
17+
action: rebuild

0 commit comments

Comments
 (0)