1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 07:10:09 +01:00

Docker 2 Stage

This commit is contained in:
Noxcis 2024-08-24 20:02:34 -05:00
parent b07f958577
commit 8f6a738481
7 changed files with 107 additions and 60 deletions

View File

@ -1,25 +1,35 @@
# Pull from small Debian stable image. # Pull from small Debian stable image.
FROM alpine:latest FROM alpine:latest AS builder
LABEL maintainer="dselen@nerthus.nl" LABEL maintainer="dselen@nerthus.nl"
ENV PYTHONPATH="/usr/lib/python3.12/site-packages"
WORKDIR /opt/wireguarddashboard/src WORKDIR /opt/wireguarddashboard/src
RUN apk update && \
apk add --no-cache sudo gcc musl-dev linux-headers && \
apk add --no-cache wireguard-tools && \
apk add --no-cache iptables ip6tables && \
mkdir /opt/wireguarddashboard/src/master-key
RUN apk update && \
apk add --no-cache sudo gcc musl-dev rust cargo linux-headers
COPY ./docker/alpine/builder.sh /opt/wireguarddashboard/src/
COPY ./docker/alpine/requirements.txt /opt/wireguarddashboard/src/
RUN chmod u+x /opt/wireguarddashboard/src/builder.sh
RUN /opt/wireguarddashboard/src/builder.sh
FROM alpine:latest
WORKDIR /opt/wireguarddashboard/src
COPY ./src /opt/wireguarddashboard/src/ COPY ./src /opt/wireguarddashboard/src/
COPY --from=builder /opt/wireguarddashboard/src/venv /opt/wireguarddashboard/src/venv
COPY --from=builder /opt/wireguarddashboard/src/log /opt/wireguarddashboard/src/log/
COPY ./docker/alpine/entrypoint.sh /opt/wireguarddashboard/src/ COPY ./docker/alpine/entrypoint.sh /opt/wireguarddashboard/src/
#COPY ./docker/alpine/wgd.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
# Defining a way for Docker to check the health of the container. In this case: checking the login URL.
RUN apk update && \
apk add --no-cache wireguard-tools sudo && \
apk add --no-cache iptables ip6tables && \
chmod u+x /opt/wireguarddashboard/src/entrypoint.sh
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD curl -f http://localhost:10086/signin || exit 1 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD curl -f http://localhost:10086/signin || exit 1
ENTRYPOINT ["/opt/wireguarddashboard/src/entrypoint.sh"] ENTRYPOINT ["/opt/wireguarddashboard/src/entrypoint.sh"]

View File

@ -12,7 +12,7 @@ services:
- wg_port=51820 - wg_port=51820
volumes: volumes:
- wgd_configs:/etc/wireguard - wgd_configs:/etc/wireguard
- wgd_app:/opt/wireguarddashboard/src #- wgd_app:/opt/wireguarddashboard/src
ports: ports:
- 10086:10086/tcp - 10086:10086/tcp
- 51820:51820/udp - 51820:51820/udp
@ -23,4 +23,4 @@ services:
volumes: volumes:
wgd_configs: wgd_configs:
wgd_app: #wgd_app:

43
docker/alpine/builder.sh Normal file
View File

