mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-12-27 09:22:19 +08:00
Changed around Docker image building and entrypoint.
- Succeeding my tests.
This commit is contained in:
parent
4ffb00c9f5
commit
83560bc775
3 changed files with 34 additions and 40 deletions
|
@ -30,9 +30,9 @@ RUN mkdir -p /setup/conf \
|
||||||
&& mkdir /data
|
&& mkdir /data
|
||||||
COPY ./src /setup/app/src
|
COPY ./src /setup/app/src
|
||||||
|
|
||||||
# Set the volume to be used for WireGuard configuration persistency.
|
# Set the volume to be used for WireGuard configuration persistency. Can be ignored so it does not create volumes when not specified.
|
||||||
VOLUME /etc/wireguard
|
#VOLUME /etc/wireguard
|
||||||
VOLUME ${WGDASH}
|
#VOLUME /data
|
||||||
|
|
||||||
# Generate basic WireGuard interface. Echoing the WireGuard interface config for readability, adjust if you want it for efficiency.
|
# Generate basic WireGuard interface. Echoing the WireGuard interface config for readability, adjust if you want it for efficiency.
|
||||||
# Also setting the pipefail option, verbose: https://github.com/hadolint/hadolint/wiki/DL4006.
|
# Also setting the pipefail option, verbose: https://github.com/hadolint/hadolint/wiki/DL4006.
|
||||||
|
|
|
@ -17,6 +17,7 @@ services:
|
||||||
- data:/data
|
- data:/data
|
||||||
cap_add:
|
cap_add:
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
conf:
|
conf:
|
||||||
data:
|
data:
|
||||||
|
|
|
@ -13,17 +13,12 @@ ensure_installation() {
|
||||||
# Moving over source files. (This does not include src/db and src/wg-dashboard.ini folder and file.)
|
# Moving over source files. (This does not include src/db and src/wg-dashboard.ini folder and file.)
|
||||||
mv -v /setup/app/* "${WGDASH}"
|
mv -v /setup/app/* "${WGDASH}"
|
||||||
|
|
||||||
if [ ! -d "/data/db" ]; then
|
[ ! -d "/data/db" ] && echo "Creating database dir" && mkdir /data/db
|
||||||
echo "Creating database dir"
|
ln -s /data/db "${WGDASH}/src/db"
|
||||||
mkdir /data/db
|
|
||||||
fi
|
[ ! -f "/data/wg-dashboard.ini" ] && echo "Creating wg-dashboard.ini file" && touch /data/wg-dashboard.ini
|
||||||
ln -s /data/db ${WGDASH}/src/db
|
ln -s /data/wg-dashboard.ini "${WGDASH}/src/wg-dashboard.ini"
|
||||||
|
|
||||||
if [ ! -f "/data/wg-dashboard.ini" ]; then
|
|
||||||
echo "Creating wg-dashboard.ini file"
|
|
||||||
touch /data/wg-dashboard.ini
|
|
||||||
fi
|
|
||||||
ln -s /data/wg-dashboard.ini ${WGDASH}/src/wg-dashboard.ini
|
|
||||||
|
|
||||||
python3 -m venv "${WGDASH}"/src/venv
|
python3 -m venv "${WGDASH}"/src/venv
|
||||||
. "${WGDASH}/src/venv/bin/activate"
|
. "${WGDASH}/src/venv/bin/activate"
|
||||||
|
@ -50,9 +45,8 @@ ensure_installation() {
|
||||||
echo "Setting a secure private key." # SORRY 4 BE4 - Daan
|
echo "Setting a secure private key." # SORRY 4 BE4 - Daan
|
||||||
|
|
||||||
local privateKey=$(wg genkey)
|
local privateKey=$(wg genkey)
|
||||||
|
|
||||||
sed -i "s|^PrivateKey =$|PrivateKey = ${privateKey}|g" /etc/wireguard/wg0.conf
|
|
||||||
sed -i "s|^PrivateKey *=.*$|PrivateKey = ${privateKey}|g" /etc/wireguard/wg0.conf
|
sed -i "s|^PrivateKey *=.*$|PrivateKey = ${privateKey}|g" /etc/wireguard/wg0.conf
|
||||||
|
|
||||||
echo "Done setting template."
|
echo "Done setting template."
|
||||||
else
|
else
|
||||||
echo "Existing wg0 configuration file found, using that."
|
echo "Existing wg0 configuration file found, using that."
|
||||||
|
@ -62,42 +56,40 @@ ensure_installation() {
|
||||||
clean_up() {
|
clean_up() {
|
||||||
printf "\n------------------------ CLEAN UP --------------------------\n"
|
printf "\n------------------------ CLEAN UP --------------------------\n"
|
||||||
|
|
||||||
# Cleaning out previous data such as the .pid file and starting the WireGuard Dashboard. Making sure to use the python venv.
|
local pid_file="${WGDASH}/src/gunicorn.pid"
|
||||||
|
local pycache="${WGDASH}/src/__pycache__"
|
||||||
|
local logdir="${WGDASH}/src/log"
|
||||||
|
|
||||||
echo "Looking for remains of previous instances..."
|
echo "Looking for remains of previous instances..."
|
||||||
|
|
||||||
local pid_file="${WGDASH}/src/gunicorn.pid"
|
# Handle the .pid file cleanup
|
||||||
if [ -f "$pid_file" ]; then
|
if [ -f "$pid_file" ]; then
|
||||||
echo "Found old pid file, removing."
|
echo "Found old pid file, removing."
|
||||||
rm $pid_file
|
rm -f "$pid_file"
|
||||||
else
|
else
|
||||||
echo "No pid remains found, continuing."
|
echo "No pid remains found, continuing."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Also check for Python caches (pycache) inspired by https://github.com/shuricksumy
|
# Remove Python caches (__pycache__)
|
||||||
echo "Looking for remains of pycache..."
|
echo "Looking for remains of pycache..."
|
||||||
|
|
||||||
local pycache="${WGDASH}/src/__pycache__"
|
|
||||||
if [ -d "$pycache" ]; then
|
if [ -d "$pycache" ]; then
|
||||||
local pycache_filecount=$(find "$pycache" -maxdepth 1 -type f | wc -l)
|
if find "$pycache" -type f -print -quit | grep -q .; then
|
||||||
if [ "$pycache_filecount" -gt 0 ]; then
|
|
||||||
echo "Found old pycaches, removing."
|
echo "Found old pycaches, removing."
|
||||||
rm -rf "$pycache"/*
|
rm -rf "$pycache"
|
||||||
else
|
else
|
||||||
echo "No pycaches found, continuing."
|
echo "No pycaches found, continuing."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "No pycaches found, continuing."
|
echo "No pycaches directory found, continuing."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleaning up the logs from the previous instance.
|
# Clean up log files
|
||||||
echo "Cleaning log directory..."
|
echo "Cleaning log directory..."
|
||||||
|
find "$logdir" -type f -name 'access_*.log' -o -name 'error_*.log' -exec rm -f {} +
|
||||||
local logdir="${WGDASH}/src/log"
|
|
||||||
find $logdir -name 'access_*.log' -exec rm {} +
|
|
||||||
find $logdir -name 'error_*.log' -exec rm {} +
|
|
||||||
echo "Removed unneeded logs!"
|
echo "Removed unneeded logs!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set_envvars() {
|
set_envvars() {
|
||||||
printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n"
|
printf "\n------------- SETTING ENVIRONMENT VARIABLES ----------------\n"
|
||||||
|
|
||||||
|
@ -118,7 +110,6 @@ set_envvars() {
|
||||||
else
|
else
|
||||||
echo "Config file is not empty"
|
echo "Config file is not empty"
|
||||||
|
|
||||||
cat /opt/wireguarddashboard/src/wg-dashboard.ini
|
|
||||||
# Check and update the DNS if it has changed
|
# Check and update the DNS if it has changed
|
||||||
current_dns=$(grep "peer_global_dns = " "$config_file" | awk '{print $NF}')
|
current_dns=$(grep "peer_global_dns = " "$config_file" | awk '{print $NF}')
|
||||||
if [ "${global_dns}" != "$current_dns" ]; then
|
if [ "${global_dns}" != "$current_dns" ]; then
|
||||||
|
@ -242,22 +233,24 @@ start_core() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# === CLEAN UP ===
|
|
||||||
ensure_blocking() {
|
ensure_blocking() {
|
||||||
#printf "\n-------------- ENSURING CONTAINER CONTINUATION -------------\n"
|
|
||||||
|
|
||||||
sleep 1s
|
sleep 1s
|
||||||
echo -e "\nEnsuring container continuation."
|
echo -e "\nEnsuring container continuation."
|
||||||
|
|
||||||
# This function checks if the latest error log is created and tails it for docker logs uses.
|
# Find and tail the latest error and access logs if they exist
|
||||||
if find "/opt/wireguarddashboard/src/log" -mindepth 1 -maxdepth 1 -type f | read -r; then
|
local logdir="/opt/wireguarddashboard/src/log"
|
||||||
latestErrLog=$(find /opt/wireguarddashboard/src/log -name "error_*.log" | head -n 1)
|
|
||||||
latestAccLog=$(find /opt/wireguarddashboard/src/log -name "access_*.log" | head -n 1)
|
latestErrLog=$(find "$logdir" -name "error_*.log" -type f -print | sort -r | head -n 1)
|
||||||
|
latestAccLog=$(find "$logdir" -name "access_*.log" -type f -print | sort -r | head -n 1)
|
||||||
|
|
||||||
tail -f "${latestErrLog}" "${latestAccLog}"
|
# Only tail the logs if they are found
|
||||||
|
if [ -n "$latestErrLog" ] || [ -n "$latestAccLog" ]; then
|
||||||
|
tail -f "$latestErrLog" "$latestAccLog"
|
||||||
|
else
|
||||||
|
echo "No log files found to tail."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Blocking command in case of erroring. So the container does not quit.
|
# Blocking command to keep the container running as a last resort.
|
||||||
sleep infinity
|
sleep infinity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue