Skip to content

Commit

Permalink
Merge pull request #689 from benbrummer/master
Browse files Browse the repository at this point in the history
Align alpine to debian and octane for maintenance
  • Loading branch information
turbo124 authored Jan 23, 2025
2 parents c69093a + 018e0e7 commit c0ee1a5
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 168 deletions.
65 changes: 29 additions & 36 deletions alpine/5/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
ARG PHP_VERSION=8.2
ARG PHP_VERSION=8.3
ARG ALPINE_VERSION=3.20
ARG BAK_STORAGE_PATH=/var/www/app/docker-backup-storage/
ARG BAK_PUBLIC_PATH=/var/www/app/docker-backup-public/

# Get Invoice Ninja and install nodejs packages
FROM --platform=$BUILDPLATFORM node:lts-alpine as nodebuild
FROM --platform=$BUILDPLATFORM php:${PHP_VERSION}-fpm-alpine${ALPINE_VERSION} AS nodebuild

# Download Invoice Ninja
ARG INVOICENINJA_VERSION
ARG REPOSITORY=invoiceninja/invoiceninja
ARG FILENAME=invoiceninja.tar

RUN set -eux; apk add curl unzip grep

RUN DOWNLOAD_URL=$(curl -s "https://api.github.com/repos/invoiceninja/invoiceninja/releases/latest" | grep -o '"browser_download_url": "[^"]*invoiceninja.tar"' | cut -d '"' -f 4) && \
curl -LJO "$DOWNLOAD_URL" && \
mv invoiceninja.tar /tmp/ninja.tar
RUN mkdir -p /var/www/app

# Extract Invoice Ninja
RUN mkdir -p /var/www/app \
&& tar -xvf /tmp/ninja.tar -C /var/www/app/ \
&& mkdir -p /var/www/app/public/logo /var/www/app/storage

RUN apk add --no-cache curl \
&& 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/app/ \
&& apk --purge del curl

RUN mkdir -p /var/www/app/public/logo /var/www/app/storage

WORKDIR /var/www/app

# Prepare php image
FROM php:${PHP_VERSION}-fpm-alpine as phpbuild
FROM php:${PHP_VERSION}-fpm-alpine${ALPINE_VERSION} AS phpbuild

LABEL maintainer="David Bomba <turbo124@gmail.com>"

# Adding caching_sha2_password.so
# With this we get native support for caching_sha2_password
RUN apk add --no-cache mariadb-connector-c
ARG php_require="bcmath gd pdo_mysql zip"
ARG php_suggest="exif imagick intl pcntl soap"
ARG php_extra="opcache"

RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini

# Install PHP extensions
# https://hub.docker.com/r/mlocati/php-extension-installer/tags
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN ln -s "${PHP_INI_DIR}/php.ini-production" "${PHP_INI_DIR}/php.ini"

# Install chromium
RUN set -eux; \
apk add --no-cache \
font-isas-misc \
supervisor \
mysql-client \
mariadb-client \
mariadb-connector-c \
chromium \
# font-noto-cjk-extra \
# font-wqy-zenhei \
ttf-freefont \
ttf-dejavu

RUN install-php-extensions \
bcmath \
exif \
gd \
gmp \
mysqli \
opcache \
pdo_mysql \
zip \
intl \
@composer \
&& rm /usr/local/bin/install-php-extensions
# Install PHP extensions
RUN ( curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - || echo 'return 1' ) | sh -s \
${php_require} \
${php_suggest} \
${php_extra}

# Copy files
COPY rootfs /
Expand Down Expand Up @@ -87,8 +82,6 @@ ENV BAK_STORAGE_PATH $BAK_STORAGE_PATH
ENV BAK_PUBLIC_PATH $BAK_PUBLIC_PATH
COPY --from=nodebuild --chown=$INVOICENINJA_USER:$INVOICENINJA_USER /var/www/app /var/www/app

RUN rm -rf /var/www/app/ui

USER $UID
WORKDIR /var/www/app

Expand All @@ -106,7 +99,7 @@ ARG BAK_PUBLIC_PATH
RUN mv /var/www/app/storage $BAK_STORAGE_PATH \
&& mv /var/www/app/public $BAK_PUBLIC_PATH

FROM phpbuild as prod
FROM phpbuild AS prod

COPY --from=dependencybuild --chown=$INVOICENINJA_USER:$INVOICENINJA_USER /var/www/app /var/www/app

Expand Down
37 changes: 18 additions & 19 deletions alpine/5/rootfs/etc/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
[supervisord]
nodaemon=true
pidfile=/tmp/supervisord.pid
logfile=/dev/null ; nodaemon will cause logs to go to stdout
logfile=/dev/null
logfile_maxbytes=0
loglevel=info

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

