Skip to content

Commit 3451dd7

Browse files
drdrew42claude
andcommitted
Modernize Docker build and update PG to 2.20.1
Multi-stage Dockerfile (Ubuntu 24.04, Node 22) cuts image size from ~1.5GB to ~770MB. Builder stage compiles XS modules and JS assets; runtime stage copies only what's needed to serve requests. - Add cpanfile for reproducible Perl dependency installs - Add .dockerignore to exclude docs, tests, git metadata from context - Update PG submodule to 2.20.1 (PG-2.20 tag + 21 hotfixes) - Update pg_config.yml for PG 2.20 macro/context paths - Rewrite README with configuration reference, deployment topologies, and JWT documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2d5ac98 commit 3451dd7

7 files changed

Lines changed: 335 additions & 116 deletions

File tree

.dockerignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
# Version control
12
.git
23
.gitignore
4+
.gitattributes
5+
.gitmodules
6+
.github
7+
8+
# Documentation & metadata
9+
README.md
10+
LICENSE.md
11+
CLAUDE.md
12+
docs/
13+
14+
# Kubernetes manifests
15+
k8/
16+
17+
# IDE & OS files
18+
.idea/
19+
*.swp
20+
*.swo
21+
*~
322
**/.DS_Store
23+
24+
# Build artifacts & temp files
25+
*.o
26+
*.bs
27+
*.pid
28+
*.pm.tdy
29+
logs/*
30+
tmp/*
31+
32+
# Local data (mounted at runtime, not baked in)
33+
webwork-open-problem-library/
34+
private/
35+
36+
# Node modules (npm install runs in Dockerfile)
37+
node_modules
38+
public/node_modules
39+
lib/PG/htdocs/node_modules
40+
41+
# Generated assets (built in Dockerfile)
42+
public/**/*.min.js
43+
public/**/*.min.css
44+
public/static-assets.json

Dockerfile

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:20.04
1+
# Stage 1: Builder — install all build tools, compile Perl XS modules, generate JS/CSS assets
2+
FROM ubuntu:24.04 AS builder
23
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer
34

