monolithic alpine container

This commit is contained in:
Adam Outler
2025-09-25 07:43:42 -04:00
parent 2e694a752d
commit 8ed21a8c07
24 changed files with 204 additions and 978 deletions

View File

@@ -0,0 +1,22 @@
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

View File

@@ -0,0 +1,62 @@
# map $request_uri $auth_result {
# default "";
# ~^/api/ /auth_result;
# }
# log_format auth_request_log '$remote_addr - $remote_user [$time_local] '
# '"$request" $status $body_bytes_sent '
# '"$http_referer" "$http_user_agent" '
# '$auth_result';
server {
listen 0.0.0.0:20211 default_server;
root /app/front;
index index.php;
add_header X-Forwarded-Prefix "/app" always;
proxy_set_header X-Forwarded-Prefix "/app";
# # Authentication endpoint
# location = /auth {
# internal;
# proxy_pass http://127.0.0.1/php/templates/auth.php;
# proxy_set_header Content-Length "";
# proxy_pass_request_body off;
# }
# # Whitelisting IP addresses and CORS for /api/
# location /api/ {
# auth_request /auth;
# access_log /var/log/nginx/auth_request.log auth_request_log;
# # Enable CORS for specific frontend domain
# add_header 'Access-Control-Allow-Origin' 'http://192.168.1.82:20211' always;
# add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
# add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always;
# add_header 'Access-Control-Allow-Credentials' 'true' always;
# if ($request_method = 'OPTIONS') {
# return 204;
# }
# error_page 401 = @unauthorized;
# # Other headers and configurations
# try_files $uri $uri/ =404;
# }
# location @unauthorized {
# return 401;
# }
location ~* \.php$ {
# Set Cache-Control header to prevent caching on the first load
add_header Cache-Control "no-store";
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_connect_timeout 75;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
}
}

View File

