FROM python:alpine RUN apk update RUN apk add --no-cache ffmpeg mimalloc2 nginx py3-pillow curl RUN mkdir -p /data /tmp/nginx-client-body /tmp/nginx-proxy /tmp/nginx-fastcgi /tmp/nginx-uwsgi /tmp/nginx-scgi ENV HOME=/root ENV LD_PRELOAD=/usr/lib/libmimalloc-secure.so.2 ENV PATH=/root/.local/bin:$PATH ENV PYTHONUNBUFFERED=1 WORKDIR $HOME/app RUN pip install --no-cache-dir copyparty RUN cat >/etc/nginx/nginx.conf.template <<'EOF' events {} http { include /etc/nginx/mime.types; default_type application/octet-stream; client_max_body_size 0; access_log /dev/stdout; error_log /dev/stderr warn; sendfile on; client_body_temp_path /tmp/nginx-client-body; proxy_temp_path /tmp/nginx-proxy; fastcgi_temp_path /tmp/nginx-fastcgi; uwsgi_temp_path /tmp/nginx-uwsgi; scgi_temp_path /tmp/nginx-scgi; map $http_upgrade $connection_upgrade { default upgrade; "" close; } map "$http_sec_fetch_mode:$http_sec_fetch_dest:$http_referer:$http_user_agent" $is_download_request { default 0; ~*aria2 1; ~*curl 1; ~*rclone 1; ~*wget 1; ~^::: 1; ~^navigate: 1; } map $uri $download_filename { default "download"; ~.*/([^/]+)$ $1; } map $uri $looks_like_direct_file { default 1; / 0; /favicon.ico 0; /robots.txt 0; ~/$ 0; ~^/\. 0; } server { listen 7860; server_name _; root /data; location / { set $redirect_file ""; if ($request_method = GET) { set $redirect_file A; } if ($args = "") { set $redirect_file ${redirect_file}B; } if ($looks_like_direct_file = 1) { set $redirect_file ${redirect_file}C; } if ($is_download_request = 1) { set $redirect_file ${redirect_file}D; } if ($redirect_file = ABCD) { add_header Content-Disposition "attachment; filename=\"$download_filename\"" always; return 302 __BASE_DOWNLOAD_URL__$request_uri?download=true; } proxy_buffering off; proxy_connect_timeout 60s; proxy_http_version 1.1; proxy_pass http://127.0.0.1:3923; proxy_read_timeout 60s; proxy_request_buffering off; proxy_send_timeout 60s; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port 443; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Real-IP $remote_addr; send_timeout 300s; } } } EOF RUN cat >/start.sh <<'EOF' #!/bin/sh set -eu if [ -z "${ADMIN_PASSWORD:-}" ]; then echo "ERROR: ADMIN_PASSWORD is not found." exit 1 fi if [ -z "${BASE_DOWNLOAD_URL:-}" ]; then echo "ERROR: BASE_DOWNLOAD_URL is not found." exit 1 fi BASE_DOWNLOAD_URL="${BASE_DOWNLOAD_URL%/}" sed "s|__BASE_DOWNLOAD_URL__|$BASE_DOWNLOAD_URL|g" /etc/nginx/nginx.conf.template >/etc/nginx/nginx.conf cat > /root/app/copyparty.conf </dev/null || true' TERM INT while kill -0 $COPYPARTY_PID 2>/dev/null && kill -0 $NGINX_PID 2>/dev/null; do sleep 2 done kill $COPYPARTY_PID $NGINX_PID 2>/dev/null || true wait EOF RUN chmod +x /start.sh EXPOSE 7860 CMD ["/start.sh"]