add docker

This commit is contained in:
arifal hidayat
2025-06-06 22:42:41 +07:00
parent 6f77120c33
commit 9437eb949f
16 changed files with 305 additions and 24 deletions

View File

@@ -0,0 +1,50 @@
server {
listen 80;
index index.php index.html;
server_name localhost;
root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Proxy Vite requests in development
location /@vite {
proxy_pass http://vite:5173;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /build/ {
alias /var/www/public/build/;
access_log off;
expires max;
}
location /assets/ {
alias /var/www/public/assets/;
access_log off;
expires max;
}
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ /\.ht {
deny all;
}
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot|otf)$ {
expires max;
log_not_found off;
}
}

59
docker/startup.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
# Enable error reporting
set -e
set -x
# Create necessary directories with proper permissions as root
mkdir -p /var/log/supervisor
mkdir -p /var/run/supervisor
chown -R www-data:www-data /var/log/supervisor
chown -R www-data:www-data /var/run/supervisor
chmod -R 775 /var/log/supervisor
chmod -R 775 /var/run/supervisor
# Create storage directories with proper permissions
mkdir -p /var/www/storage/logs
chown -R www-data:www-data /var/www/storage
chmod -R 775 /var/www/storage
# Ensure Laravel storage and cache directories are writable
chown -R www-data:www-data /var/www/bootstrap/cache
chmod -R 775 /var/www/bootstrap/cache
# Wait for database to be ready (with increased timeout and better error handling)
max_tries=30
count=0
echo "Waiting for database connection..."
# First, wait a bit for the database container to fully initialize
sleep 10
while ! php artisan db:monitor > /dev/null 2>&1; do
count=$((count + 1))
if [ $count -gt $max_tries ]; then
echo "Database connection timeout after $max_tries attempts"
echo "Checking database container status..."
# Try to connect directly to MySQL to get more detailed error
mysql -h db -u admindb_arifal -parifal201 -e "SELECT 1" || true
exit 1
fi
echo "Waiting for database... ($count/$max_tries)"
sleep 5
done
echo "Database connection established!"
# Run database-dependent commands
echo "Running database migrations..."
php artisan migrate --force
echo "Running database seeders..."
php artisan db:seed --force
echo "Optimizing Laravel..."
php artisan optimize:clear
php artisan optimize
# Start supervisor (which will manage PHP-FPM)
exec /usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf

View File

@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/artisan queue:work --queue=default --timeout=82800 --tries=1
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/storage/logs/worker.log
stopasgroup=true
killasgroup=true
user=www-data
priority=10