From 06193d27c0cd86f2e2531cf9d3507866068b8649 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 4 Jun 2024 17:05:17 +0200 Subject: [PATCH] Added dockerfile and entrypoint for basic compilation, moving to finalizing --- docker/Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 19 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..d6d4fc3 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,43 @@ +# Pull from small Debian stable image. +FROM debian:stable-slim +LABEL maintainer="dselen@nerthus.nl" + +# Copy the basic entrypoint.sh script. +COPY entrypoint.sh /entrypoint.sh + +# Declaring environment variables +ENV tz=Europe/Amsterdam +ENV WGPEERNET=10.0.0.1 + +# Doing basic system maintenance. Change the timezone to the desired timezone. +RUN ln -sf /usr/share/zoneinfo/${tz} /etc/localtime \ + && apt-get update \ + && apt-get upgrade -y \ + && apt-get purge linux-image* -y \ + && apt-get autoremove -y +# Removing the linux-image package to preserve space on the container. + +# Installing needed packages for installation. +RUN apt-get install -y --no-install-recommends git wireguard wireguard-tools python3 python3-pip python3-venv iproute2 openresolv procps + +ENV WGDASH=/opt/wireguardashboard +RUN python3 -m venv ${WGDASH}/venv + +# Doing WireGuard Dashboard installation measures. +RUN . ${WGDASH}/venv/bin/activate \ + && git clone -b v3.0.6.2 https://github.com/donaldzou/WGDashboard.git ${WGDASH}/app \ + && pip3 install -r ${WGDASH}/app/src/requirements.txt \ + && chmod +x ${WGDASH}/app/src/wgd.sh \ + && .${WGDASH}/app/src/wgd.sh install + +# Set the volume to be used for persistency. +VOLUME /etc/wireguard + +# Generate basic WireGuard interface. Change Peernet to CIDR you would like. +RUN wg genkey | tee /etc/wireguard/wg0_privatekey \ + && echo "[Interface]\nSaveConfig = true\nAddress = ${WGPEERNET}/24\nPrivateKey = $(cat /etc/wireguard/wg0_privatekey)\nListenPort = 51820\nDNS = 8.8.8.8" > /etc/wireguard/wg0.conf \ + && rm /etc/wireguard/wg0_privatekey + +# Exposing the default WireGuard Dashboard port for web access. +EXPOSE 10086 +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..ed61833 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,19 @@ +echo "Starting the WireGuard Dashboard." + +outgoing=$(ip -o -4 route show to default | awk '{print $NF}') +echo $outgoing + +. ${WGDASH}/venv/bin/activate +cd /opt/wireguardashboard/app/src +bash ./wgd.sh start + +if [ "$tz" != "Europe/Amsterdam" ]; then + echo "Changing timezone..." + ln -sf /usr/share/zoneinfo/$tz /etc/localtime +fi + +sleep 3s +tail -f /opt/wireguardashboard/app/src/log/*.log + +# Blocking command in case of erroring. +sleep infinity \ No newline at end of file