Skip to content

Commit 008bad9

Browse files
authored
Merge pull request #38 from mukhumaev/main
Improved Dockerfile
2 parents 69fb91c + f2cd51f commit 008bad9

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

Dockerfile

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,73 @@
11
# Builder
2-
FROM alpine AS builder
2+
FROM alpine AS nodpi-builder
33

44
WORKDIR /app
55

66
# Download latest release source code
7-
RUN apk add --no-cache curl jq && \
8-
curl -sSL "$(curl -sSL 'https://api.github.com/repos/GVCoder09/NoDPI/releases/latest' | jq -r '.tarball_url')" -o /tmp/nodpi.tar && \
9-
tar --strip-components=1 -xf /tmp/nodpi.tar
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
1011

1112
# Preparing run script
12-
RUN echo '#!/bin/sh' > ./nodpi && \
13-
echo 'script_path="$(cd "$(dirname "$0")" && pwd)"' >> ./nodpi && \
14-
echo 'blacklist_file="$script_path/blacklist.txt"' >> ./nodpi && \
15-
echo 'blacklists_dir="/blacklists"' >> ./nodpi && \
16-
echo 'tmp_file="/tmp/blacklist.txt"' >> ./nodpi && \
17-
echo 'if [ -d "$blacklists_dir" ]; then' >> ./nodpi && \
18-
echo ' cat "$blacklists_dir"/* > "$tmp_file" 2>/dev/null' >> ./nodpi && \
19-
echo ' if [ -f "$tmp_file" ] && [ -s "$tmp_file" ]; then' >> ./nodpi && \
20-
echo ' blacklist_file="$tmp_file"' >> ./nodpi && \
21-
echo ' fi' >> ./nodpi && \
22-
echo 'fi' >> ./nodpi && \
23-
echo 'python3 "$script_path/src/main.py" --host 0.0.0.0 --blacklist "$blacklist_file" "$@"' >> ./nodpi
24-
RUN chmod +x ./nodpi
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
2552

2653
# App runner
27-
FROM python:alpine AS app
54+
FROM python:3-alpine AS app
2855

29-
COPY --from=builder /app /app
56+
RUN apk add --no-cache curl && \
57+
adduser -u 1000 -D -h /app -s /sbin/nologin nodpi
3058

31-
RUN adduser -u 1000 -D -h /app -s /sbin/nologin nodpi
59+
COPY --from=nodpi-builder /app /app
60+
61+
VOLUME [/blacklists]
3262

3363
USER nodpi
3464

35-
EXPOSE 8881
65+
HEALTHCHECK \
66+
--interval=5s \
67+
--timeout=3s \
68+
--retries=2 \
69+
CMD /app/entrypoint.sh healthcheck https://youtube.com
3670

37-
ENTRYPOINT ["/app/nodpi"]
71+
EXPOSE 8881
3872

73+
ENTRYPOINT ["/app/entrypoint.sh"]

0 commit comments

Comments
 (0)