Created
October 14, 2025 01:58
-
-
Save iakat/bdd7231a125a30927e033589d023a64b to your computer and use it in GitHub Desktop.
rclone-serve-wireguard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM debian:trixie-slim | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| wireguard-tools \ | |
| rclone \ | |
| iproute2 \ | |
| && rm -rf /var/lib/apt/lists/* \ | |
| && mkdir -p /etc/wireguard /data | |
| RUN cat > /entrypoint.sh << 'EOF' | |
| #!/bin/bash | |
| set -e | |
| WG_IFACE="wg0" | |
| cleanup() { | |
| echo "[INFO] Shutting down..." | |
| killall rclone 2>/dev/null || true | |
| wg-quick down "${WG_IFACE}" 2>/dev/null || true | |
| exit 0 | |
| } | |
| trap cleanup SIGTERM SIGINT | |
| # Generate WireGuard keys if needed | |
| if [ ! -f /etc/wireguard/privatekey ]; then | |
| wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey | |
| chmod 600 /etc/wireguard/privatekey | |
| wg genpsk > /etc/wireguard/psk | |
| chmod 600 /etc/wireguard/psk | |
| echo "[INFO] Generated WireGuard keys. Public key: $(cat /etc/wireguard/publickey)" | |
| fi | |
| # Generate WebDAV password if needed | |
| if [ ! -f /etc/wireguard/webdav-password ]; then | |
| tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 32 > /etc/wireguard/webdav-password | |
| chmod 600 /etc/wireguard/webdav-password | |
| echo "[INFO] Generated WebDAV password: $(cat /etc/wireguard/webdav-password)" | |
| fi | |
| WG_CLIENT_PUBKEY="${WG_CLIENT_PUBKEY:-CHANGEME}" | |
| WG_IP="${WG_IP:-100.87.143.201}" | |
| WG_CLIENT_IP="${WG_CLIENT_IP:-100.87.143.1}" | |
| cat > "/etc/wireguard/${WG_IFACE}.conf" << WGEOF | |
| [Interface] | |
| PrivateKey = $(cat /etc/wireguard/privatekey) | |
| Address = ${WG_IP}/32 | |
| ListenPort = 51820 | |
| [Peer] | |
| PublicKey = ${WG_CLIENT_PUBKEY} | |
| PresharedKey = $(cat /etc/wireguard/psk) | |
| AllowedIPs = ${WG_CLIENT_IP}/32 | |
| WGEOF | |
| chmod 600 "/etc/wireguard/${WG_IFACE}.conf" | |
| wg-quick up "${WG_IFACE}" | |
| echo "[INFO] WireGuard up: ${WG_IP}" | |
| WEBDAV_PASSWORD=$(cat /etc/wireguard/webdav-password) | |
| echo "[INFO] WebDAV server: http://${WG_IP}:8080" | |
| echo "[INFO] Username: root | Password: ${WEBDAV_PASSWORD}" | |
| exec rclone serve webdav /data \ | |
| --addr ${WG_IP}:8080 \ | |
| --user root \ | |
| --pass "${WEBDAV_PASSWORD}" \ | |
| --read-only \ | |
| ${RCLONE_ARGS} | |
| EOF | |
| RUN chmod +x /entrypoint.sh | |
| VOLUME /data /etc/wireguard | |
| EXPOSE 51820/udp | |
| CMD ["/entrypoint.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment