diff --git a/Dockerfile b/Dockerfile index c520706..a517a76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,20 @@ # Pull from small Debian stable image. FROM alpine:latest LABEL maintainer="dselen@nerthus.nl" -ENV PYTHONPATH="/usr/bin/python" +ENV PYTHONPATH="/usr/lib/python3.12/site-packages" WORKDIR /opt/wireguarddashboard/src RUN apk update && \ - apk add --no-cache py3-bcrypt py3-psutil && \ + apk add --no-cache sudo gcc musl-dev linux-headers && \ apk add --no-cache wireguard-tools && \ - apk add --no-cache net-tools iproute2 iptables ip6tables && \ - apk add --no-cache inotify-tools procps openresolv && \ + apk add --no-cache iptables ip6tables && \ mkdir /opt/wireguarddashboard/src/master-key + COPY ./src /opt/wireguarddashboard/src/ -COPY ./docker/wgd.sh /opt/wireguarddashboard/src/ -COPY ./docker/requirements.txt /opt/wireguarddashboard/src/ +COPY ./docker/alpine/entrypoint.sh /opt/wireguarddashboard/src/ +#COPY ./docker/alpine/wgd.sh /opt/wireguarddashboard/src/ +#COPY ./docker/alpine/requirements.txt /opt/wireguarddashboard/src/ RUN chmod u+x /opt/wireguarddashboard/src/entrypoint.sh diff --git a/compose.yaml b/compose.yaml index a75ef45..b729110 100644 --- a/compose.yaml +++ b/compose.yaml @@ -10,9 +10,9 @@ services: environment: - wg_net=10.0.0.1/24 - wg_port=51820 - volumes: - - wgd_configs:/etc/wireguard - - wgd_app:/opt/wireguarddashboard/src + #volumes: + #- wgd_configs:/etc/wireguard + #- wgd_app:/opt/wireguarddashboard/src ports: - 10086:10086/tcp - 51820:51820/udp @@ -21,6 +21,6 @@ services: - net.ipv4.conf.all.src_valid_mark=1 -volumes: - wgd_configs: - wgd_app: \ No newline at end of file +#volumes: + #wgd_configs: + #wgd_app: \ No newline at end of file diff --git a/docker/alpine/entrypoint.sh b/docker/alpine/entrypoint.sh new file mode 100644 index 0000000..6c79033 --- /dev/null +++ b/docker/alpine/entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/bash +echo "Starting the WireGuard Dashboard Docker container." + +clean_up() { + # Cleaning out previous data such as the .pid file and starting the WireGuard Dashboard. Making sure to use the python venv. + echo "Looking for remains of previous instances..." + if [ -f "/opt/wireguarddashboard/app/src/gunicorn.pid" ]; then + echo "Found old .pid file, removing." + rm /opt/wireguarddashboard/app/src/gunicorn.pid + else + echo "No remains found, continuing." + fi +} + + + +ensure_blocking() { + sleep 1s + echo "Ensuring container continuation." + + # This function checks if the latest error log is created and tails it for docker logs uses. + if find "/opt/wireguarddashboard/src/log" -mindepth 1 -maxdepth 1 -type f | read -r; then + latestErrLog=$(find /opt/wireguarddashboard/src/log -name "error_*.log" | head -n 1) + latestAccLog=$(find /opt/wireguarddashboard/src/log -name "access_*.log" | head -n 1) + tail -f "${latestErrLog}" "${latestAccLog}" + fi + + # Blocking command in case of erroring. So the container does not quit. + sleep infinity +} + +# Execute functions for the WireGuard Dashboard services, then set the environment variables +clean_up + +chmod u+x /opt/wireguarddashboard/src/wgd.sh +if [ ! -f "/opt/wireguarddashboard/src/wg-dashboard.ini" ]; then + /opt/wireguarddashboard/src/wgd.sh install + +fi +/opt/wireguarddashboard/src/wgd.sh start +ensure_blocking diff --git a/docker/requirements.txt b/docker/alpine/requirements.txt similarity index 100% rename from docker/requirements.txt rename to docker/alpine/requirements.txt diff --git a/docker/alpine/wgd.sh b/docker/alpine/wgd.sh new file mode 100644 index 0000000..e13aa9b --- /dev/null +++ b/docker/alpine/wgd.sh @@ -0,0 +1,438 @@ +#!/bin/bash + +# wgd.sh - Copyright(C) 2024 Donald Zou [https://github.com/donaldzou] +# Under Apache-2.0 License +#trap "kill $TOP_PID" +export TOP_PID=$$ + +app_name="dashboard.py" +app_official_name="WGDashboard" +venv_python="./venv/bin/python3" +venv_gunicorn="./venv/bin/gunicorn" +pythonExecutable="python3" + +heavy_checkmark=$(printf "\xE2\x9C\x94") +heavy_crossmark=$(printf "\xE2\x9C\x97") + +PID_FILE=./gunicorn.pid +environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi) +if [[ $CONFIGURATION_PATH ]]; then + cb_work_dir=$CONFIGURATION_PATH/letsencrypt/work-dir + cb_config_dir=$CONFIGURATION_PATH/letsencrypt/config-dir +else + cb_work_dir=/etc/letsencrypt + cb_config_dir=/var/lib/letsencrypt +fi + +dashes='------------------------------------------------------------' +equals='============================================================' +helpMsg="[WGDashboard] Please check ./log/install.txt for more details. For further assistance, please open a ticket on https://github.com/donaldzou/WGDashboard/issues/new/choose, I'm more than happy to help :)" +help () { + printf "=================================================================================\n" + printf "+ by Donald Zou - https://github.com/donaldzou +\n" + printf "=================================================================================\n" + printf "| Usage: ./wgd.sh