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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - 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 - name: Create Laravel project
run: | run: |
composer create-project laravel/laravel laravel composer create-project laravel/laravel laravel

View File

@@ -1,37 +1,33 @@
#!/bin/sh #!/bin/sh
set -e
echo "" echo ""
echo "***********************************************************" echo "***********************************************************"
echo " Starting NGINX PHP-FPM Docker Container " echo " Starting NGINX PHP-FPM Docker Container "
echo "***********************************************************" echo "***********************************************************"
set -e # Logging functions
set -e info() { echo "[INFO] $*"; }
info() { warning() { echo "[WARNING] $*"; }
{ set +x; } 2> /dev/null fatal() { echo "[ERROR] $*" >&2; exit 1; }
echo '[INFO] ' "$@"
} ARTISAN_FILE="/var/www/html/artisan"
warning() { SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
{ set +x; } 2> /dev/null NGINX_CONF_DIR="/etc/nginx/conf.d"
echo '[WARNING] ' "$@" CUSTOM_NGINX_CONF="/var/www/html/conf/nginx"
} CUSTOM_SUPERVISOR_CONF="/var/www/html/conf/worker/supervisor.conf"
fatal() { DOCUMENT_ROOT="/var/www/html/public"
{ set +x; } 2> /dev/null
echo '[ERROR] ' "$@" >&2 # Laravel Supervisor Setup
exit 1 setup_laravel_supervisor() {
} info "Artisan file found, creating Laravel supervisor config"
## Check if the artisan file exists export DOCUMENT_ROOT
if [ -f /var/www/html/artisan ]; then
info "Artisan file found, creating laravel supervisor config" cat > "$SUPERVISOR_CONF_DIR/laravel-worker.conf" <<EOF
# 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
[program:Laravel-scheduler] [program:Laravel-scheduler]
process_name=%(program_name)s_%(process_num)02d 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 autostart=true
autorestart=true autorestart=true
numprocs=1 numprocs=1
@@ -49,55 +45,51 @@ if [ -f /var/www/html/artisan ]; then
redirect_stderr=true redirect_stderr=true
stdout_logfile=/var/log/laravel_worker.log stdout_logfile=/var/log/laravel_worker.log
EOF EOF
info "Laravel supervisor config created"
else
info "artisan file not found"
fi
# Enable custom nginx config files if they exist info "Laravel supervisor config created"
if [ -f /var/www/html/conf/nginx/nginx.conf ]; then }
cp /var/www/html/conf/nginx/nginx.conf /etc/nginx/nginx.conf
# 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" info "Using custom nginx.conf"
fi 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" info "Custom nginx site config found"
rm /etc/nginx/conf.d/default.conf rm -f "$NGINX_CONF_DIR/default.conf"
cp /var/www/html/conf/nginx/nginx-site.conf /etc/nginx/conf.d/default.conf cp "$CUSTOM_NGINX_CONF/nginx-site.conf" "$NGINX_CONF_DIR/default.conf"
info "Start nginx with custom server config..." info "Start nginx with custom server config..."
else else
info "nginx-site.conf not found" 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..." info "Start nginx with default config..."
rm -f /etc/nginx/conf.d/default.conf
TASK=/etc/nginx/conf.d/default.conf cat > "$NGINX_CONF_DIR/default.conf" <<EOF
touch $TASK
cat > "$TASK" <<EOF
server { server {
listen 80 default_server; listen 80 default_server;
listen [::]:80 default_server; listen [::]:80 default_server;
server_name $DOMAIN; server_name $DOMAIN;
# Add index.php to setup Nginx, PHP & PHP-FPM config root $DOCUMENT_ROOT;
index index.php index.html index.htm index.nginx-debian.html; index index.php index.html index.htm;
error_log /var/log/nginx/error.log; error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.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; try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(/.+)\$;
# Nginx php-fpm config:
fastcgi_pass 127.0.0.1:9000; fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$fastcgi_path_info; fastcgi_param PATH_INFO \$fastcgi_path_info;
} }
client_max_body_size $CLIENT_MAX_BODY_SIZE; client_max_body_size $CLIENT_MAX_BODY_SIZE;
server_tokens off; server_tokens off;
# Hide PHP headers
fastcgi_hide_header X-Powered-By; fastcgi_hide_header X-Powered-By;
fastcgi_hide_header X-CF-Powered-By; fastcgi_hide_header X-CF-Powered-By;
fastcgi_hide_header X-Runtime; 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; try_files \$uri \$uri/ /index.php\$is_args\$args;
gzip_static on; gzip_static on;
} }
location ~ \.css {
add_header Content-Type text/css; location ~ \.css\$ { add_header Content-Type text/css; }
} location ~ \.js\$ { add_header Content-Type application/x-javascript; }
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 ~ /\.ht { deny all; } location ~ /\.ht { deny all; }
location ~ /\.svn/ {deny all;} location ~ /\.(svn|git|hg|bzr)/ { deny all; }
location ~ /\.git/ {deny all;}
location ~ /\.hg/ {deny all;}
location ~ /\.bzr/ {deny all;}
} }
EOF EOF
fi 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