mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
Debugging operational in vscode
This commit is contained in:
@@ -67,13 +67,13 @@ ENV SYSTEM_SERVICES_RUN_LOG=${SYSTEM_SERVICES_RUN}/logs
|
||||
ENV PHP_FPM_CONFIG_FILE=${SYSTEM_SERVICES_PHP_FOLDER}/php-fpm.conf
|
||||
|
||||
ENV PYTHONPATH=${NETALERTX_SERVER}
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
|
||||
RUN apk add --no-cache bash mtr libbsd zip lsblk sudo tzdata curl arp-scan iproute2 \
|
||||
iproute2-ss nmap nmap-scripts traceroute nbtscan net-tools net-snmp-tools bind-tools awake \
|
||||
ca-certificates sqlite php83 php83-fpm php83-cgi php83-curl php83-sqlite3 php83-session python3 \
|
||||
nginx sudo shadow && \
|
||||
iproute2-ss nmap nmap-scripts traceroute nbtscan net-tools net-snmp-tools bind-tools awake \
|
||||
ca-certificates sqlite php83 php83-fpm php83-cgi php83-curl php83-sqlite3 php83-session python3 \
|
||||
nginx sudo shadow && \
|
||||
rm -Rf /var/cache/apk/* && \
|
||||
rm -Rf /etc/nginx && \
|
||||
addgroup -g 20211 netalertx && \
|
||||
@@ -105,6 +105,7 @@ RUN apk add libcap && \
|
||||
/bin/sh /build/init-php-fpm.sh && \
|
||||
/bin/sh /build/init-crond.sh && \
|
||||
/bin/sh /build/init-backend.sh && \
|
||||
chmod 755 ${NETALERTX_BACK}/update_vendors.sh ${NETALERTX_BACK}/cron_script.sh ${NETALERTX_BACK}/speedtest-cli && \
|
||||
rm -rf /build && \
|
||||
apk del libcap
|
||||
# set netalertx to allow sudoers for any command, no password
|
||||
@@ -135,7 +136,7 @@ RUN chown -R readonly:readonly ${NETALERTX_BACK} ${NETALERTX_FRONT} ${NETALERTX_
|
||||
chmod 700 ${NETALERTX_CONFIG} ${NETALERTX_DB} ${NETALERTX_API} ${NETALERTX_LOG} ${NETALERTX_PLUGINS_LOG} ${SYSTEM_SERVICES_RUN_TMP} && \
|
||||
chown readonly:readonly /entrypoint.sh && \
|
||||
install -d -o netalertx -g netalertx -m 700 ${SYSTEM_SERVICES_RUN} ${SYSTEM_SERVICES_RUN_TMP} ${SYSTEM_SERVICES_RUN_LOG} && \
|
||||
chmod 005 /entrypoint.sh
|
||||
chmod 005 /entrypoint.sh ${NETALERTX_BACK}/update_vendors.sh ${NETALERTX_BACK}/cron_script.sh ${NETALERTX_BACK}/speedtest-cli
|
||||
|
||||
#
|
||||
# remove sudo and alpine installers pacakges
|
||||
@@ -155,7 +156,7 @@ RUN rm -Rf /etc/sudoers.d/* /etc/shadow /etc/gshadow /etc/sudoers \
|
||||
USER netalertx
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /usr/local/bin/healthcheck.sh
|
||||
CMD /services/healthcheck.sh
|
||||
|
||||
#ENTRYPOINT [ "/bin/sh" ]
|
||||
ENTRYPOINT [ "/bin/sh", "/entrypoint.sh" ]
|
||||
@@ -172,10 +173,13 @@ FROM runner AS netalertx-devcontainer
|
||||
ENV INSTALL_DIR=/app
|
||||
ENV PYTHONPATH=/workspaces/NetAlertX/test:/workspaces/NetAlertX/server:/app:/app/server:/opt/venv/lib/python3.12/site-packages
|
||||
ENV PATH=/services:${PATH}
|
||||
ENV PHP_INI_SCAN_DIR=/services/config/php/conf.d:/etc/php83/conf.d
|
||||
COPY .devcontainer/resources/devcontainer-overlay/ /
|
||||
|
||||
# Install common tools, create user, and set up sudo
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov
|
||||
RUN install -d -o netalertx -g netalertx -m 755 /services/php/modules && \
|
||||
cp -a /usr/lib/php83/modules/. /services/php/modules/
|
||||
# Install debugpy in the virtualenv if present, otherwise into system python3
|
||||
RUN /bin/sh -c '(/opt/venv/bin/python3 -m pip install --no-cache-dir debugpy) || (python3 -m pip install --no-cache-dir debugpy) || true' && \
|
||||
mkdir /workspaces && \
|
||||
|
||||
@@ -8,10 +8,13 @@ FROM runner AS netalertx-devcontainer
|
||||
ENV INSTALL_DIR=/app
|
||||
ENV PYTHONPATH=/workspaces/NetAlertX/test:/workspaces/NetAlertX/server:/app:/app/server:/opt/venv/lib/python3.12/site-packages
|
||||
ENV PATH=/services:${PATH}
|
||||
ENV PHP_INI_SCAN_DIR=/services/config/php/conf.d:/etc/php83/conf.d
|
||||
COPY .devcontainer/resources/devcontainer-overlay/ /
|
||||
|
||||
# Install common tools, create user, and set up sudo
|
||||
RUN apk add --no-cache git nano vim jq php83-pecl-xdebug py3-pip nodejs sudo gpgconf pytest pytest-cov
|
||||
RUN install -d -o netalertx -g netalertx -m 755 /services/php/modules && \
|
||||
cp -a /usr/lib/php83/modules/. /services/php/modules/
|
||||
# Install debugpy in the virtualenv if present, otherwise into system python3
|
||||
RUN /bin/sh -c '(/opt/venv/bin/python3 -m pip install --no-cache-dir debugpy) || (python3 -m pip install --no-cache-dir debugpy) || true' && \
|
||||
mkdir /workspaces && \
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
zend_extension="/services/php/modules/xdebug.so"
|
||||
extension_dir="/services/php/modules"
|
||||
|
||||
[xdebug]
|
||||
xdebug.mode=develop,debug
|
||||
xdebug.log=/app/log/xdebug.log
|
||||
xdebug.log_level=7
|
||||
xdebug.client_host=host.docker.internal
|
||||
xdebug.client_port=9003
|
||||
xdebug.start_with_request=yes
|
||||
xdebug.discover_client_host=1
|
||||
@@ -0,0 +1 @@
|
||||
-m debugpy --listen 0.0.0.0:5678
|
||||
@@ -109,10 +109,10 @@ configure_php() {
|
||||
start_services() {
|
||||
echo "[4/4] Starting services..."
|
||||
|
||||
echo " -> Starting CronD"
|
||||
echo " -> Starting CronD (${SYSTEM_SERVICES_CROND}...)"
|
||||
setsid nohup /services/start-crond.sh &>/dev/null &
|
||||
|
||||
echo " -> Starting PHP-FPM"
|
||||
echo " -> Starting PHP-FPM (${SYSTEM_SERVICES_PHP_FOLDER}...)"
|
||||
setsid nohup /services/start-php-fpm.sh &>/dev/null &
|
||||
|
||||
# Wait for the previous nginx processes to exit and for the port to free up
|
||||
@@ -123,10 +123,10 @@ start_services() {
|
||||
tries=$((tries+1))
|
||||
done
|
||||
sleep 1
|
||||
echo " -> Starting Nginx"
|
||||
/services/start-nginx.sh
|
||||
echo " -> Starting Backend ${APP_DIR}/server..."
|
||||
setsid nohup /services/start-backend.sh &
|
||||
echo " -> Starting Nginx (${NETALERTX_FRONT}...)"
|
||||
setsid nohup /services/start-nginx.sh &>/dev/null &
|
||||
echo " -> Starting Backend (${NETALERTX_SERVER}...)"
|
||||
setsid nohup /services/start-backend.sh >/dev/null 2>&1 &
|
||||
sleep 2
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
zend_extension=xdebug.so
|
||||
xdebug.mode=debug
|
||||
xdebug.start_with_request=trigger
|
||||
xdebug.trigger_value=VSCODE
|
||||
xdebug.client_host=host.docker.internal
|
||||
xdebug.client_port=9003
|
||||
xdebug.log=/var/log/xdebug.log
|
||||
xdebug.log_level=7
|
||||
xdebug.idekey=VSCODE
|
||||
xdebug.discover_client_host=true
|
||||
xdebug.max_nesting_level=512
|
||||
2
.vscode/tasks.json
vendored
2
.vscode/tasks.json
vendored
@@ -110,7 +110,7 @@
|
||||
{
|
||||
"label": "[Dev Container] Start Frontend (nginx and PHP-FPM)",
|
||||
"type": "shell",
|
||||
"command": "./isDevContainer.sh || exit 1; killall php-fpm83 nginx 2>/dev/nulltrue; sleep 1; /services/start-php-fpm.sh & /sevices/start-nginx.sh &",
|
||||
"command": "./isDevContainer.sh || exit 1; killall php-fpm83 nginx 2>/dev/null||true; sleep 1; /services/start-php-fpm.sh & /services/start-nginx.sh &",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder:NetAlertX}/.devcontainer/scripts"
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ RUN rm -Rf /etc/sudoers.d/* /etc/shadow /etc/gshadow /etc/sudoers \
|
||||
USER netalertx
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /usr/local/bin/healthcheck.sh
|
||||
CMD /services/healthcheck.sh
|
||||
|
||||
#ENTRYPOINT [ "/bin/sh" ]
|
||||
ENTRYPOINT [ "/bin/sh", "/entrypoint.sh" ]
|
||||
|
||||
@@ -1,35 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "Starting backend..."
|
||||
cd "${NETALERTX_APP}" || exit 1
|
||||
# Change user to netalertx
|
||||
export PYTHONPATH="${NETALERTX_SERVER}:${NETALERTX_APP}"
|
||||
|
||||
EXTRA_PARAMS=""
|
||||
if [ -f /services/config/python/backend-extra-launch-parameters ]; then
|
||||
EXTRA_PARAMS=$(cat /services/config/python/backend-extra-launch-parameters)
|
||||
fi
|
||||
|
||||
backend_pid=""
|
||||
|
||||
cleanup() {
|
||||
status=$?
|
||||
echo "Backend stopped! (exit ${status})"
|
||||
}
|
||||
|
||||
forward_signal() {
|
||||
if [[ -n "${backend_pid}" ]]; then
|
||||
kill -TERM "${backend_pid}" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
trap forward_signal INT TERM
|
||||
|
||||
# Start the backend, teeing stdout and stderr to log files and the container's console
|
||||
python3 ${EXTRA_PARAMS} -m server > >(tee /app/log/stdout.log) 2> >(tee /app/log/stderr.log >&2) &
|
||||
backend_pid=$!
|
||||
|
||||
wait "${backend_pid}"
|
||||
exit $?
|
||||
exec python3 $(cat /services/config/python/backend-extra-launch-parameters 2>/dev/null) -m server > >(tee /app/log/stdout.log) 2> >(tee /app/log/stderr.log >&2)
|
||||
|
||||
Reference in New Issue
Block a user