-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
104 lines (88 loc) · 2.6 KB
/
Dockerfile
File metadata and controls
104 lines (88 loc) · 2.6 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
102
103
104
FROM nikolaik/python-nodejs:python3.13-nodejs24 AS build
ADD . /app
WORKDIR /app
RUN uv sync && npm install
RUN rm -rf public/dist && uv run hyperflask build
RUN mkdir -p _site
RUN uv export --frozen --no-hashes > requirements.txt
FROM python:3.13-slim
ARG EXPOSED_PORT=8080
ENV LITESTREAM_TYPE=s3
ENV LITESTREAM_PATH=app.db
RUN apt update && apt install -y git curl
ADD . /app
WORKDIR /app
COPY --from=build /app/app/assets.json /app/app/assets.json
COPY --from=build /app/public /app/public
COPY --from=build /app/_site /app/_site
COPY --from=caddy:latest /usr/bin/caddy /usr/bin/caddy
COPY --from=litestream/litestream:latest /usr/local/bin/litestream /usr/local/bin/litestream
RUN mkdir -p database uploads
RUN cat >/app/Caddyfile <<EOT
{
auto_https off
admin off
grace_period 5s
servers {
trusted_proxies static private_ranges
trusted_proxies_strict
client_ip_headers X-Real-IP Fly-Client-IP X-Forwarded-For
}
}
:${EXPOSED_PORT} {
root * /app/_site
handle_path /static/* {
file_server {
root /app/public
}
}
handle /.well-known/mercure {
reverse_proxy localhost:5300
}
handle {
file_server {
pass_thru
}
reverse_proxy localhost:5000
}
}
EOT
RUN cat >/app/Procfile <<EOT
caddy: caddy run --config /app/Caddyfile
EOT
RUN --mount=type=bind,from=build,source=/app/requirements.txt,target=/tmp/requirements.txt \
pip install -r /tmp/requirements.txt
RUN cat >/app/entrypoint.sh <<EOT
#!/bin/sh
set -e
if [ -z "\${LITESTREAM_BUCKET}" ] && [ ! -f /etc/litestream.yml ]; then
hyperflask "\$@"
else
if [ ! -f /etc/litestream.yml ] && [ -f /app/litestream.yml ]; then
cp /app/litestream.yml /etc/litestream.yml
elif [ ! -f /etc/litestream.yml ]; then
cat >/etc/litestream.yml <<EOF
dbs:
- path: /app/database/app.db
replica:
type: \${LITESTREAM_TYPE}
path: \${LITESTREAM_PATH}
bucket: \${LITESTREAM_BUCKET}
EOF
if [ -n "\${LITESTREAM_ENDPOINT}" ]; then
echo " endpoint: \${LITESTREAM_ENDPOINT}" >> /etc/litestream.yml
fi
if [ -n "\${LITESTREAM_REGION}" ]; then
echo " region: \${LITESTREAM_REGION}" >> /etc/litestream.yml
fi
fi
litestream replicate -exec "hyperflask \$*"
fi
EOT
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["run", "--extend-procfile", "--init-db"]
VOLUME ["/app/database", "/app/uploads", "/etc/litestream.yml"]
EXPOSE ${EXPOSED_PORT}
HEALTHCHECK --interval=5m --start-period=5s \
CMD curl -f http://localhost/healthcheck || exit 1