45
WORKDIR /usr/app
@@ -41,12 +42,13 @@ RUN apt-get update \
4142
libdata-structure-util-perl \
4243
liblocale-maketext-lexicon-perl \
4344
libyaml-libyaml-perl \
44-
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
45+
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
4546
&& apt-get install -y --no-install-recommends --no-install-suggests nodejs \
4647
&& apt-get clean \
4748
&& rm -fr /var/lib/apt/lists/* /tmp/*
4849

49-
RUN cpanm install Mojo::Base Statistics::R::IO::Rserve Date::Format Future::AsyncAwait Crypt::JWT IO::Socket::SSL CGI::Cookie \
50+
COPY cpanfile .
51+
RUN cpanm --installdeps . \
5052
&& rm -fr ./cpanm /root/.cpanm /tmp/*
5153

5254
COPY . .
@@ -55,12 +57,61 @@ RUN cp renderer.conf.dist renderer.conf
5557

5658
RUN cp conf/pg_config.yml lib/PG/conf/pg_config.yml
5759

58-
RUN cd public/ && npm install && cd ..
60+
# Install all npm deps (including devDependencies for asset generation),
61+
# then prune to production-only for the runtime image.
62+
RUN cd public/ && npm install && npm prune --omit=dev && cd ..
5963

60-
RUN cd lib/PG/htdocs && npm install && cd ../../..
64+
RUN cd lib/PG/htdocs && npm install && npm prune --omit=dev && cd ../../..
65+
66+
# Stage 2: Runtime — only what's needed to serve requests
67+
FROM ubuntu:24.04
68+
69+
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer
70+
71+
WORKDIR /usr/app
72+
ARG DEBIAN_FRONTEND=noninteractive
73+
ENV TZ=America/New_York
74+
75+
RUN apt-get update \
76+
&& apt-get install -y --no-install-recommends --no-install-suggests \
77+
apt-utils \
78+
curl \
79+
dvipng \
80+
openssl \
81+
libgd-perl \
82+
imagemagick \
83+
libdbi-perl \
84+
libjson-perl \
85+
libcgi-pm-perl \
86+
libjson-xs-perl \
87+
ca-certificates \
88+
libstorable-perl \
89+
libdatetime-perl \
90+
libuuid-tiny-perl \
91+
libtie-ixhash-perl \
92+
libhttp-async-perl \
93+
libnet-ssleay-perl \
94+
libarchive-zip-perl \
95+
libcrypt-ssleay-perl \
96+
libclass-accessor-perl \
97+
libstring-shellquote-perl \
98+
libproc-processtable-perl \
99+
libmath-random-secure-perl \
100+
libdata-structure-util-perl \
101+
liblocale-maketext-lexicon-perl \
102+
libyaml-libyaml-perl \
103+
&& apt-get clean \
104+
&& rm -fr /var/lib/apt/lists/* /tmp/*
105+
106+
# Copy cpanm-installed Perl modules (XS .so + pure Perl) and Mojo binaries.
107+
# Copies all of /usr/local/ to stay architecture-independent (avoids hardcoding aarch64/x86_64 paths).
108+
COPY --from=builder /usr/local /usr/local
109+
110+
# Copy the full app tree (includes pruned node_modules and generated assets)
111+
COPY --from=builder /usr/app /usr/app
61112

62113
EXPOSE 3000
63114

64115
HEALTHCHECK CMD curl -I localhost:3000/health
65116

66-
CMD hypnotoad -f ./script/renderer
117+
CMD ["hypnotoad", "-f", "./script/renderer"]

Dockerfile_with_OPL

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:20.04
1+
# Stage 1: Builder — install all build tools, compile Perl XS modules, generate JS/CSS assets
2+
FROM ubuntu:24.04 AS builder
23
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer
34

45
WORKDIR /usr/app
@@ -41,12 +42,13 @@ RUN apt-get update \
4142
libdata-structure-util-perl \
4243
liblocale-maketext-lexicon-perl \
4344
libyaml-libyaml-perl \
44-
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
45+
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
4546
&& apt-get install -y --no-install-recommends --no-install-suggests nodejs \
4647
&& apt-get clean \
4748
&& rm -fr /var/lib/apt/lists/* /tmp/*
4849

49-
RUN cpanm install Mojo::Base Statistics::R::IO::Rserve Date::Format Future::AsyncAwait Crypt::JWT IO::Socket::SSL CGI::Cookie \
50+
COPY cpanfile .
51+
RUN cpanm --installdeps . \
5052
&& rm -fr ./cpanm /root/.cpanm /tmp/*
5153

5254
ENV MOJO_MODE=production
@@ -66,12 +68,62 @@ RUN cp renderer.conf.dist renderer.conf
6668

6769
RUN cp conf/pg_config.yml lib/PG/conf/pg_config.yml
6870

69-
RUN npm install
71+
# Install all npm deps (including devDependencies for asset generation),
72+
# then prune to production-only for the runtime image.
73+
RUN cd public/ && npm install && npm prune --omit=dev && cd ..
7074

71-
RUN cd lib/PG/htdocs && npm install && cd ../../..
75+
RUN cd lib/PG/htdocs && npm install && npm prune --omit=dev && cd ../../..
76+
77+
# Stage 2: Runtime — only what's needed to serve requests
78+
FROM ubuntu:24.04
79+
80+
LABEL org.opencontainers.image.source=https://github.com/openwebwork/renderer
81+
82+
WORKDIR /usr/app
83+
ARG DEBIAN_FRONTEND=noninteractive
84+
ENV TZ=America/New_York
85+
ENV MOJO_MODE=production
86+
87+
RUN apt-get update \
88+
&& apt-get install -y --no-install-recommends --no-install-suggests \
89+
apt-utils \
90+
curl \
91+
dvipng \
92+
openssl \
93+
libgd-perl \
94+
imagemagick \
95+
libdbi-perl \
96+
libjson-perl \
97+
libcgi-pm-perl \
98+
libjson-xs-perl \
99+
ca-certificates \
100+
libstorable-perl \
101+
libdatetime-perl \
102+
libuuid-tiny-perl \
103+
libtie-ixhash-perl \
104+
libhttp-async-perl \
105+
libnet-ssleay-perl \
106+
libarchive-zip-perl \
107+
libcrypt-ssleay-perl \
108+
libclass-accessor-perl \
109+
libstring-shellquote-perl \
110+
libproc-processtable-perl \
111+
libmath-random-secure-perl \
112+
libdata-structure-util-perl \
113+
liblocale-maketext-lexicon-perl \
114+
libyaml-libyaml-perl \
115+
&& apt-get clean \
116+
&& rm -fr /var/lib/apt/lists/* /tmp/*
117+
118+
# Copy cpanm-installed Perl modules (XS .so + pure Perl) and Mojo binaries.
119+
# Copies all of /usr/local/ to stay architecture-independent (avoids hardcoding aarch64/x86_64 paths).
120+
COPY --from=builder /usr/local /usr/local
121+
122+
# Copy the full app tree (includes OPL, pruned node_modules, and generated assets)
123+
COPY --from=builder /usr/app /usr/app
72124

73125
EXPOSE 3000
74126

75127
HEALTHCHECK CMD curl -I localhost:3000/health
76128

77-
CMD hypnotoad -f ./script/renderer
129+
CMD ["hypnotoad", "-f", "./script/renderer"]

0 commit comments

Comments
 (0)