forked from Rongronggg9/RSS-to-Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
165 lines (135 loc) · 5.44 KB
/
Dockerfile
File metadata and controls
165 lines (135 loc) · 5.44 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# RSS to Telegram Bot
# Copyright (C) 2020-2025 Rongrong <i@rong.moe>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM python:3.13-bookworm AS dep-builder-common
ENV PATH="/opt/venv/bin:$PATH"
RUN \
set -ex && \
python -m venv --copies /opt/venv && \
python -m pip install --no-cache-dir --upgrade \
pip setuptools wheel
COPY requirements.txt .
RUN \
set -ex && \
export MAKEFLAGS="-j$((`nproc`+1))" && \
pip install --no-cache-dir \
-r requirements.txt \
&& \
rm -rf /opt/venv/src
#-----------------------------------------------------------------------------------------------------------------------
FROM python:3.13-bookworm AS dep-builder
ENV PATH="/opt/venv/bin:$PATH"
ARG EXP_REGEX='^([^~=<>]+)[^#]*#\s*(\1@.+)$'
COPY requirements.txt .
RUN \
set -ex && \
pip wheel --no-cache-dir --no-deps \
$(sed -nE "s/$EXP_REGEX/\2/p" requirements.txt)
COPY --from=dep-builder-common /opt/venv /opt/venv
ARG EXP_DEPS=0
RUN \
set -ex && \
if [ "$EXP_DEPS" = 1 ]; then \
AFFECTED_PKGS=$(sed -nE "s/$EXP_REGEX/\1/p" requirements.txt); \
pip uninstall -y $AFFECTED_PKGS && \
for pkg in $AFFECTED_PKGS; do \
sed -Ei "s#$pkg.*#$(find . -iname "${pkg}-*.whl")#" requirements.txt; \
done; \
pip install --no-cache-dir \
-r requirements.txt \
; \
fi;
#-----------------------------------------------------------------------------------------------------------------------
FROM buildpack-deps:bookworm AS mimalloc-builder
WORKDIR /mimalloc
RUN \
set -ex && \
apt-get update && \
apt-get install -yq --no-install-recommends \
cmake \
&& \
curl -sL https://github.com/microsoft/mimalloc/archive/refs/tags/v2.0.9.tar.gz | tar -zxf - --strip-components=1 && \
mkdir -p build/lib && \
cd build && \
cmake .. && \
make mimalloc -j$((`nproc`+1)) && \
ln libmimalloc.so* lib/ && \
apt-get purge -yq --auto-remove \
cmake \
&& \
rm -rf /var/lib/apt/lists/*
#-----------------------------------------------------------------------------------------------------------------------
FROM python:3.13-bookworm AS app-builder
WORKDIR /app
COPY . /app
# inject railway env vars
ARG RAILWAY_GIT_COMMIT_SHA
ARG RAILWAY_GIT_BRANCH
RUN \
set -ex && \
echo "$(expr substr "$RAILWAY_GIT_COMMIT_SHA" 1 7)@$RAILWAY_GIT_BRANCH" | tee .version && \
if test $(expr length "$(cat .version)") -le 3; then \
echo "$(git describe --tags --always)@$(git branch --show-current)" | tee .version ; \
fi && \
if test $(expr length "$(cat .version)") -le 3; then \
echo "dirty-build@$(date -Iseconds)" | tee .version; else echo "build@$(date -Iseconds)" | tee -a .version; \
fi && \
mkdir /app-minimal && \
cp -aL .version LICENSE src telegramRSSbot.py scripts/health_check.py /app-minimal && \
cd / && \
rm -rf /app && \
rm -f /app-minimal/*.md && \
ls -la /app-minimal && \
du -hd1 /app-minimal && \
cat /app-minimal/.version
#-----------------------------------------------------------------------------------------------------------------------
FROM python:3.13-slim-bookworm AS app
WORKDIR /app
RUN \
set -ex && \
apt-get update && \
apt-get install -yq --no-install-recommends \
fonts-wqy-microhei libjemalloc2 \
&& \
rm -rf /var/lib/apt/lists/*
# PORT: default port for health check, can be safely overridden.
# Note: We don't expose this port in the Dockerfile. If users want to expose
# this port, they should do so in their docker-compose.yml or docker run
# command.
# PYTHONMALLOC: enable pymalloc together with jemalloc, see also
# https://lirias.kuleuven.be/retrieve/695404
# https://dl.acm.org/doi/abs/10.1007/978-3-031-15074-6_14
# Note: Do not compare pymalloc_jemalloc to the baseline (i.e., pymalloc),
# compare pymalloc_jemalloc to jemalloc (i.e., jemalloc+malloc) instead.
# LD_PRELOAD: enable jemalloc to prevent memory fragmentation issues.
# MALLOC_CONF: jemalloc tuning, see also
# https://github.com/home-assistant/core/pull/70899
# https://github.com/jemalloc/jemalloc/blob/5.2.1/TUNING.md
ENV \
PORT=8848 \
PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
RAPIDFUZZ_IMPLEMENTATION=cpp \
PYTHONMALLOC=pymalloc \
LD_PRELOAD=libjemalloc.so.2 \
MALLOC_CONF=background_thread:true,max_background_threads:1,metadata_thp:auto,dirty_decay_ms:80000,muzzy_decay_ms:80000
COPY --from=mimalloc-builder /mimalloc/build/lib /usr/local/lib
COPY --from=dep-builder /opt/venv /opt/venv
COPY --from=app-builder /app-minimal /app
# verify cryptg installation
RUN python -c 'import logging; logging.basicConfig(level=logging.DEBUG); import telethon; import cryptg'
HEALTHCHECK --start-period=1m \
CMD ["python", "-u", "health_check.py"]
ENTRYPOINT ["python", "-u", "telegramRSSbot.py"]