diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c514872 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +.git +.gitignore +.github +node_modules +vendor +public/build +public/hot +.env +.env.* +storage/logs/* +storage/framework/cache/data/* +storage/framework/sessions/* +storage/framework/views/* +tests +.phpunit.result.cache +.DS_Store +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ab4ee58 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# syntax=docker/dockerfile:1 + +# ---------- Stage 1: Frontend assets (Vite + Tailwind) ---------- +FROM node:20-alpine AS assets +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY resources ./resources +COPY vite.config.js ./ +COPY public ./public +RUN npm run build + +# ---------- Stage 2: PHP runtime (php-fpm + nginx) ---------- +FROM serversideup/php:8.3-fpm-nginx AS app + +# Install PHP extensions the app needs +USER root +RUN install-php-extensions \ + pdo_mysql \ + bcmath \ + gd \ + intl \ + zip \ + exif \ + pcntl \ + redis \ + opcache + +WORKDIR /var/www/html + +# Composer dependencies first (better layer caching) +COPY --chown=www-data:www-data composer.json composer.lock ./ +RUN composer install \ + --no-dev \ + --no-scripts \ + --no-autoloader \ + --prefer-dist \ + --no-interaction + +# Application source +COPY --chown=www-data:www-data . . + +# Compiled frontend assets from stage 1 +COPY --chown=www-data:www-data --from=assets /app/public/build ./public/build + +# Optimize autoloader +RUN composer dump-autoload --optimize --no-dev --no-interaction + +# Runtime init (migrate + cache) runs on container start +COPY --chown=www-data:www-data docker/entrypoint.d/ /etc/entrypoint.d/ +RUN chmod +x /etc/entrypoint.d/*.sh + +USER www-data diff --git a/docker/entrypoint.d/99-laravel-init.sh b/docker/entrypoint.d/99-laravel-init.sh new file mode 100755 index 0000000..2580965 --- /dev/null +++ b/docker/entrypoint.d/99-laravel-init.sh @@ -0,0 +1,16 @@ +#!/command/with-contenv bash +# Runs on every container start (after DB/Redis are reachable on the Coolify network). +set -e + +cd /var/www/html + +# Storage symlink (idempotent) +php artisan storage:link 2>/dev/null || true + +# Run pending migrations +php artisan migrate --force --no-interaction || true + +# Cache config/routes/views for production speed +php artisan config:cache +php artisan route:cache +php artisan view:cache