@@ -0,0 +1,98 @@
user nginx;
# Set number of worker processes automatically based on number of CPU cores.
worker_processes auto;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Configures default error logger.
error_log /var/log/nginx/error.log warn;
# Includes files with directives to load dynamic modules.
include /etc/nginx/modules/*.conf;
events {
# The maximum number of simultaneous connections that can be opened by
# a worker process.
worker_connections 1024;
}
http {
# Includes mapping of file name extensions to MIME types of responses
# and defines the default type.
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Name servers used to resolve names of upstream servers into addresses.
# It's also needed when using tcpsocket and udpsocket in Lua modules.
#resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001];
# Don't tell nginx version to the clients. Default is 'on'.
server_tokens off;
# Specifies the maximum accepted body size of a client request, as
# indicated by the request header Content-Length. If the stated content
# length is greater than this size, then the client receives the HTTP
# error code 413. Set to 0 to disable. Default is '1m'.
client_max_body_size 1m;
# Sendfile copies data between one FD and other from within the kernel,
# which is more efficient than read() + write(). Default is off.
sendfile on;
# Causes nginx to attempt to send its HTTP response head in one packet,
# instead of using partial frames. Default is 'off'.
tcp_nopush on;
# Enables the specified protocols. Default is TLSv1 TLSv1.1 TLSv1.2.
# TIP: If you're not obligated to support ancient clients, remove TLSv1.1.
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
# Path of the file with Diffie-Hellman parameters for EDH ciphers.
# TIP: Generate with: `openssl dhparam -out /etc/ssl/nginx/dh2048.pem 2048`
#ssl_dhparam /etc/ssl/nginx/dh2048.pem;
# Specifies that our cipher suits should be preferred over client ciphers.
# Default is 'off'.
ssl_prefer_server_ciphers on;
# Enables a shared SSL cache with size that can hold around 8000 sessions.
# Default is 'none'.
ssl_session_cache shared:SSL:2m;
# Specifies a time during which a client may reuse the session parameters.
# Default is '5m'.
ssl_session_timeout 1h;
# Disable TLS session tickets (they are insecure). Default is 'on'.
ssl_session_tickets off;
# Enable gzipping of responses.
#gzip on;
# Set the Vary HTTP header as defined in the RFC 2616. Default is 'off'.
gzip_vary on;
# Helper variable for proxying websockets.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Specifies the main log format.
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# Sets the path, format, and configuration for a buffered log write.
access_log /var/log/nginx/access.log main;
# Includes virtual hosts configs.
include /app/services/nginx/netalertx.conf;
}

View File

@@ -0,0 +1,8 @@
#!/bin/bash
echo "Initializing backend..."
# Future backend initialization steps can go here.
# For now, we'll just ensure permissions are correct.
chown -R nginx:www-data "${NETALERTX_APP}"
chmod 750 "${NETALERTX_APP}"/config "${NETALERTX_APP}"/log "${NETALERTX_APP}"/db
find "${NETALERTX_APP}"/config "${NETALERTX_APP}"/log "${NETALERTX_APP}"/db -type f -exec chmod 640 {} \;
echo "Backend initialized."

View File

@@ -0,0 +1,7 @@
#!/bin/bash
echo "Initializing crond..."
# Add crontab file
chmod 600 /etc/crontabs/root
chown root:root /etc/crontabs/root
echo "crond initialized."

View File

@@ -0,0 +1,3 @@
#!/bin/bash
echo "Initializing nginx..."
# Nothing to do here, nginx is configured at runtime

View File

@@ -0,0 +1,22 @@
#!/bin/bash
echo "Initializing php-fpm..."
# Set up PHP-FPM directories and socket configuration
install -d -o nginx -g www-data /run/php/
sed -i "/^;pid/c\pid = /run/php/php8.3-fpm.pid" /etc/php83/php-fpm.conf
sed -i "/^listen/c\listen = /run/php/php8.3-fpm.sock" /etc/php83/php-fpm.d/www.conf
sed -i "/^;listen.owner/c\listen.owner = nginx" /etc/php83/php-fpm.d/www.conf
sed -i "/^;listen.group/c\listen.group = www-data" /etc/php83/php-fpm.d/www.conf
sed -i "/^user/c\user = nginx" /etc/php83/php-fpm.d/www.conf
sed -i "/^group/c\group = www-data" /etc/php83/php-fpm.d/www.conf
# Increase max child process count
sed -i -e 's/pm.max_children = 5/pm.max_children = 10/' /etc/php83/php-fpm.d/www.conf
# Set error log path
sed -i "/^;*error_log\s*=/c\error_log = ${LOG_APP_PHP_ERRORS}" /etc/php83/php-fpm.conf
# If the line was not found, append it to the end of the file
if ! grep -q '^error_log\s*=' /etc/php83/php-fpm.conf; then
echo "error_log = ${LOG_APP_PHP_ERRORS}" >> /etc/php83/php-fpm.conf
fi
echo "php-fpm initialized."

View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Function to clean up background processes
cleanup() {
echo "Caught signal, shutting down services..."
# Kill all background jobs
kill $(jobs -p)
wait
echo "All services stopped."
exit 0
}
# Trap SIGINT (Ctrl+C) and SIGTERM (docker stop)
trap cleanup SIGINT SIGTERM
# Start all necessary services for NetAlertX in the background
/services/start-crond.sh &
/services/start-php-fpm.sh &
/services/start-nginx.sh &
/services/start-backend.sh &
# Wait for any background process to exit
wait -n
# Trigger cleanup if any process exits
cleanup

View File

@@ -0,0 +1,2 @@
# Schedule cron jobs
* * * * * /app/back/cron_script.sh

View File

@@ -0,0 +1,15 @@
-----BEGIN CERTIFICATE-----
MIICOjCCAcCgAwIBAgIUI0Tu7zsrBJACQIZgLMJobtbdNn4wCgYIKoZIzj0EAwIw
TDELMAkGA1UEBhMCSVQxDjAMBgNVBAgMBUl0YWx5MQ4wDAYDVQQKDAVJbGlhZDEd
MBsGA1UEAwwUSWxpYWRib3ggRUNDIFJvb3QgQ0EwHhcNMjAxMTI3MDkzODEzWhcN
NDAxMTIyMDkzODEzWjBMMQswCQYDVQQGEwJJVDEOMAwGA1UECAwFSXRhbHkxDjAM
BgNVBAoMBUlsaWFkMR0wGwYDVQQDDBRJbGlhZGJveCBFQ0MgUm9vdCBDQTB2MBAG
ByqGSM49AgEGBSuBBAAiA2IABMryJyb2loHNAioY8IztN5MI3UgbVHVP/vZwcnre
ZvJOyDvE4HJgIti5qmfswlnMzpNbwf/MkT+7HAU8jJoTorRm1wtAnQ9cWD3Ebv79
RPwtjjy3Bza3SgdVxmd6fWPUKaNjMGEwHQYDVR0OBBYEFDUij/4lpoJ+kOXRyrcM
jf2RPzOqMB8GA1UdIwQYMBaAFDUij/4lpoJ+kOXRyrcMjf2RPzOqMA8GA1UdEwEB
/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA2gAMGUCMQC6eUV1
pFh4UpJOTc1JToztN4ttnQR6rIzxMZ6mNCe+nhjkohWp24pr7BpUYSbEizYCMAQ6
LCiBKV2j7QQGy7N1aBmdur17ZepYzR1YV0eI+Kd978aZggsmhjXENQYVTmm/XA==
-----END CERTIFICATE-----

View File

@@ -0,0 +1,73 @@
#!/bin/bash
# NetAlertX Comprehensive Health Check Script
# This script verifies all critical services and endpoints are functioning
set -e
EXIT_CODE=0
echo "[HEALTHCHECK] Starting comprehensive health check..."
# Function to log errors and set exit code
log_error() {
echo "[HEALTHCHECK] ERROR: $1" >&2
EXIT_CODE=1
}
# Function to log success
log_success() {
echo "[HEALTHCHECK] ✓ $1"
}
# 1. Check if crond is running
if pgrep -f "crond" > /dev/null; then
log_success "crond is running"
else
log_error "crond is not running"
fi
# 2. Check if php-fpm is running
if pgrep -f "php-fpm" > /dev/null; then
log_success "php-fpm is running"
else
log_error "php-fpm is not running"
fi
# 3. Check if nginx is running
if pgrep -f "nginx" > /dev/null; then
log_success "nginx is running"
else
log_error "nginx is not running"
fi
# 4. Check if python /app/server is running
if pgrep -f "python.*server" > /dev/null; then
log_success "python /app/server is running"
else
log_error "python /app/server is not running"
fi
# 5. Check port 20211 is open and contains "netalertx"
if curl -sf --max-time 10 "http://localhost:${PORT:-20211}" | grep -i "netalertx" > /dev/null; then
log_success "Port ${PORT:-20211} is responding and contains 'netalertx'"
else
log_error "Port ${PORT:-20211} is not responding or doesn't contain 'netalertx'"
fi
# 6. Check port 20212/graphql returns "graphql" in first lines
GRAPHQL_PORT=${GRAPHQL_PORT:-20212}
if curl -sf --max-time 10 "http://localhost:${GRAPHQL_PORT}/graphql" | head -10 | grep -i "graphql" > /dev/null; then
log_success "Port ${GRAPHQL_PORT}/graphql is responding with GraphQL content"
else
log_error "Port ${GRAPHQL_PORT}/graphql is not responding or doesn't contain 'graphql'"
fi
# Summary
if [ $EXIT_CODE -eq 0 ]; then
echo "[HEALTHCHECK] ✅ All health checks passed"
else
echo "[HEALTHCHECK] ❌ One or more health checks failed"
fi
exit $EXIT_CODE

View File

@@ -0,0 +1,6 @@
#!/bin/bash
echo "Starting backend..."
cd "${NETALERTX_APP}" || exit
export PYTHONPATH="${NETALERTX_SERVER}"
# Start the backend, teeing stdout and stderr to log files and the container's console
python3 -m server > >(tee /app/log/stdout.log) 2> >(tee /app/log/stderr.log >&2)

View File

@@ -0,0 +1,3 @@
#!/bin/bash
echo "Starting crond..."
exec /usr/sbin/crond -f -L "${LOG_CROND}"

View File

@@ -0,0 +1,5 @@
#!/bin/bash
echo "Starting nginx..."
exec nginx \
-c "${NGINX_CONFIG_FILE}" \
-g "daemon off;" >> "${LOG_APP_FRONT}" 2>&1

View File

@@ -0,0 +1,3 @@
#!/bin/bash
echo "Starting php-fpm..."
exec /usr/sbin/php-fpm83 -F >> "${LOG_APP_PHP_ERRORS}" 2>&1