@ -0,0 +1,43 @@
venv_python="./venv/bin/python3"
venv_gunicorn="./venv/bin/gunicorn"
pythonExecutable="python3"
_check_and_set_venv(){
VIRTUAL_ENV="./venv"
if [ ! -d $VIRTUAL_ENV ]; then
printf "[WGDashboard] Creating Python Virtual Environment under ./venv\n"
{ $pythonExecutable -m venv $VIRTUAL_ENV; } >> ./log/install.txt
fi
if ! $venv_python --version > /dev/null 2>&1
then
printf "[WGDashboard] %s Python Virtual Environment under ./venv failed to create. Halting now.\n" "$heavy_crossmark"
kill $TOP_PID
fi
source ${VIRTUAL_ENV}/bin/activate
}
build_core () {
if [ ! -d "log" ]
then
printf "[WGDashboard] Creating ./log folder\n"
mkdir "log"
fi
apk add --no-cache python3 net-tools python3-dev py3-virtualenv
_check_and_set_venv
printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n"
{ date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt
printf "[WGDashboard] Building Bcrypt & Psutil\n"
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt
printf "[WGDashboard] Build Successfull!\n"
printf "[WGDashboard] Clean Up Pip!\n"
{ date; rm -rf /opt/wireguarddashboard/src/venv/lib/python3.12/site-packages/pip* ; printf "\n\n"; } >> ./log/install.txt
}
build_core

View File

@ -11,9 +11,6 @@ clean_up() {
echo "No remains found, continuing." echo "No remains found, continuing."
fi fi
} }
ensure_blocking() { ensure_blocking() {
sleep 1s sleep 1s
echo "Ensuring container continuation." echo "Ensuring container continuation."
@ -29,13 +26,13 @@ ensure_blocking() {
sleep infinity sleep infinity
} }
# Execute functions for the WireGuard Dashboard services, then set the environment variables { date; clean_up; printf "\n\n"; } >> ./log/install.txt
clean_up
chmod u+x /opt/wireguarddashboard/src/wgd.sh 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 install
/opt/wireguarddashboard/src/wgd.sh start /opt/wireguarddashboard/src/wgd.sh start
ensure_blocking ensure_blocking

View File

@ -1,8 +1,2 @@
#bcrypt bcrypt
ifcfg psutil
#psutil
pyotp
Flask
flask-cors
icmplib
gunicorn

View File

@ -59,6 +59,7 @@ _check_and_set_venv(){
. ${VIRTUAL_ENV}/bin/activate . ${VIRTUAL_ENV}/bin/activate
} }
_determineOS(){ _determineOS(){
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
. /etc/os-release . /etc/os-release
@ -88,7 +89,7 @@ _installPython(){
fi fi
;; ;;
alpine) alpine)
{ apk update; apk add python3 net-tools py3-bcrypt py3-psutil; printf "\n\n"; } &>> ./log/install.txt { apk update; apk add python3 net-tools ; printf "\n\n"; } &>> ./log/install.txt
;; ;;
esac esac
@ -257,8 +258,6 @@ install_wgd(){
_installPythonPip _installPythonPip
if [ ! -d "db" ] if [ ! -d "db" ]
then then
printf "[WGDashboard] Creating ./db folder\n" printf "[WGDashboard] Creating ./db folder\n"
@ -266,12 +265,16 @@ install_wgd(){
fi fi
_check_and_set_venv _check_and_set_venv
printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n" printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n"
{ date; python3 -m ensurepip --upgrade; printf "\n\n"; } >> ./log/install.txt
{ date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt { date; python3 -m pip install --upgrade pip; printf "\n\n"; } >> ./log/install.txt
printf "[WGDashboard] Installing latest Python dependencies\n" printf "[WGDashboard] Installing latest Python dependencies\n"
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt { date; python3 -m pip install -r requirements.txt ; printf "\n\n"; } >> ./log/install.txt
printf "[WGDashboard] WGDashboard installed successfully!\n" printf "[WGDashboard] WGDashboard installed successfully!\n"
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n" printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
#deactivate
} }
check_wgd_status(){ check_wgd_status(){
@ -307,8 +310,8 @@ gunicorn_start () {
fi fi
_check_and_set_venv _check_and_set_venv
sudo "$venv_gunicorn" --config ./gunicorn.conf.py sudo "$venv_gunicorn" --config ./gunicorn.conf.py
#sudo gunicorn -c ./gunicorn.conf.py
sleep 5 sleep 5
checkPIDExist=0 checkPIDExist=0
while [ $checkPIDExist -eq 0 ] while [ $checkPIDExist -eq 0 ]

View File

@ -88,7 +88,7 @@ _installPython(){
fi fi
;; ;;
alpine) alpine)
{ apk update; apk add python3 net-tools python3-dev; printf "\n\n"; } &>> ./log/install.txt { apk update; apk add python3 net-tools; printf "\n\n"; } &>> ./log/install.txt
;; ;;
esac esac