forked from DivinumOfficium/divinum-officium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
101 lines (85 loc) · 3.49 KB
/
Copy pathDockerfile
File metadata and controls
101 lines (85 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# --- STAGE 1: Build Info ---
FROM public.ecr.aws/docker/library/alpine:latest AS gitinfo
RUN apk add git
COPY .git /build/
WORKDIR /build
RUN echo "{" > /build/buildinfo && \
echo " \"build-date\": \"$(date +%s)\", " >> /build/buildinfo && \
echo " \"build-date-human\": \"$(date)\", " >> /build/buildinfo && \
echo " \"commit\": \"$(git rev-parse HEAD)\", " >> /build/buildinfo && \
echo " \"branch\": \"$(git rev-parse --abbrev-ref HEAD)\"" >> /build/buildinfo && \
echo "}" >> /build/buildinfo
# --- STAGE 2: Final Container ---
FROM perl:5.40-slim AS final
LABEL maintainer="Thomas Randall <thomas.james.randall@gmail.com>"
# 1. System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libperl-dev \
libssl-dev \
zlib1g-dev \
libcgi-pm-perl \
libcgi-session-perl \
libhttp-message-perl \
liburi-perl \
libwww-perl \
libplack-perl \
perl-modules \
wget \
cron \
python3 \
&& rm -rf /var/lib/apt/lists/*
# 2. Plack Stack — pin Plack to 1.0050 which reverts the breaking return_405 change
RUN cpanm --notest \
MIYAGAWA/Plack-1.0050.tar.gz \
Starman \
Plack::App::CGIBin \
CGI::Compile \
CGI::Emulate::PSGI \
CGI::Session
# 3. Process management — detect arch so this works on both x86_64 and ARM
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "x86_64" ]; then \
DUMB_INIT_ARCH="x86_64"; \
elif [ "$ARCH" = "aarch64" ]; then \
DUMB_INIT_ARCH="aarch64"; \
else \
echo "Unsupported architecture: $ARCH" && exit 1; \
fi && \
wget -O /usr/local/bin/dumb-init \
"https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_${DUMB_INIT_ARCH}" && \
chmod +x /usr/local/bin/dumb-init
WORKDIR /var/www
# 4. Copy code and set permissions
COPY web /var/www/web
COPY lexicon-tools /var/www/lexicon-tools
COPY app.psgi /var/www/app.psgi
COPY warm-ordo-cache.sh /usr/local/bin/warm-ordo-cache.sh
COPY --from=gitinfo /build/buildinfo /var/www/web/buildinfo
RUN perl /var/www/lexicon-tools/build_lexicon_storable.pl
RUN find /var/www/web -type d -exec chmod 755 {} + && \
find /var/www/web -type f -exec chmod 644 {} + && \
find /var/www/web/cgi-bin -type f -name "*.pl" -exec chmod +x {} + && \
chmod +x /usr/local/bin/warm-ordo-cache.sh && \
mkdir -p /var/www/web/ordo-cache && \
chown -R www-data:www-data /var/www
# 5. Internalize URLs
RUN grep -rl 'divinumofficium.com' /var/www/web | xargs sed -i 's|https\?://divinumofficium\.com/|/|g'
# 6. Set up nightly cron job to warm the ordo cache at 2:00 AM UTC
# Runs as www-data, logs to /var/log/ordo-cache-warm.log
RUN echo "0 2 * * * www-data BASE_URL=http://localhost:8080 /usr/local/bin/warm-ordo-cache.sh >> /var/log/ordo-cache-warm.log 2>&1" \
> /etc/cron.d/ordo-cache && \
chmod 644 /etc/cron.d/ordo-cache
# 7. Clear any debug environment that might have leaked in
ENV PERL5OPT=""
ENV PERL5DB=""
ENV PERLDB_OPTS=""
USER root
ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
# Start cron, then warm the ordo cache in the background after a 15 second
# delay to allow Starman to fully start before requests are made.
# Cache will be ready within ~75 seconds of container startup.
CMD ["/bin/bash", "-c", \
"cron && \
(sleep 15 && BASE_URL=http://localhost:8080 /usr/local/bin/warm-ordo-cache.sh >> /var/log/ordo-cache-warm.log 2>&1) & \
starman --port 8080 --host 0.0.0.0 --workers 20 --preload-app --user www-data --group www-data /var/www/app.psgi"]