forked from Rongronggg9/RSS-to-Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
133 lines (106 loc) · 3.92 KB
/
Dockerfile
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
FROM python:3.11-bullseye AS dep-builder-common
ENV PATH="/opt/venv/bin:$PATH"
RUN \
set -ex && \
python -m venv --copies /opt/venv && \
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.11-bullseye 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:bullseye AS mimalloc-builder
RUN \
set -ex && \
apt-get update && \
apt-get install -yq --no-install-recommends \
cmake \
&& \
git clone --depth=1 https://github.com/microsoft/mimalloc.git && \
mkdir -p /mimalloc/build/lib && \
cd /mimalloc/build && \
cmake /mimalloc && \
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.11-bullseye 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 -r .version LICENSE src telegramRSSbot.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.11-slim-bullseye 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/*
ENV \
PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
RAPIDFUZZ_IMPLEMENTATION=cpp \
PYTHONMALLOC=malloc \
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
# jemalloc tuning, Ref:
# https://github.com/home-assistant/core/pull/70899
# https://github.com/jemalloc/jemalloc/blob/5.2.1/TUNING.md
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'
ENTRYPOINT ["python", "-u", "telegramRSSbot.py"]