From b12d41b07dd26e599f828083ebc007f648af12c3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 12 Nov 2025 13:48:36 +1100 Subject: [PATCH] Docker setup improvements and fixes --- .dockerignore | 25 +++++++----- DOCKER_SETUP.md | 41 ++++++++----------- Dockerfile | 9 ++-- composer.lock | 12 +++--- docker-compose.yml | 100 +++++++++++++++++++++++++++++++-------------- 5 files changed, 111 insertions(+), 76 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5b2c909ad..0f26bb37e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,19 +1,22 @@ -.git +# Folders +.git/ +tests/ +mariadb-11-data/ +redis-data/ +node_modules/ +vendor/ +storage/ +bootstrap/cache/ +.ddev/ + +#Files .gitignore .env .env.* -!.env.docker -node_modules -vendor -storage/logs/* -storage/framework/cache/* -storage/framework/sessions/* -storage/framework/views/* -bootstrap/cache/* -.ddev +.env.example +.env.docker.example docker-compose.yml Dockerfile README.md .editorconfig .phpunit.result.cache -tests diff --git a/DOCKER_SETUP.md b/DOCKER_SETUP.md index 90cfa9a28..e6d2e942b 100644 --- a/DOCKER_SETUP.md +++ b/DOCKER_SETUP.md @@ -12,26 +12,33 @@ This setup uses `serversideup/php:8.4-fpm-nginx` as the base image and is design 1. **Copy the environment file:** ```bash - cp .env.docker.example .env.docker + cp .env.docker.example .env ``` -2. **Update `.env.docker` with your configuration:** - - Set `APP_KEY` (generate with: `docker compose run --rm pixelfed php artisan key:generate --show`) +2. **Update `.env` with your configuration:** + - Set `APP_KEY` ( generate with https://laravel-encryption-key-generator.vercel.app/ ) - Update `APP_URL`, `APP_DOMAIN`, `ADMIN_DOMAIN`, `SESSION_DOMAIN` with your domain - Set secure database passwords for `DB_PASSWORD` and `DB_ROOT_PASSWORD` - Configure mail settings -3. **Build and start the containers:** +3. **Build container** + ```bash + docker compose build + ``` + +4. **Build and start the containers:** ```bash docker compose up -d ``` -4. **Generate application key (if not done in step 2):** +5. **Generate application key (if not done in step 2):** ```bash - docker compose exec pixelfed php artisan key:generate + docker compose exec pixelfed php artisan instance:actor + docker compose exec pixelfed php artisan import:cities + docker compose exec pixelfed php artisan passport:keys ``` -5. **Create admin user:** +6. **Create admin user:** ```bash docker compose exec pixelfed php artisan user:create ``` @@ -77,25 +84,11 @@ server { } ``` -## Services - -- **pixelfed:** Main application (port 8080) -- **db:** MariaDB 11 database -- **redis:** Redis cache and queue backend -- **horizon:** Laravel Horizon queue worker - -## Volumes - -- `db-data`: Database persistence -- `redis-data`: Redis persistence -- `./storage`: Application storage (uploads, cache, logs) -- `./bootstrap/cache`: Laravel bootstrap cache - ## Useful Commands ```bash # View logs -docker compose logs -f pixelfed +docker compose logs -f # Run artisan commands docker compose exec pixelfed php artisan [command] @@ -144,6 +137,6 @@ docker compose exec pixelfed php artisan view:clear ``` ### Database Connection Issues -- Verify database credentials in `.env.docker` +- Verify database credentials in `.env` - Check if database container is running: `docker compose ps` -- View database logs: `docker compose logs db` +- View database logs: `docker compose logs -f db` diff --git a/Dockerfile b/Dockerfile index 3ec57cca2..c68332c31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,20 +31,21 @@ RUN install-php-extensions \ zip \ pdo_mysql \ redis \ - vips + vips \ + ffi # Copy application files COPY --chown=www-data:www-data . /var/www/html -# Install composer dependencies -RUN composer install --no-dev --optimize-autoloader --no-interaction - # Set proper permissions RUN chown -R www-data:www-data /var/www/html \ && find /var/www/html -type f -exec chmod 644 {} \; \ && find /var/www/html -type d -exec chmod 755 {} \; \ && chmod -R ug+rwx /var/www/html/storage /var/www/html/bootstrap/cache +# Install composer dependencies +RUN composer install --no-ansi --no-interaction --optimize-autoloader + # Switch back to www-data user USER www-data diff --git a/composer.lock b/composer.lock index 7f36813c2..935696543 100644 --- a/composer.lock +++ b/composer.lock @@ -62,16 +62,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.359.9", + "version": "3.359.10", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "754b25dae2f50b568b55735931a3cd73263ac5ae" + "reference": "10989892e99083c73e8421b85b5d6f7d2ca0f2f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/754b25dae2f50b568b55735931a3cd73263ac5ae", - "reference": "754b25dae2f50b568b55735931a3cd73263ac5ae", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/10989892e99083c73e8421b85b5d6f7d2ca0f2f5", + "reference": "10989892e99083c73e8421b85b5d6f7d2ca0f2f5", "shasum": "" }, "require": { @@ -153,9 +153,9 @@ "support": { "forum": "https://github.com/aws/aws-sdk-php/discussions", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.359.9" + "source": "https://github.com/aws/aws-sdk-php/tree/3.359.10" }, - "time": "2025-11-10T19:14:56+00:00" + "time": "2025-11-11T19:08:54+00:00" }, { "name": "bacon/bacon-qr-code", diff --git a/docker-compose.yml b/docker-compose.yml index 09da76857..0968471af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,32 @@ -version: '3.8' - services: +## MariaDB and Redis (optional) + db: + image: mariadb:11 + container_name: pixelfed-db + restart: unless-stopped + env_file: + - .env + environment: + MARIADB_DATABASE: ${DB_DATABASE} + MARIADB_USER: ${DB_USERNAME} + MARIADB_PASSWORD: ${DB_PASSWORD} + MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} + volumes: + - ./mariadb-11-data:/var/lib/mysql + networks: + - pixelfed-network + + redis: + image: redis:7-alpine + container_name: pixelfed-redis + restart: unless-stopped + command: redis-server --appendonly yes + volumes: + - ./redis-data:/data + networks: + - pixelfed-network + +## Pixelfed containers - App (Web/API), Horizon Queue, Scheduled task. pixelfed: build: context: . @@ -10,10 +36,12 @@ services: ports: - "8080:8080" env_file: - - .env.docker + - .env environment: + # SSL Configuration (handled by reverse proxy) + SSL_MODE: "off" + # PHP Configuration - AUTORUN_LARAVEL_MIGRATION_ISOLATION: "true" PHP_POST_MAX_SIZE: "500M" PHP_UPLOAD_MAX_FILE_SIZE: "500M" PHP_OPCACHE_ENABLE: "1" @@ -21,14 +49,13 @@ services: # Laravel Auto-run Configuration AUTORUN_ENABLED: "true" AUTORUN_LARAVEL_MIGRATION: "true" + AUTORUN_LARAVEL_MIGRATION_ISOLATION: "true" AUTORUN_LARAVEL_STORAGE_LINK: "true" AUTORUN_LARAVEL_EVENT_CACHE: "true" AUTORUN_LARAVEL_ROUTE_CACHE: "true" AUTORUN_LARAVEL_VIEW_CACHE: "true" AUTORUN_LARAVEL_CONFIG_CACHE: "true" - - # SSL Configuration (handled by reverse proxy) - SSL_MODE: "off" + volumes: - ./storage:/var/www/html/storage - ./bootstrap/cache:/var/www/html/bootstrap/cache @@ -38,43 +65,51 @@ services: networks: - pixelfed-network - db: - image: mariadb:11 - container_name: pixelfed-db + horizon: + build: + context: . + dockerfile: Dockerfile + container_name: pixelfed-horizon restart: unless-stopped + command: ["php", "/var/www/html/artisan", "horizon"] env_file: - - .env.docker + - .env environment: - MYSQL_DATABASE: ${DB_DATABASE} - MYSQL_USER: ${DB_USERNAME} - MYSQL_PASSWORD: ${DB_PASSWORD} - MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} - volumes: - - ./mariadb-11-data:/var/lib/mysql - networks: - - pixelfed-network - - redis: - image: redis:7-alpine - container_name: pixelfed-redis - restart: unless-stopped - command: redis-server --appendonly yes + # Laravel Auto-run Configuration + AUTORUN_LARAVEL_STORAGE_LINK: "true" + AUTORUN_LARAVEL_EVENT_CACHE: "true" + AUTORUN_LARAVEL_ROUTE_CACHE: "true" + AUTORUN_LARAVEL_VIEW_CACHE: "true" + AUTORUN_LARAVEL_CONFIG_CACHE: "true" + PHP_POST_MAX_SIZE: "500M" + PHP_UPLOAD_MAX_FILE_SIZE: "500M" + PHP_OPCACHE_ENABLE: "1" volumes: - - ./redis-data:/data + - ./storage:/var/www/html/storage + - ./bootstrap/cache:/var/www/html/bootstrap/cache + depends_on: + - db + - redis networks: - pixelfed-network - horizon: + scheduler: build: context: . dockerfile: Dockerfile - container_name: pixelfed-horizon + container_name: pixelfed-scheduler restart: unless-stopped - command: php artisan horizon + command: ["php", "/var/www/html/artisan", "schedule:work"] + stop_signal: SIGTERM env_file: - - .env.docker + - .env environment: - AUTORUN_ENABLED: "false" + # Laravel Auto-run Configuration + AUTORUN_LARAVEL_STORAGE_LINK: "true" + AUTORUN_LARAVEL_EVENT_CACHE: "true" + AUTORUN_LARAVEL_ROUTE_CACHE: "true" + AUTORUN_LARAVEL_VIEW_CACHE: "true" + AUTORUN_LARAVEL_CONFIG_CACHE: "true" PHP_POST_MAX_SIZE: "500M" PHP_UPLOAD_MAX_FILE_SIZE: "500M" PHP_OPCACHE_ENABLE: "1" @@ -84,6 +119,9 @@ services: depends_on: - db - redis + healthcheck: + test: ["CMD", "healthcheck-schedule"] + start_period: 10s networks: - pixelfed-network