Optimization of entrypoint (#39)
Some checks failed
Test / integration (push) Has been cancelled
Build / docker (push) Has been cancelled

This commit is contained in:
2025-05-11 09:39:25 +02:00
committed by GitHub
parent 258580b107
commit 091ebc6b09
3 changed files with 99 additions and 97 deletions

View File

@@ -6,6 +6,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Build the Docker image
- name: Build Docker Image
run: |
docker buildx build -f src/docker/Dockerfile --build-arg phpVersion=8.4 -t ${{ vars.BUILDKIT_IMAGE }}:latest --load .
- name: Verify Docker images
run: |
docker images
- name: Create Laravel project
run: |
composer create-project laravel/laravel laravel

View File

@@ -1,37 +1,33 @@
#!/bin/sh
set -e
echo ""
echo "***********************************************************"
echo " Starting NGINX PHP-FPM Docker Container "
echo "***********************************************************"
set -e
set -e
info() {
{ set +x; } 2> /dev/null
echo '[INFO] ' "$@"
}
warning() {
{ set +x; } 2> /dev/null
echo '[WARNING] ' "$@"
}
fatal() {
{ set +x; } 2> /dev/null
echo '[ERROR] ' "$@" >&2
exit 1
}
## Check if the artisan file exists
if [ -f /var/www/html/artisan ]; then
info "Artisan file found, creating laravel supervisor config"
# Set DocumentRoot to the Laravel project directory
export DOCUMENT_ROOT=/var/www/html/public
##Create Laravel Scheduler process
TASK=/etc/supervisor/conf.d/laravel-worker.conf
touch $TASK
cat > "$TASK" <<EOF
# Logging functions
info() { echo "[INFO] $*"; }
warning() { echo "[WARNING] $*"; }
fatal() { echo "[ERROR] $*" >&2; exit 1; }
ARTISAN_FILE="/var/www/html/artisan"
SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
NGINX_CONF_DIR="/etc/nginx/conf.d"
CUSTOM_NGINX_CONF="/var/www/html/conf/nginx"
CUSTOM_SUPERVISOR_CONF="/var/www/html/conf/worker/supervisor.conf"
DOCUMENT_ROOT="/var/www/html/public"
# Laravel Supervisor Setup
setup_laravel_supervisor() {
info "Artisan file found, creating Laravel supervisor config"
export DOCUMENT_ROOT
cat > "$SUPERVISOR_CONF_DIR/laravel-worker.conf" <<EOF
[program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d
command=/bin/sh -c "while [ true ]; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
command=/bin/sh -c "while true; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done"
autostart=true
autorestart=true
numprocs=1
@@ -49,55 +45,51 @@ if [ -f /var/www/html/artisan ]; then
redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log
EOF
info "Laravel supervisor config created"
else
info "artisan file not found"
fi
# Enable custom nginx config files if they exist
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then
cp /var/www/html/conf/nginx/nginx.conf /etc/nginx/nginx.conf
info "Laravel supervisor config created"
}
# Nginx Config Setup
setup_nginx_config() {
if [ -f "$CUSTOM_NGINX_CONF/nginx.conf" ]; then
cp "$CUSTOM_NGINX_CONF/nginx.conf" /etc/nginx/nginx.conf
info "Using custom nginx.conf"
fi
if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
if [ -f "$CUSTOM_NGINX_CONF/nginx-site.conf" ]; then
info "Custom nginx site config found"
rm /etc/nginx/conf.d/default.conf
cp /var/www/html/conf/nginx/nginx-site.conf /etc/nginx/conf.d/default.conf
rm -f "$NGINX_CONF_DIR/default.conf"
cp "$CUSTOM_NGINX_CONF/nginx-site.conf" "$NGINX_CONF_DIR/default.conf"
info "Start nginx with custom server config..."
else
info "nginx-site.conf not found"
info "If you want to use custom configs, create config file in /var/www/html/conf/nginx/nginx-site.conf"
info "If you want to use custom configs, create it at $CUSTOM_NGINX_CONF/nginx-site.conf"
info "Start nginx with default config..."
rm -f /etc/nginx/conf.d/default.conf
TASK=/etc/nginx/conf.d/default.conf
touch $TASK
cat > "$TASK" <<EOF
cat > "$NGINX_CONF_DIR/default.conf" <<EOF
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name $DOMAIN;
# Add index.php to setup Nginx, PHP & PHP-FPM config
index index.php index.html index.htm index.nginx-debian.html;
root $DOCUMENT_ROOT;
index index.php index.html index.htm;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root $DOCUMENT_ROOT;
# pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
location ~ \.php$ {
location ~ \.php\$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Nginx php-fpm config:
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info;
}
client_max_body_size $CLIENT_MAX_BODY_SIZE;
server_tokens off;
# Hide PHP headers
fastcgi_hide_header X-Powered-By;
fastcgi_hide_header X-CF-Powered-By;
fastcgi_hide_header X-Runtime;
@@ -106,27 +98,30 @@ if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then
try_files \$uri \$uri/ /index.php\$is_args\$args;
gzip_static on;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
# deny access to Apache .htaccess on Nginx with PHP,
# if Apache and Nginx document roots concur
location ~ \.css\$ { add_header Content-Type text/css; }
location ~ \.js\$ { add_header Content-Type application/x-javascript; }
location ~ /\.ht { deny all; }
location ~ /\.svn/ {deny all;}
location ~ /\.git/ {deny all;}
location ~ /\.hg/ {deny all;}
location ~ /\.bzr/ {deny all;}
location ~ /\.(svn|git|hg|bzr)/ { deny all; }
}
EOF
fi
## Check if the supervisor config file exists
if [ -f /var/www/html/conf/worker/supervisor.conf ]; then
info "Custom supervisor config found"
cp /var/www/html/conf/worker/supervisor.conf /etc/supervisor/conf.d/supervisor.conf
fi
## Start Supervisord
supervisord -c /etc/supervisor/supervisord.conf
}
# Load custom supervisor config if exists
load_custom_supervisor_config() {
if [ -f "$CUSTOM_SUPERVISOR_CONF" ]; then
info "Custom supervisor config found"
cp "$CUSTOM_SUPERVISOR_CONF" "$SUPERVISOR_CONF_DIR/supervisor.conf"
fi
}
# Main Execution
[ -f "$ARTISAN_FILE" ] && setup_laravel_supervisor || info "artisan file not found"
setup_nginx_config
load_custom_supervisor_config
# Start Supervisor
supervisord -c /etc/supervisor/supervisord.conf

0
version Normal file
View File