From b532c51c32f7ba93920b83302587dafbd9f0e323 Mon Sep 17 00:00:00 2001 From: Alexander Gabriel Date: Thu, 2 Jul 2026 20:22:24 +0000 Subject: [PATCH] added docker-compose file for production --- .dockerignore | 42 ++++++++++++++++++++++++++ Dockerfile | 54 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 41 ++++++++++++++++++++++++++ docker/apache/000-default.conf | 12 ++++++++ docker/entrypoint.sh | 23 +++++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker/apache/000-default.conf create mode 100644 docker/entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8813d7b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,42 @@ +.git +.gitattributes +.github + +.env +.env.* +auth.json + +node_modules +vendor + +public/build +public/hot +public/storage + +storage/*.key +storage/app/* +storage/framework/cache/* +storage/framework/sessions/* +storage/framework/testing/* +storage/framework/views/* +storage/logs/* +storage/pail +!storage/app/.gitignore +!storage/framework/**/.gitignore +!storage/logs/.gitignore + +database/database.sqlite + +tests +.phpunit.cache +.phpunit.result.cache + +.devcontainer +.claude +.idea +.vscode +.fleet +.zed + +docker-compose.yml +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..867c593 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +# syntax=docker/dockerfile:1.7 +ARG PHP_VERSION=8.5 + +# --- frontend assets ------------------------------------------------------- +FROM node:22-alpine AS frontend +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci +COPY vite.config.js ./ +COPY resources ./resources +RUN npm run build + +# --- application ------------------------------------------------------- +FROM php:${PHP_VERSION}-apache AS app + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libsqlite3-dev \ + libicu-dev \ + libzip-dev \ + unzip \ + git \ + curl \ + && docker-php-ext-install \ + pdo_sqlite \ + intl \ + zip \ + bcmath \ + pcntl \ + opcache \ + && a2enmod rewrite \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + +COPY docker/apache/000-default.conf /etc/apache2/sites-available/000-default.conf +COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +WORKDIR /var/www/html + +COPY . . +COPY --from=frontend /app/public/build ./public/build + +# auth.json holds the Filament composer repository credentials; it's +# gitignored and must never end up baked into an image layer, so it's +# supplied as a BuildKit secret and mounted only for this RUN step. +RUN --mount=type=secret,id=composer_auth,target=/var/www/html/auth.json \ + composer install --no-dev --no-interaction --no-progress --optimize-autoloader + +RUN mkdir -p storage/app storage/framework/cache storage/framework/sessions storage/framework/views storage/logs bootstrap/cache \ + && chown -R www-data:www-data storage bootstrap/cache + +ENTRYPOINT ["entrypoint.sh"] +CMD ["apache2-foreground"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..75dbbbb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +x-app: &app + image: z-lab-cockpit:latest + env_file: .env + # environment: + # DB_CONNECTION: sqlite + # DB_DATABASE: /var/www/html/storage/app/database.sqlite + volumes: + - ./storage:/var/www/html/storage + depends_on: + app: + condition: service_healthy + restart: unless-stopped + +services: + app: + <<: *app + build: + context: . + secrets: + - composer_auth + depends_on: [] + ports: + - "8000:80" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost/up"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s + + queue: + <<: *app + command: ["php", "artisan", "queue:work", "--tries=3", "--backoff=10"] + + scheduler: + <<: *app + command: ["php", "artisan", "schedule:work"] + +secrets: + composer_auth: + file: ./auth.json diff --git a/docker/apache/000-default.conf b/docker/apache/000-default.conf new file mode 100644 index 0000000..52aa052 --- /dev/null +++ b/docker/apache/000-default.conf @@ -0,0 +1,12 @@ + + DocumentRoot /var/www/html/public + + + Options -Indexes +FollowSymLinks + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..65bba91 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +cd /var/www/html + +mkdir -p storage/app storage/framework/cache storage/framework/sessions storage/framework/views storage/logs bootstrap/cache +chown -R www-data:www-data storage bootstrap/cache + +if [ -n "$DB_DATABASE" ] && [ "$DB_CONNECTION" = "sqlite" ]; then + mkdir -p "$(dirname "$DB_DATABASE")" + touch -a "$DB_DATABASE" + chown www-data:www-data "$DB_DATABASE" +fi + +# Only the web process runs bootstrap steps, so the queue/scheduler +# containers (which override CMD) don't race each other on migrations. +if [ "$1" = "apache2-foreground" ]; then + php artisan config:clear + php artisan migrate --force + php artisan storage:link || true +fi + +exec "$@"