Files
WGDashboard/docker/Dockerfile

145 lines
3.9 KiB
Docker
Raw Normal View History

2025-09-10 20:52:47 +02:00
#
# AWG GOLANG BUILDING STAGE
2025-09-14 17:15:41 +02:00
# Base: Alpine
2025-09-10 20:52:47 +02:00
#
# Pull the current golang-alpine image.
2025-09-14 17:15:41 +02:00
FROM golang:1.25-alpine AS awg-go
# Install build-dependencies.
2025-09-14 17:15:41 +02:00
RUN apk add --no-cache \
git \
gcc \
musl-dev
2024-12-12 11:03:39 +01:00
2025-09-10 20:52:47 +02:00
# Standard working directory for WGDashboard
RUN mkdir -p /workspace && \
git clone https://github.com/WGDashboard/amneziawg-go /workspace/awg
# Enable CGO compilation for AmneziaWG
2025-09-14 17:15:41 +02:00
ENV CGO_ENABLED=1
# Change directory
2025-09-10 20:52:47 +02:00
WORKDIR /workspace/awg
# Compile the binaries
2025-05-01 16:15:55 +02:00
RUN go mod download && \
go mod verify && \
go build -ldflags '-linkmode external -extldflags "-fno-PIC -static"' -v -o /usr/bin
2025-09-10 20:52:47 +02:00
#
# AWG TOOLS BUILDING STAGE
# Base: Debian
#
2025-09-14 17:15:41 +02:00
FROM alpine:latest AS awg-tools
# Install needed dependencies.
2025-09-14 17:15:41 +02:00
RUN apk add --no-cache \
make \
git \
build-base \
linux-headers \
ca-certificates
2025-09-10 20:52:47 +02:00
# Get the workspace ready
2025-09-10 20:52:47 +02:00
RUN mkdir -p /workspace && \
git clone https://github.com/WGDashboard/amneziawg-tools /workspace/awg-tools
# Change directory
WORKDIR /workspace/awg-tools/src
# Compile and change permissions
2025-09-10 20:52:47 +02:00
RUN make && chmod +x wg*
#
# PIP DEPENDENCY BUILDING
# Base: Alpine
#
2025-07-24 20:23:42 +02:00
# Use the python-alpine image for building pip dependencies
FROM python:3.13-alpine AS pip-builder
# Add the build dependencies and create a Python virtual environment.
2025-09-14 17:15:41 +02:00
RUN apk add --no-cache \
build-base \
pkgconfig \
python3-dev \
libffi-dev \
linux-headers \
2025-09-16 14:00:20 +02:00
rust \
cargo \
2025-09-10 20:52:47 +02:00
&& mkdir -p /opt/wgdashboard/src \
&& python3 -m venv /opt/wgdashboard/src/venv
# Copy the requirements file into the build layer.
2025-09-10 20:52:47 +02:00
COPY ./src/requirements.txt /opt/wgdashboard/src
# Install the pip packages
2025-09-10 20:52:47 +02:00
RUN . /opt/wgdashboard/src/venv/bin/activate && \
pip3 install --upgrade pip && \
pip3 install -r /opt/wgdashboard/src/requirements.txt
#
# WGDashboard RUNNING STAGE
# Base: Alpine
#
# Running with the python-alpine image.
2025-09-14 17:15:41 +02:00
FROM python:3.13-alpine AS final
2025-07-24 20:23:42 +02:00
LABEL maintainer="dselen@nerthus.nl"
2025-09-14 17:15:41 +02:00
# Install only the runtime dependencies
RUN apk add --no-cache \
iproute2 iptables \
bash curl \
wget unzip \
procps sudo \
tzdata wireguard-tools \
openresolv openrc
2025-05-01 16:15:55 +02:00
# Copy only the final binaries from the AWG builder stages
2025-07-24 20:23:42 +02:00
COPY --from=awg-go /usr/bin/amneziawg-go /usr/bin/amneziawg-go
2025-09-10 20:52:47 +02:00
COPY --from=awg-tools /workspace/awg-tools/src/wg /usr/bin/awg
COPY --from=awg-tools /workspace/awg-tools/src/wg-quick/linux.bash /usr/bin/awg-quick
2024-12-12 11:03:39 +01:00
2025-09-14 17:15:41 +02:00
# Environment variables
ARG wg_net="10.0.0.1"
ARG wg_port="51820"
2025-04-25 09:27:07 +02:00
ENV TZ="Europe/Amsterdam" \
2025-05-01 16:15:55 +02:00
global_dns="9.9.9.9" \
wgd_port="10086" \
log_level="INFO" \
2025-09-14 17:15:41 +02:00
public_ip="" \
WGDASH=/opt/wgdashboard
2024-11-07 11:25:05 +01:00
# Create directories needed for operation
2025-09-14 17:15:41 +02:00
RUN mkdir /data /configs -p ${WGDASH}/src /etc/amnezia/amneziawg
2025-09-10 20:52:47 +02:00
# Copy the python virtual environment from the pip-builder stage
2024-11-07 11:25:05 +01:00
COPY ./src ${WGDASH}/src
2025-09-10 20:52:47 +02:00
COPY --from=pip-builder /opt/wgdashboard/src/venv /opt/wgdashboard/src/venv
2024-11-07 11:25:05 +01:00
# First WireGuard interface template
2024-11-07 11:25:05 +01:00
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN out_adapt=$(ip -o -4 route show to default | awk '{print $NF}') \
&& echo -e "[Interface]\n\
Address = ${wg_net}/24\n\
PrivateKey =\n\
PostUp = iptables -t nat -I POSTROUTING 1 -s ${wg_net}/24 -o ${out_adapt} -j MASQUERADE\n\
PostUp = iptables -I FORWARD -i wg0 -o wg0 -j DROP\n\
PreDown = iptables -t nat -D POSTROUTING -s ${wg_net}/24 -o ${out_adapt} -j MASQUERADE\n\
PreDown = iptables -D FORWARD -i wg0 -o wg0 -j DROP\n\
ListenPort = ${wg_port}\n\
SaveConfig = true\n\
DNS = ${global_dns}" > /configs/wg0.conf.template \
&& chmod 600 /configs/wg0.conf.template
# Set a healthcheck to determine the container its health
2024-11-07 11:25:05 +01:00
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD sh -c 'pgrep gunicorn > /dev/null && pgrep tail > /dev/null' || exit 1
# Copy in the runtime script, essential.
2025-04-22 21:20:41 +02:00
COPY ./docker/entrypoint.sh /entrypoint.sh
2024-11-07 11:25:05 +01:00
#
2024-11-07 11:25:05 +01:00
EXPOSE 10086
2025-09-10 20:52:47 +02:00
WORKDIR $WGDASH/src
2024-11-07 23:50:54 +08:00
2025-09-14 17:40:53 +02:00
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]