Skip to content

A self-hosted media server and file management system

feat: remove the need for git and npm in docker builds

aminnausin65fc36ea981b
diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml
index d0dc7526..64819fef 100644
--- a/.github/workflows/release-docker.yml
+++ b/.github/workflows/release-docker.yml
@@ -43,6 +43,9 @@ jobs:
with:
context: .
push: true
+ build-args: |
+ GIT_COMMIT=${{ github.sha }}
+ GIT_TAG=${{ inputs.version_tag }}
tags: |
aminnausin/mediaserver:${{ inputs.docker_tag}}
aminnausin/mediaserver:${{ inputs.version_tag }}
diff --git a/Dockerfile b/Dockerfile
index 493563e8..efeaceec 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,15 @@
# 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
# Add user/group
ARG USER_ID=1000
ARG GROUP_ID=1000
+# Git state
+ARG GIT_COMMIT=unknown
+ARG GIT_TAG=unknown
+
# =================================================================
# 1: Install composer dependencies
# =================================================================
@@ -63,29 +65,30 @@ FROM serversideup/php:${SERVERSIDEUP_PHP_VERSION}
ARG USER_ID
ARG GROUP_ID
-ARG POSTGRES_VERSION
+ARG GIT_COMMIT=unknown
+ARG GIT_TAG=unknown
WORKDIR /var/www/html
USER root
-# Install PostgreSQL repository and keys for external access
+# Install runtime dependencies
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 && \
- apk add --no-cache gnupg && \
- mkdir -p /usr/share/keyrings && \
- curl --proto "=https" -fSsL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /usr/share/keyrings/postgresql.gpg && \
- apk update && \
+ # apk add --no-cache gnupg && \
+ # mkdir -p /usr/share/keyrings && \
+ # curl --proto "=https" -fSsL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /usr/share/keyrings/postgresql.gpg && \
+ # apk update && \
apk add --no-cache \
ca-certificates \
chromium \
exiftool \
ffmpeg \
freetype \
- git \
+ # git \
harfbuzz \
nodejs \
- npm \
+ # npm \
nss \
ttf-freefont && \
rm -rf /var/cache/apk/*
@@ -118,22 +121,25 @@ COPY --chown=www-data:www-data . .
# Copy .env and set up Laravel
COPY --chown=www-data:www-data .env.example .env
-# Copy .git folder for manifest generation at runtime
-COPY --chown=www-data:www-data .git .git
+# Copy Nginx config
+COPY docker/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
-# Set permissions for Laravel runtime
-RUN composer dump-autoload && \
+# Set permissions for Laravel runtime and generate git info
+# Setup NGINX
+RUN echo "${GIT_COMMIT}" > ./COMMIT && \
+ echo "${GIT_TAG}" > ./VERSION && \
+ chown www-data:www-data ./COMMIT ./VERSION && \
+ mkdir -p /var/www/html/bootstrap/cache && \
+ chown www-data:www-data /var/www/html/bootstrap/cache && \
+ composer dump-autoload --optimize --classmap-authoritative && \
chown -R www-data:www-data /var/www/html/storage /var/www/html/shared && \
chmod -R 775 /var/www/html/storage /var/www/html/shared && \
chmod 644 /var/www/html/.env && \
chmod g+s /var/www/html/storage/app/private \
/var/www/html/storage/app/public \
/var/www/html/storage/logs \
- /var/www/html/shared
-
-# Nginx
-COPY docker/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
-RUN chown -R www-data:www-data /etc/nginx && \
+ /var/www/html/shared && \
+ chown -R www-data:www-data /etc/nginx && \
chmod -R 775 /etc/nginx && \
rm -rf /tmp/* /root/.npm /root/.cache /home/www-data/.cache /usr/share/man /usr/share/doc /var/cache/apk/*
diff --git a/app/Console/Commands/GenerateManifest.php b/app/Console/Commands/GenerateManifest.php
index 9bec24ad..30dfe47f 100644
--- a/app/Console/Commands/GenerateManifest.php
+++ b/app/Console/Commands/GenerateManifest.php
@@ -13,6 +13,7 @@ class GenerateManifest extends Command {
public function handle() {
$commit = trim(shell_exec('git rev-parse --short HEAD') ?? '')
?: substr(env('GITHUB_SHA', ''), 0, 7)
+ ?: (file_exists(base_path('COMMIT')) ? trim(file_get_contents(base_path('COMMIT'))) : null)
?: 'unknown';
$version = trim(shell_exec('git describe --tags --abbrev=0') ?? '')