1- # Builder
2- FROM alpine AS nodpi-builder
1+ FROM python:3.11-slim
32
43WORKDIR /app
54
6- # Download latest release source code
7- RUN apk add --no-cache git && \
8- git clone https://github.com/GVCoder09/NoDPI . && \
9- mv src/main.py src/nodpi && \
10- rm -rf .git
5+ COPY src/ ./src/
116
12- # Preparing run script
13- RUN echo '#!/bin/sh' > ./entrypoint.sh && \
14- echo >> ./entrypoint.sh && \
15- echo '# For Docker HEALTHCHECK' >> ./entrypoint.sh && \
16- echo 'if [ "$1" = "healthcheck" ]; then' >> ./entrypoint.sh && \
17- echo ' port=$(netstat -l | egrep -o ":[0-9]{1,}")' >> ./entrypoint.sh && \
18- echo >> ./entrypoint.sh && \
19- echo ' check_url="https://youtube.com"' >> ./entrypoint.sh && \
20- echo ' [ -n "$2" ] && check_url="$2"' >> ./entrypoint.sh && \
21- echo ' nodpi_proxy="http://127.0.0.1$port"' >> ./entrypoint.sh && \
22- echo >> ./entrypoint.sh && \
23- echo ' https_proxy="$nodpi_proxy" curl -s "$check_url"' >> ./entrypoint.sh && \
24- echo >> ./entrypoint.sh && \
25- echo ' exit $?' >> ./entrypoint.sh && \
26- echo 'fi' >> ./entrypoint.sh && \
27- echo >> ./entrypoint.sh && \
28- echo 'workdir="/app"' >> ./entrypoint.sh && \
29- echo 'blacklist_file="$workdir/blacklist.txt"' >> ./entrypoint.sh && \
30- echo 'nodpi="$workdir/src/nodpi"' >> ./entrypoint.sh && \
31- echo 'blacklists_dir="/blacklists"' >> ./entrypoint.sh && \
32- echo 'tmp_file="/tmp/blacklist.txt"' >> ./entrypoint.sh && \
33- echo >> ./entrypoint.sh && \
34- echo 'if [ -d "$blacklists_dir" ]; then' >> ./entrypoint.sh && \
35- echo ' cat "$blacklists_dir"/* > "$tmp_file" 2>/dev/null' >> ./entrypoint.sh && \
36- echo ' if [ -f "$tmp_file" ] && [ -s "$tmp_file" ]; then' >> ./entrypoint.sh && \
37- echo ' blacklist_file="$tmp_file"' >> ./entrypoint.sh && \
38- echo ' fi' >> ./entrypoint.sh && \
39- echo 'fi' >> ./entrypoint.sh && \
40- echo >> ./entrypoint.sh && \
41- echo 'BLACKLIST="--blacklist $blacklist_file"' >> ./entrypoint.sh && \
42- echo 'HOST="--host 0.0.0.0"' >> ./entrypoint.sh && \
43- echo 'for arg in $*; do' >> ./entrypoint.sh && \
44- echo ' [ "$arg" = ' --blacklist' ] && BLACKLIST=""' >> ./entrypoint.sh && \
45- echo ' [ "$arg" = ' --no_blacklist' ] && BLACKLIST=""' >> ./entrypoint.sh && \
46- echo ' [ "$arg" = ' --host' ] && HOST=""' >> ./entrypoint.sh && \
47- echo 'done' >> ./entrypoint.sh && \
48- echo >> ./entrypoint.sh && \
49- echo 'python3 "$nodpi" "$@" $HOST $BLACKLIST' >> ./entrypoint.sh && \
50- echo >> ./entrypoint.sh && \
51- chmod +x ./entrypoint.sh
7+ RUN groupadd -r nodpi && useradd -r -g nodpi nodpi
528
53- # App runner
54- FROM python:3-alpine AS app
55-
56- RUN apk add --no-cache curl && \
57- adduser -u 1000 -D -h /app -s /sbin/nologin nodpi
58-
59- COPY --from=nodpi-builder /app /app
60-
61- VOLUME [/blacklists]
9+ RUN mkdir -p /tmp/nodpi && chown -R nodpi:nodpi /tmp/nodpi
6210
6311USER nodpi
6412
65- HEALTHCHECK \
66- --interval=5s \
67- --timeout=3s \
68- --retries=2 \
69- CMD /app/entrypoint.sh healthcheck https://youtube.com
70-
71- EXPOSE 8881
72-
73- ENTRYPOINT ["/app/entrypoint.sh" ]
13+ ENTRYPOINT ["python" , "src/main.py" ]
0 commit comments