Skip to content

A self-hosted media server and file management system

working docker file but with supervisord for now

aminnausindebb0a21aaa9
diff --git a/.dockerignore b/.dockerignore
index e84d6d71..bf2a90a8 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -3,19 +3,17 @@
.phpunit.cache
public/build
public/hot
-public/storage/
+public/storage
storage/*.key
storage/pail
-
-
storage/app/*
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
storage/logs/*
-storage/debugbar/
-
-bootstrap/cache/services.php
+storage/debugbar
+bootstrap/cache/*
+data
vendor
node_modules
.env
@@ -28,9 +26,7 @@ node_modules
.editorconfig
.dockerignore
.gitignore
-.git
-.git/
-
+.git/*
pint.json
commands.txt
diff --git a/.env.example b/.env.example
index 366dcb3f..c0dab58b 100755
--- a/.env.example
+++ b/.env.example
@@ -3,7 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=false
APP_TIMEZONE=UTC
-APP_URL=https://app.test:8080
+APP_URL=http://app.test:8080
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_CA
@@ -84,7 +84,7 @@ REVERB_HOST=app.test
REVERB_PORT=443
REVERB_SERVER_PORT=6002
REVERB_SERVER_HOST=0.0.0.0
-REVERB_SCHEME=https
+REVERB_SCHEME=http
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
diff --git a/Dockerfile b/Dockerfile
index 28a3cb27..0a7c5977 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,23 +1,54 @@
-FROM node:22 AS builder
-
-WORKDIR /var/www/html
-
-COPY package.json ./
-COPY package-lock.json ./
-
-RUN npm ci
-
-COPY . .
-
-RUN npm run build-only
-
-FROM jkaninda/nginx-php-fpm:8.3
+FROM php:8.3.16-fpm-alpine AS backend
+
+RUN apk update && apk add --no-cache \
+ bash \
+ git \
+ freetype-dev \
+ libjpeg-turbo-dev \
+ libpng-dev \
+ libwebp-dev \
+ libzip-dev \
+ oniguruma-dev \
+ postgresql-dev \
+ postgresql-client \
+ nodejs \
+ npm \
+ ffmpeg \
+ exiftool \
+ supervisor \
+ cronie
+
+# Install PHP extensions
+RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
+ && docker-php-ext-install gd \
+ && docker-php-ext-install pdo pdo_pgsql mbstring zip exif pcntl bcmath opcache
+
+# Install Composer
+COPY --from=composer/composer:latest-bin /composer /usr/bin/composer
+
+RUN echo "error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED" > /usr/local/etc/php/conf.d/error_reporting.ini
+
+# Create Supervisor directory
+RUN mkdir -p /etc/supervisor/conf.d
+
+# Copy Supervisor main config
+COPY docker/supervisor/supervisord.conf /etc/supervisord.conf
+# Copy Supervisor configuration
+COPY docker/supervisor/laravel-worker.conf /etc/supervisor/conf.d/laravel-worker.conf
+
+# Copy crontab file
+COPY docker/crontab /etc/crontabs/www-data
+
+# Ensure correct permissions
+RUN chmod 0644 /etc/crontabs/www-data
+
+RUN crond
WORKDIR /var/www/html
COPY . .
-RUN composer Install
+RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts
RUN chmod o+w ./storage/ -R
RUN chmod o+w ./public/ -R
@@ -29,8 +60,37 @@ RUN php artisan reverb:generate
RUN php artisan storage:link
-# RUN php artisan migrate
+FROM node:22 AS builder
+
+WORKDIR /var/www/html
+
+COPY package.json ./
+COPY package-lock.json ./
+
+# Copy application files again
+COPY --from=backend /var/www/html /var/www/html
+
+RUN npm ci
+
+
+RUN npm run build-only && \
+ npm cache clean --force && \
+ rm -rf node_modules
+
+
+FROM backend AS Final
COPY --from=builder /var/www/html/public/build ./public/build
-ENV DOCUMENT_ROOT=/var/www/html/public
+RUN chown -R www-data:www-data /var/www/html/
+RUN chmod -R 755 /var/www/html/
+
+USER www-data
+
+# Make storage folders mountable
+VOLUME [ "/var/www/html/storage" ]
+
+EXPOSE 9000
+ENTRYPOINT ["/var/www/html/docker/entrypoint.sh"]
+CMD ["supervisord", "-c", "/etc/supervisord.conf"]
+# CMD ["php-fpm"]
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index c6348f3e..62e50813 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -22,8 +22,6 @@ use Ramsey\Uuid\Uuid;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
-use function PHPUnit\Framework\isNull;
-
class VerifyFiles implements ShouldQueue {
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -252,7 +250,7 @@ class VerifyFiles implements ShouldQueue {
}
}
- if ((isNull($metadata->title) || $fileUpdated) && str_starts_with($mime_type, 'audio') && isset($audioMetadata['title'])) {
+ if ((is_null($metadata->title) || $fileUpdated) && str_starts_with($mime_type, 'audio') && isset($audioMetadata['title'])) {
$changes['title'] = $audioMetadata['title'];
}
diff --git a/docker-compose.yaml b/docker-compose.yaml
index 0a3f919b..66c54d38 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,101 +1,20 @@
services:
- # app:
- # build:
- # context: .
- # dockerfile: Dockerfile
- # container_name: MediaServer
- # volumes:
- # - ./data/media:/var/www/html/storage/public/media
- # # - type: bind
- # # source: ./media
- # # target: /storage/public/media
- # restart: unless-stopped
- # networks:
- # - docker-network
- # ports:
- # - 9000:9000
- # depends_on:
- # - db
- # environment:
- # - DB_HOST=db
- # - DB_PORT=5432
- # - DB_DATABASE=mediaServer
- # - DB_USERNAME=postgres
- # - DB_PASSWORD=root
- # # entrypoint: ['sh', '/usr/local/bin/entrypoint.sh']
-
- # # queue-worker:
- # # build:
- # # context: .
- # # dockerfile: Dockerfile
- # # restart: unless-stopped
- # # networks:
- # # - docker-network
- # # depends_on:
- # # - db
- # # - app
- # # command: php artisan queue:work
- # # pulse-worker:
- # # build:
- # # context: ./
- # # dockerfile: Dockerfile
- # # restart: unless-stopped
- # # networks:
- # # - docker-network
- # # depends_on:
- # # - db
- # # command: php artisan pulse:check
- # # reverb-worker:
- # # build:
- # # context: ./
- # # dockerfile: Dockerfile
- # # restart: unless-stopped
- # # networks:
- # # - docker-network
- # # ports:
- # # - 6001:6001
- # # depends_on:
- # # - db
- # # command: php artisan reverb:start
-
- # caddy:
- # image: caddy:2.9.1-alpine
- # ports:
- # - 8080:8080
- # # - 443:443
- # # - 443:443/udp
- # volumes:
- # - .:/var/www/html
- # - ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile
- # networks:
- # - docker-network
- # depends_on:
- # - app
- # nginx:
- # image: nginx:latest
- # container_name: nginx
- # volumes:
- # - ./:/var/www/html
- # - ./docker/nginx/app.conf:/etc/nginx/conf.d/default.conf
- # ports:
- # - "8000:80"
- # depends_on:
- # - app
- # networks:
- # - docker-network
-
app:
build:
context: .
dockerfile: Dockerfile
+ image: mediaserver:latest
container_name: MediaServer
volumes:
- - ./data/media:/var/www/html/storage/app/public/media
- # restart: unless-stopped
+ - app-public:/var/www/html/public
+ - ./data:/var/www/html/storage/app/public
+ restart: unless-stopped
networks:
- docker-network
ports:
- - 8080:80
+ - 9000:9000
+ expose:
+ - '9000'
depends_on:
- db
environment:
@@ -104,9 +23,102 @@ services:
- DB_DATABASE=mediaServer
- DB_USERNAME=postgres
- DB_PASSWORD=root
- # entrypoint: ['sh', '/var/www/html/docker/entrypoint.sh']
+ # queue:
+ # image: mediaserver:latest # Reuse the built image
+ # container_name: job_queue
+ # command: php artisan queue:work --timeout=3600 --tries=3
+ # restart: unless-stopped
+ # tty: true
+ # volumes:
+ # - ./data:/var/www/html/storage/app/public
+ # networks:
+ # - docker-network
+ # depends_on:
+ # - app
+ # event-queue:
+ # image: mediaserver:latest # Reuse the built image
+ # container_name: event_queue
+ # command: php artisan queue:work --queue=high --tries=3
+ # restart: unless-stopped
+ # tty: true
+ # volumes:
+ # - ./data:/var/www/html/storage/app/public
+ # networks:
+ # - docker-network
+ # depends_on:
+ # - app
+ # scheduler:
+ # image: mediaserver:latest # Reuse the built image
+ # container_name: laravel_scheduler
+ # command: php artisan schedule:work
+ # restart: unless-stopped
+ # tty: true
+ # volumes:
+ # - ./data:/var/www/html/storage/app/public
+ # networks:
+ # - docker-network
+ # depends_on:
+ # - app
+ # pulse:
+ # image: mediaserver:latest # Reuse the built image
+ # container_name: pulse
+ # command: php artisan pulse:check
+ # restart: unless-stopped
+ # tty: true
+ # volumes:
+ # - ./data:/var/www/html/storage/app/public
+ # networks:
+ # - docker-network
+ # depends_on:
+ # - app
+ # ws:
+ # image: mediaserver:latest # Reuse the built image
+ # container_name: ws
+ # command: php artisan reverb:start
+ # restart: unless-stopped
+ # tty: true
+ # volumes:
+ # - ./data:/var/www/html/storage/app/public
+ # ports:
+ # - 6001:6001
+ # expose:
+ # - '6001'
+ # networks:
+ # - docker-network
+ # depends_on:
+ # - app
+
+ nginx:
+ image: nginx:alpine
+ container_name: nginx
+ volumes:
+ - ./docker/nginx/app.conf:/etc/nginx/conf.d/default.conf
+ - ./data:/var/www/html/storage/app/public
+ - app-public:/var/www/html/public
+ ports:
+ - '8080:8080'
+ expose:
+ - '8080'
+ depends_on:
+ - app
+ networks:
+ - docker-network
+ caddy:
+ image: caddy:2.9.1-alpine
+ container_name: caddy
+ ports:
+ - 80:80
+ - 443:443
+ - 443:443/udp
+ volumes:
+ - ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile
+ networks:
+ - docker-network
+ depends_on:
+ - nginx
db:
image: bitnami/postgresql:17.2.0
+ container_name: database
platform: linux/amd64
ports:
- 5432:5432
@@ -122,6 +134,9 @@ services:
volumes:
db-data:
+ driver: local
+ app-public:
+ driver: local
networks:
docker-network:
diff --git a/docker/caddy/CaddyFile b/docker/caddy/CaddyFile
index 6433ab55..5c42697b 100644
--- a/docker/caddy/CaddyFile
+++ b/docker/caddy/CaddyFile
@@ -1,21 +1,10 @@
-http://app.test:8080 {
- root * /var/www/html/public
- encode gzip
-
- php_fastcgi app:9000
-
- file_server
-
- handle_errors {
- @404 {
- method GET
- not file
- path not *
- }
- rewrite @404 /index.php
- }
+{
+ auto_https off
+ debug
+}
- handle_errors {
- rewrite * /index.php
- }
+app.test {
+ reverse_proxy nginx:8080
+ encode gzip
+ tls internal
}
diff --git a/docker/crontab/cron b/docker/crontab/cron
new file mode 100644
index 00000000..efe22744
--- /dev/null
+++ b/docker/crontab/cron
@@ -0,0 +1 @@
+* * * * * php /var/www/html/artisan schedule:run >> /var/www/html/storage/logs/scheduler.log 2>&1
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
index 6ac01457..338095d7 100644
--- a/docker/entrypoint.sh
+++ b/docker/entrypoint.sh
@@ -1,24 +1,20 @@
#!/bin/bash
-# RUN npm i
-# npm run build-only
-# npm cache clean --force
-# rm -rf node_modules
-# "Installing Composer (PHP) dependencies"
-# composer install
-# "Setup environment variables"
-cp .env.example .env
+# Exit immediately if a command exits with a non-zero status
+set -e
-# "Setup Laravel app key"
-php artisan key:generate
+echo "Waiting for PostgreSQL to be ready..."
-# "Setup Reverb app keys"
-php artisan reverb:generate
+# Loop until PostgreSQL is ready
+until PGPASSWORD=$DB_PASSWORD psql -h "$DB_HOST" -U "$DB_USERNAME" -d "$DB_DATABASE" -c "SELECT 1" > /dev/null 2>&1; do
+ echo "PostgreSQL is unavailable - sleeping..."
+ sleep 2
+done
-# Link Storage
-php artisan storage:link
-
-# "Setup a database connection in the .env file and then run 'php artisan migrate'"
-# "Finally run 'npm run vite:php' to start the queue and websocket servers in addition to your web server (nginx)"
php artisan migrate
+
+# Start Supervisor in the background
+echo "Starting Supervisor..."
+
+exec "$@"
diff --git a/docker/nginx/app.conf b/docker/nginx/app.conf
index 7921b650..ed5c17c6 100644
--- a/docker/nginx/app.conf
+++ b/docker/nginx/app.conf
@@ -1,14 +1,15 @@
server {
- listen 80;
- server_name app.test;
+ listen 8080;
+ server_name app.test *.app.test;
+ root /var/www/html/public;
+
+ index index.php index.html;
+ error_log /var/log/nginx/error.log;
+ access_log /var/log/nginx/access.log;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
- index index.php;
-
- root /var/www/html/public;
-
location /app {
proxy_http_version 1.1;
proxy_set_header Host $host;
@@ -22,41 +23,46 @@ server {
proxy_pass http://0.0.0.0:6001;
}
+ include mime.types;
+
location / {
try_files $uri $uri/ /index.php?$query_string;
autoindex off;
+ gzip_static on;
}
location ~ \.php$ {
+ include fastcgi_params;
+ try_files $uri =404;
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
+ # try_files $fastcgi_script_name =404;
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- try_files $fastcgi_script_name =404;
-
- set $path_info $fastcgi_path_info;
- fastcgi_param PATH_INFO $path_info;
- fastcgi_read_timeout 3600;
-
+ fastcgi_pass app:9000;
fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ fastcgi_param PATH_INFO $fastcgi_path_info;
- # include fastcgi.conf;
- include fastcgi_params;
-
-
- fastcgi_pass app:9000;
+ fastcgi_read_timeout 3600;
fastcgi_hide_header X-Powered-By;
}
charset utf-8;
- location = /favicon.ico { access_log off; log_not_found off; }
- location = /robots.txt { access_log off; log_not_found off; }
+ location = /favicon.ico {
+ access_log off;
+ log_not_found off;
+ }
+ location = /robots.txt {
+ access_log off;
+ log_not_found off;
+ }
location ~ /\.(?!well-known).* {
deny all;
}
- location /storage/media/ {
+ location /storage/ {
valid_referers app.test ;
if ($invalid_referer) {
return 403;
diff --git a/docker/supervisor/laravel-worker.conf b/docker/supervisor/laravel-worker.conf
new file mode 100644
index 00000000..d5b9099b
--- /dev/null
+++ b/docker/supervisor/laravel-worker.conf
@@ -0,0 +1,32 @@
+[supervisord]
+nodaemon=true
+
+[program:php-fpm]
+command=php-fpm --nodaemonize
+autostart=true
+autorestart=true
+stopsignal=QUIT # ✅ Ensure PHP-FPM stops gracefully
+
+[program:queue-worker]
+command=php /var/www/html/artisan queue:work --timeout=3600 --tries=3
+autostart=true
+autorestart=true
+redirect_stderr=true
+stdout_logfile=/var/www/html/storage/logs/queue-worker.log
+stopsignal=TERM
+
+[program:event-queue-worker]
+command=php /var/www/html/artisan queue:work --queue=high --tries=3
+autostart=true
+autorestart=true
+redirect_stderr=true
+stdout_logfile=/var/www/html/storage/logs/event-queue-worker.log
+stopsignal=TERM
+
+[program:reverb]
+command=php /var/www/html/artisan reverb:start
+autostart=true
+autorestart=true
+redirect_stderr=true
+stdout_logfile=/var/www/html/storage/logs/reverb.log
+stopsignal=TERM
diff --git a/docker/supervisor/supervisord.conf b/docker/supervisor/supervisord.conf
new file mode 100644
index 00000000..a951685a
--- /dev/null
+++ b/docker/supervisor/supervisord.conf
@@ -0,0 +1,5 @@
+[supervisord]
+nodaemon=true
+
+[include]
+files = /etc/supervisor/conf.d/*.conf
diff --git a/routes/console.php b/routes/console.php
index f654987e..b8ca9d63 100755
--- a/routes/console.php
+++ b/routes/console.php
@@ -10,4 +10,5 @@ use Illuminate\Support\Facades\Schedule;
// })->purpose('Display an inspiring quote')->hourly();
Schedule::job(new ScheduledIndexFiles)->everySixHours()->environments(['staging', 'production']);
+Schedule::command('pulse:check')->everyMinute();
Schedule::command('sanctum:prune-expired --hours=2')->daily();