[program:php-fpm]
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php-fpm
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:scheduler]
command=php artisan schedule:work
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
command=php artisan schedule:work
redirect_stderr=true

[program:queue-worker]
process_name=%(program_name)s_%(process_num)02d
command=php artisan queue:work --sleep=3 --tries=1 --timeout=3600
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stopasgroup=true
killasgroup=true
numprocs=2
command=php artisan queue:work --sleep=3 --tries=1 --memory=256 --timeout=3600
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
stopwaitsecs=3600

[eventlistener:shutdown]
command=shutdown.sh
Expand Down
4 changes: 2 additions & 2 deletions alpine/5/rootfs/usr/local/bin/invoiceninja-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ php artisan optimize
php artisan package:discover

# Check if DB works, if not crash the app.
DB_READY=$(php artisan tinker --execute='echo app()->call("App\Utils\SystemHealth@dbCheck")["success"];')
DB_READY=$(php -d opcache.preload='' artisan tinker --execute='echo app()->call("App\Utils\SystemHealth@dbCheck")["success"];')
if [ "$DB_READY" != "1" ]; then
php artisan migrate:status # Print verbose error
in_error "Error connecting to DB"
Expand All @@ -39,7 +39,7 @@ fi
php artisan migrate --force

# If first IN run, it needs to be initialized
IN_INIT=$(php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')
IN_INIT=$(php -d opcache.preload='' artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')
if [ "$IN_INIT" == "1" ]; then
docker_process_init_files /docker-entrypoint-init.d/*
fi
1 change: 1 addition & 0 deletions alpine/5/rootfs/usr/local/etc/php-fpm.d/invoiceninja.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pm.max_children = 10
17 changes: 0 additions & 17 deletions alpine/5/rootfs/usr/local/etc/php/conf.d/in-php.ini

This file was deleted.

22 changes: 22 additions & 0 deletions alpine/5/rootfs/usr/local/etc/php/conf.d/invoiceninja.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[core]
; https://www.php.net/manual/en/ini.core.php
post_max_size=10M
upload_max_filesize=10M

[opcache]
; https://www.php.net/manual/en/opcache.installation.php#opcache.installation.recommended
opcache.enable_cli=1

[jit]
; https://wiki.php.net/rfc/jit_config_defaults
opcache.jit=tracing
opcache.jit_buffer_size=64M

[extra]
; http://symfony.com/doc/current/performance.html
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.preload=/var/www/app/preload.php
opcache.validate_timestamps=0
realpath_cache_size=4096K
realpath_cache_ttl=600
34 changes: 0 additions & 34 deletions config/nginx/in-vhost.conf

This file was deleted.

14 changes: 14 additions & 0 deletions config/nginx/invoiceninja.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://nginx.org/en/docs/http/ngx_http_core_module.html
client_max_body_size 10M;
client_body_buffer_size 10M;
server_tokens off;

# https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html
fastcgi_buffers 32 16K;

# https://nginx.org/en/docs/http/ngx_http_gzip_module.html
gzip on;
gzip_comp_level 2;
gzip_min_length 1M;
gzip_proxied any;
gzip_types *;
32 changes: 32 additions & 0 deletions config/nginx/laravel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# https://laravel.com/docs/master/deployment#nginx
server {
listen 80 default_server;
server_name _;
root /var/www/app/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

error_page 404 /index.php;

location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
18 changes: 0 additions & 18 deletions config/php/php-cli.ini

This file was deleted.

1 change: 1 addition & 0 deletions config/php/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pm.max_children = 10
37 changes: 19 additions & 18 deletions config/php/php.ini
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
session.auto_start = Off
short_open_tag = Off
[core]
; https://www.php.net/manual/en/ini.core.php
post_max_size=10M
upload_max_filesize=10M

error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
[opcache]
; https://www.php.net/manual/en/opcache.installation.php#opcache.installation.recommended
opcache.enable_cli=1

; opcache.enable=1
; opcache.preload=/var/www/app/preload.php
; opcache.preload_user=www-data
[jit]
; https://wiki.php.net/rfc/jit_config_defaults
opcache.jit=tracing
opcache.jit_buffer_size=64M

; ; The OPcache shared memory storage size.
; opcache.max_accelerated_files=300000
; opcache.validate_timestamps=1
; opcache.revalidate_freq=30
; opcache.jit_buffer_size=256M
; opcache.jit=1205
; opcache.memory_consumption=1024M


post_max_size = 60M
upload_max_filesize = 50M
memory_limit=512M
[extra]
; http://symfony.com/doc/current/performance.html
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.preload=/var/www/app/preload.php
opcache.validate_timestamps=0
realpath_cache_size=4096K
realpath_cache_ttl=600
Loading

0 comments on commit c0ee1a5

Please sign in to comment.