Skip to content

A self-hosted media server and file management system

use new docker image base

aminnausinb2dafe6d49d4
diff --git a/.gitignore b/.gitignore
index 71060506..94b5359c 100755
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@ storage/logs/*
/old
/pulsesrc
/data
+install.sh
diff --git a/Dockerfile b/Dockerfile
index 185d3ec5..aa498267 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,95 +1,117 @@
-FROM php:8.3.16-fpm-alpine AS composer
+# Versions
+# https://hub.docker.com/r/serversideup/php/tags?name=8.4-fpm-nginx-alpine
+ARG SERVERSIDEUP_PHP_VERSION=8.4-fpm-nginx-alpine
+# https://www.postgresql.org/support/versioning/
+ARG POSTGRES_VERSION=17
-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
-
-# 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
+# Add user/group
+ARG USER_ID=9999
+ARG GROUP_ID=9999
-WORKDIR /var/www/html
+# =================================================================
+# 1: Install composer dependencies
+# =================================================================
+FROM serversideup/php:${SERVERSIDEUP_PHP_VERSION} AS composer
-COPY composer.lock composer.lock
-COPY composer.json composer.json
-RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts
+USER root
-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 \
- ffmpeg \
- exiftool
+ARG USER_ID
+ARG GROUP_ID
-# 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
+RUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \
+ docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx
WORKDIR /var/www/html
+COPY --chown=www-data:www-data composer.json composer.lock ./
+RUN composer install --no-dev --no-interaction --no-plugins --no-scripts --prefer-dist
-COPY . .
-
-COPY --from=composer /var/www/html/vendor ./vendor
-
-RUN chmod o+w ./storage/ -R
-RUN chmod o+w ./public/ -R
-
-# Copy .env and set up Laravel
-RUN cp .env.example .env && php artisan storage:link
+USER www-data
+# =================================================================
+# 2: Build Frontend
+# =================================================================
FROM node:22 AS builder
WORKDIR /var/www/html
-COPY package.json package-lock.json ./
+COPY . .
RUN npm ci
-# Copy application files again
-COPY --from=backend /var/www/html /var/www/html
-
RUN npm run build-only && \
npm cache clean --force && \
rm -rf node_modules
+# =================================================================
+# 3: Compile Laravel Image
+# =================================================================
+FROM serversideup/php:${SERVERSIDEUP_PHP_VERSION}
+
+ARG USER_ID
+ARG GROUP_ID
+ARG POSTGRES_VERSION
+
+WORKDIR /var/www/html
+
+USER root
+
+RUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \
+ docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx
+
+# Install PostgreSQL repository and keys for external access
+RUN apk add --no-cache gnupg && \
+ mkdir -p /usr/share/keyrings && \
+ curl -fSsL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /usr/share/keyrings/postgresql.gpg
+
+RUN apk update && apk add --no-cache \
+ git \
+ vim \
+ ffmpeg \
+ exiftool
+
+# Useful shell aliases
+RUN echo "alias ll='ls -al'" >> /etc/profile && \
+ echo "alias a='php artisan'" >> /etc/profile && \
+ echo "alias logs='tail -f storage/logs/laravel.log'" >> /etc/profile
+
+# Configure PHP
+COPY docker/etc/php/conf.d/zzz-custom-php.ini /usr/local/etc/php/conf.d/zzz-custom-php.ini
+ENV PHP_OPCACHE_ENABLE=1
+
+# Configure entrypoint
+COPY --chmod=755 docker/entrypoint.d/ /etc/entrypoint.d
+
+# Copy dependencies
+COPY --from=composer --chown=www-data:www-data /var/www/html/vendor ./vendor
+COPY --from=builder --chown=www-data:www-data /var/www/html/public/build ./public/build
+
+COPY --chown=www-data:www-data . .
+
+RUN composer dump-autoload
+
+RUN chmod o+w ./storage/ -R
+# RUN chmod o+w ./public/ -R
+
+# Copy .env and set up Laravel
+COPY --chown=www-data:www-data .env.example .env
-FROM backend AS final
+# Nginx
+# COPY docker/etc/nginx/site-opts.d/http.conf /etc/nginx/site-opts.d/http.conf
+COPY docker/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
+RUN chown -R www-data:www-data /etc/nginx && \
+ chmod -R 755 /etc/nginx
-COPY --from=builder /var/www/html/public/build ./public/build
+ENV AUTORUN_ENABLED=true
+ENV AUTORUN_LARAVEL_CONFIG_CACHE=false
-# Set correct permissions
-RUN chown -R www-data:www-data /var/www/html && chmod -R 755 /var/www/html
+# RUN chown -R www-data:www-data /var/www/html && chmod -R 755 /var/www/html
# Clean up unnecessary files
-RUN rm -rf node_modules vendor/bin ~/.composer/cache /usr/local/bin/composer
+# RUN rm vendor/bin ~/.composer/cache /usr/local/bin/composer
# Make storage folders mountable
VOLUME [ "/var/www/html/storage" ]
USER www-data
-EXPOSE 9000
-ENTRYPOINT ["/var/www/html/docker/entrypoint.sh"]
-# CMD ["supervisord", "-c", "/etc/supervisord.conf"]
-CMD ["php-fpm"]
+# ENTRYPOINT ["/var/www/html/docker/entrypoint.sh"]
+# CMD ["php-fpm"]
diff --git a/docker/.env.docker b/docker/.env.docker
index dcb3bedf..95b6fd16 100644
--- a/docker/.env.docker
+++ b/docker/.env.docker
@@ -6,7 +6,7 @@ REVERB_SCHEME=http # Websocket Protocol -> http OR https -> Set to HTTPS if
APP_ENV=staging
-DB_HOST=db
+DB_HOST=database
DB_PORT=5432
DB_DATABASE=mediaServer
DB_USERNAME=postgres
diff --git a/docker/entrypoint.d/keys.sh b/docker/entrypoint.d/keys.sh
new file mode 100644
index 00000000..3079387f
--- /dev/null
+++ b/docker/entrypoint.d/keys.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+
+# Exit immediately if a command exits with a non-zero status
+set -e
+
+if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:" ]; then
+ echo "No APP_KEY detected, generating one..."
+ php artisan key:generate
+else
+ echo "APP_KEY already set, skipping key generation."
+fi
+
+php artisan reverb:generate
+
+# echo "Waiting for PostgreSQL to be ready..."
+
+# # 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
+
+# php artisan migrate
+
+# Start Supervisor in the background
+# echo "Starting Supervisor..."
+
+# exec "$@"
diff --git a/docker/etc/caddy/CaddyFile b/docker/etc/caddy/CaddyFile
new file mode 100644
index 00000000..3fbecb3e
--- /dev/null
+++ b/docker/etc/caddy/CaddyFile
@@ -0,0 +1,10 @@
+app.test {
+ reverse_proxy nginx:8086 {
+ header_up X-Forwarded-For {remote}
+ header_up X-Real-IP {remote}
+ header_up X-Forwarded-Proto {scheme}
+ header_up Host {host}
+ }
+ encode gzip
+ tls internal
+}
diff --git a/docker/etc/nginx/conf.d/default.conf b/docker/etc/nginx/conf.d/default.conf
new file mode 100644
index 00000000..10746075
--- /dev/null
+++ b/docker/etc/nginx/conf.d/default.conf
@@ -0,0 +1,72 @@
+server {
+ listen 8080;
+ server_name app.test;
+ root /var/www/html/public;
+
+ index index.php;
+ 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";
+
+ # location /app {
+ # proxy_http_version 1.1;
+ # proxy_set_header Host $http_host ;
+ # proxy_set_header Scheme $scheme;
+ # proxy_set_header SERVER_PORT $server_port;
+ # proxy_set_header REMOTE_ADDR $remote_addr;
+ # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ # # proxy_set_header X-Forwarded-Proto $scheme;
+ # proxy_set_header Upgrade $http_upgrade;
+ # proxy_set_header Connection "Upgrade";
+
+ # 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.conf;
+ include fastcgi_params;
+ try_files $uri =404;
+
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
+
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ fastcgi_param PATH_INFO $fastcgi_path_info;
+
+ 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 ~ /\.(?!well-known).* {
+ deny all;
+ }
+
+ location /storage/ {
+ valid_referers 127.0.0.1, app.test ;
+ if ($invalid_referer) {
+ return 403;
+ }
+ }
+}
diff --git a/docker/etc/nginx/site-opts.d/http.conf b/docker/etc/nginx/site-opts.d/http.conf
new file mode 100644
index 00000000..3669a237
--- /dev/null
+++ b/docker/etc/nginx/site-opts.d/http.conf
@@ -0,0 +1,45 @@
+listen 8080 default_server;
+listen [::]:8080 default_server;
+
+root /var/www/html/public;
+
+index index.php;
+
+server_name _;
+charset utf-8;
+client_max_body_size 2048M;
+
+include mime.types;
+
+# Healthchecks: Set /healthcheck to be the healthcheck URL
+location /healthcheck {
+ access_log off;
+
+ # set max 5 seconds for healthcheck
+ fastcgi_read_timeout 5s;
+
+ include fastcgi_params;
+ fastcgi_param SCRIPT_NAME /healthcheck;
+ fastcgi_param SCRIPT_FILENAME /healthcheck;
+ fastcgi_pass 127.0.0.1:9000;
+}
+
+location / {
+ try_files $uri $uri/ /index.php?$query_string;
+}
+
+location ~ \.php$ {
+ include fastcgi.conf;
+ include fastcgi_params;
+ try_files $uri =404;
+
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
+
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+ fastcgi_param PATH_INFO $fastcgi_path_info;
+
+ fastcgi_read_timeout 3600;
+ fastcgi_hide_header X-Powered-By;
+}
diff --git a/docker/etc/php/conf.d/zzz-custom-php.ini b/docker/etc/php/conf.d/zzz-custom-php.ini
new file mode 100644
index 00000000..8e75dc04
--- /dev/null
+++ b/docker/etc/php/conf.d/zzz-custom-php.ini
@@ -0,0 +1,10 @@
+error_reporting = E_ERROR
+error_log = /var/www/html/storage/logs/php-error.log
+; log_errors = Off
+; log_errors_max_len = 8192
+ignore_repeated_errors = On
+ignore_repeated_source = On
+
+upload_max_filesize = 256M
+; post_max_size = 256M
+memory_limit = ${PHP_MEMORY_LIMIT:-1G}