diff --git a/debian/Dockerfile b/debian/Dockerfile index 5b7ac4d..2979d6b 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -1,5 +1,25 @@ -FROM php:8.3-fpm AS base +ARG PHP=8.3 +FROM php:${PHP}-fpm AS prepare-app + +USER www-data + +RUN curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | \ + grep -o '"browser_download_url": "[^"]*invoiceninja.tar.gz"' | \ + cut -d '"' -f 4 | \ + xargs curl -sL | \ + tar -xz --strip-components=1 -C /var/www/html \ + && ln -s /var/www/html/resources/views/react/index.blade.php /var/www/html/public/index.html \ + && php -d opcache.preload='' artisan storage:link \ + # Workaround for application updates + && mv /var/www/html/public /tmp/public + +# ================== +# InvoiceNinja image +# ================== +FROM php:${PHP}-fpm + +# PHP modules ARG php_require="bcmath gd pdo_mysql zip" ARG php_suggest="exif imagick intl pcntl soap saxon-12.5.0" ARG php_extra="opcache" @@ -48,29 +68,12 @@ COPY php/php.ini /usr/local/etc/php/conf.d/invoiceninja.ini COPY php/php-fpm.conf /usr/local/etc/php-fpm.d/invoiceninja.conf -# Copy scripts -COPY rootfs / - -USER www-data - -WORKDIR /var/www/html +# Setup supervisor --chown=www-data:www-data +COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Setup InvoiceNinja -RUN curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | \ - grep -o '"browser_download_url": "[^"]*invoiceninja.tar.gz"' | \ - cut -d '"' -f 4 | \ - xargs curl -sL | \ - tar -xz --strip-components=1 -C /var/www/html \ - && ln -s /var/www/html/resources/views/react/index.blade.php /var/www/html/public/index.html \ - && php artisan optimize \ - && php artisan storage:link \ - # Workaround for application updates - && mv /var/www/html/public /tmp/public - -USER root - -# Setup supervisor -COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY --from=prepare-app /var/www/html /var/www/html +COPY --from=prepare-app /tmp/public /tmp/public # Add initialization script COPY --chmod=0755 scripts/init.sh /usr/local/bin/init.sh diff --git a/debian/rootfs/docker-entrypoint-init.d/10-init-in.sh b/debian/rootfs/docker-entrypoint-init.d/10-init-in.sh deleted file mode 100644 index 6c03b9d..0000000 --- a/debian/rootfs/docker-entrypoint-init.d/10-init-in.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -php artisan db:seed --force - -# Build up array of arguments... -if [ ! -z "${IN_USER_EMAIL}" ]; then - email="--email ${IN_USER_EMAIL}" -fi - -if [ ! -z "${IN_PASSWORD}" ]; then - password="--password ${IN_PASSWORD}" -fi - -php artisan ninja:create-account $email $password diff --git a/debian/scripts/init.sh b/debian/scripts/init.sh index 4385791..30ebc72 100755 --- a/debian/scripts/init.sh +++ b/debian/scripts/init.sh @@ -1,33 +1,4 @@ -#!/bin/sh -set -e - -in_log() { - local type="$1" - shift - printf '%s [%s] [Entrypoint]: %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$type" "$*" -} - -docker_process_init_files() { - echo - local f - for f; do - case "$f" in - *.sh) - # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 - # https://github.com/docker-library/postgres/pull/452 - if [ -x "$f" ]; then - in_log INFO "$0: running $f" - "$f" - else - in_log INFO "$0: sourcing $f" - . "$f" - fi - ;; - *) in_log INFO "$0: ignoring $f" ;; - esac - echo - done -} +#!/bin/sh -eu if [ "$*" = 'supervisord -c /etc/supervisor/conf.d/supervisord.conf' ]; then # Workaround for application updates @@ -61,18 +32,20 @@ if [ "$*" = 'supervisord -c /etc/supervisor/conf.d/supervisord.conf' ]; then runuser -u www-data -- php artisan migrate --force # If first IN run, it needs to be initialized - echo "Checking initialization status..." - IN_INIT=$(php -d opcache.preload='' artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();') - echo "IN_INIT value: $IN_INIT" + if [ "$(php -d opcache.preload='' artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')" = "1" ]; then + echo "Running initialization..." - if [ "$IN_INIT" = "1" ]; then - echo "Running initialization scripts..." - docker_process_init_files /docker-entrypoint-init.d/* + php artisan db:seed --force + + if [ -n "${IN_USER_EMAIL}" ] && [ -n "${IN_PASSWORD}" ]; then + php artisan ninja:create-account --email "${IN_USER_EMAIL}" --password "${IN_PASSWORD}" + else + echo "Initialization failed - Set IN_USER_EMAIL and IN_PASSWORD in .env" + exit 1 + fi fi echo "Production setup completed" - echo "IN_INIT value: $IN_INIT" - fi echo "Starting supervisord..." diff --git a/debian/supervisor/supervisord.conf b/debian/supervisor/supervisord.conf index ffa858a..cf97afe 100644 --- a/debian/supervisor/supervisord.conf +++ b/debian/supervisor/supervisord.conf @@ -39,7 +39,7 @@ stderr_logfile=/var/log/php-worker.err.log stopwaitsecs=3600 [program:scheduler] -command=/bin/sh -c "while [ true ]; do (php /var/www/html/artisan schedule:run --verbose --no-interaction &); sleep 60; done" +command=php /var/www/html/artisan schedule:work --verbose --no-interaction autostart=true autorestart=true user=www-data