Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 57 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
# Builder
FROM alpine AS builder
FROM alpine AS nodpi-builder

WORKDIR /app

# Download latest release source code
RUN apk add --no-cache curl jq && \
curl -sSL "$(curl -sSL 'https://api.github.com/repos/GVCoder09/NoDPI/releases/latest' | jq -r '.tarball_url')" -o /tmp/nodpi.tar && \
tar --strip-components=1 -xf /tmp/nodpi.tar
RUN apk add --no-cache git && \
git clone https://github.com/GVCoder09/NoDPI . && \
mv src/main.py src/nodpi && \
rm -rf .git

# Preparing run script
RUN echo '#!/bin/sh' > ./nodpi && \
echo 'script_path="$(cd "$(dirname "$0")" && pwd)"' >> ./nodpi && \
echo 'blacklist_file="$script_path/blacklist.txt"' >> ./nodpi && \
echo 'blacklists_dir="/blacklists"' >> ./nodpi && \
echo 'tmp_file="/tmp/blacklist.txt"' >> ./nodpi && \
echo 'if [ -d "$blacklists_dir" ]; then' >> ./nodpi && \
echo ' cat "$blacklists_dir"/* > "$tmp_file" 2>/dev/null' >> ./nodpi && \
echo ' if [ -f "$tmp_file" ] && [ -s "$tmp_file" ]; then' >> ./nodpi && \
echo ' blacklist_file="$tmp_file"' >> ./nodpi && \
echo ' fi' >> ./nodpi && \
echo 'fi' >> ./nodpi && \
echo 'python3 "$script_path/src/main.py" --host 0.0.0.0 --blacklist "$blacklist_file" "$@"' >> ./nodpi
RUN chmod +x ./nodpi
RUN echo '#!/bin/sh' > ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo '# For Docker HEALTHCHECK' >> ./entrypoint.sh && \
echo 'if [ "$1" = "healthcheck" ]; then' >> ./entrypoint.sh && \
echo ' port=$(netstat -l | egrep -o ":[0-9]{1,}")' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo ' check_url="https://youtube.com"' >> ./entrypoint.sh && \
echo ' [ -n "$2" ] && check_url="$2"' >> ./entrypoint.sh && \
echo ' nodpi_proxy="http://127.0.0.1$port"' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo ' https_proxy="$nodpi_proxy" curl -s "$check_url"' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo ' exit $?' >> ./entrypoint.sh && \
echo 'fi' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo 'workdir="/app"' >> ./entrypoint.sh && \
echo 'blacklist_file="$workdir/blacklist.txt"' >> ./entrypoint.sh && \
echo 'nodpi="$workdir/src/nodpi"' >> ./entrypoint.sh && \
echo 'blacklists_dir="/blacklists"' >> ./entrypoint.sh && \
echo 'tmp_file="/tmp/blacklist.txt"' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo 'if [ -d "$blacklists_dir" ]; then' >> ./entrypoint.sh && \
echo ' cat "$blacklists_dir"/* > "$tmp_file" 2>/dev/null' >> ./entrypoint.sh && \
echo ' if [ -f "$tmp_file" ] && [ -s "$tmp_file" ]; then' >> ./entrypoint.sh && \
echo ' blacklist_file="$tmp_file"' >> ./entrypoint.sh && \
echo ' fi' >> ./entrypoint.sh && \
echo 'fi' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo 'BLACKLIST="--blacklist $blacklist_file"' >> ./entrypoint.sh && \
echo 'HOST="--host 0.0.0.0"' >> ./entrypoint.sh && \
echo 'for arg in $*; do' >> ./entrypoint.sh && \
echo ' [ "$arg" = '--blacklist' ] && BLACKLIST=""' >> ./entrypoint.sh && \
echo ' [ "$arg" = '--no_blacklist' ] && BLACKLIST=""' >> ./entrypoint.sh && \
echo ' [ "$arg" = '--host' ] && HOST=""' >> ./entrypoint.sh && \
echo 'done' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
echo 'python3 "$nodpi" "$@" $HOST $BLACKLIST' >> ./entrypoint.sh && \
echo >> ./entrypoint.sh && \
chmod +x ./entrypoint.sh

# App runner
FROM python:alpine AS app
FROM python:3-alpine AS app

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

RUN adduser -u 1000 -D -h /app -s /sbin/nologin nodpi
COPY --from=nodpi-builder /app /app

VOLUME [/blacklists]

USER nodpi

EXPOSE 8881
HEALTHCHECK \
--interval=5s \
--timeout=3s \
--retries=2 \
CMD /app/entrypoint.sh healthcheck https://youtube.com

ENTRYPOINT ["/app/nodpi"]
EXPOSE 8881

ENTRYPOINT ["/app/entrypoint.sh"]