diff --git a/README.md b/README.md index a21f2e6..d9eac97 100644 --- a/README.md +++ b/README.md @@ -31,21 +31,19 @@ git clone https://github.com/invoiceninja/dockerfiles.git cd dockerfiles ``` -Instead of defining our environment variables inside our docker-compose.yml file we now define this in the `env` file, open this file up and insert your `APP_URL` and your `APP_KEY` +Instead of defining our environment variables inside our docker-compose.yml file we now define this in the `env` file, open this file up and insert your `APP_URL`, `APP_KEY` and update the rest of the variables as required. ``` APP_URL=http://in.localhost:8003/ APP_KEY= APP_DEBUG=true -MULTI_DB_ENABLED=false -DB_HOST1=db -DB_PORT1=3306 -DB_USERNAME1=ninja -DB_PASSWORD1=ninja -DB_DATABASE1=ninja -PHANTOMJS_PDF_GENERATION=false +REQUIRE_HTTPS=false +IN_USER_EMAIL= +IN_PASSWORD= ``` +If `IN_USER_EMAIL` and `IN_PASSWORD` is not set the default user email and password is "admin@example.com" and "changeme!" respectively. You will use this for the initial login, thereafter, you can delete this two environment variables. + The `APP_KEY` can be generated by running ```bash diff --git a/alpine/5/rootfs/docker-entrypoint-init.d/10-init-in.sh b/alpine/5/rootfs/docker-entrypoint-init.d/10-init-in.sh new file mode 100755 index 0000000..dae8552 --- /dev/null +++ b/alpine/5/rootfs/docker-entrypoint-init.d/10-init-in.sh @@ -0,0 +1,14 @@ +#!/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/alpine/5/rootfs/usr/local/bin/docker-entrypoint b/alpine/5/rootfs/usr/local/bin/docker-entrypoint index 0dadb4f..4cf0b71 100755 --- a/alpine/5/rootfs/usr/local/bin/docker-entrypoint +++ b/alpine/5/rootfs/usr/local/bin/docker-entrypoint @@ -46,43 +46,52 @@ file_env() { # first arg is `-f` or `--some-option` if [ "${1#-}" != "$1" ]; then - set -- php-fpm "$@" + set -- supervisord "$@" fi # create storage volume -if [ ! -d /var/www/app/storage ] && [ -d "$BAK_STORAGE_PATH" ]; then - mv "$BAK_STORAGE_PATH" /var/www/app/storage -elif [ -d "$BAK_STORAGE_PATH" ]; then - # copy missing folders in storage - IN_STORAGE_BACKUP="$(ls "$BAK_STORAGE_PATH")" - for path in $IN_STORAGE_BACKUP; do - if [ ! -e "/var/www/app/storage/$path" ]; then - cp -Rp "$BAK_STORAGE_PATH/$path" "/var/www/app/storage/" - fi - done +if [ -d "$BAK_STORAGE_PATH" ]; then + if [ ! -d /var/www/app/storage ]; then + mv "$BAK_STORAGE_PATH" /var/www/app/storage + else + # copy missing folders in storage + IN_STORAGE_BACKUP="$(ls "$BAK_STORAGE_PATH")" + for path in $IN_STORAGE_BACKUP; do + if [ ! -e "/var/www/app/storage/$path" ]; then + cp -Rp "$BAK_STORAGE_PATH/$path" "/var/www/app/storage/" + fi + done + fi + rm -rf "$BAK_STORAGE_PATH" +fi + +# prevent init scripts from running when upgrading from IN <= 5.1.62 +if [ -f /var/www/app/public/version ] && [ "$INVOICENINJA_VERSION" != "$(cat /var/www/app/public/version)" ]; then + touch /var/www/app/storage/.initialized fi -rm -rf "$BAK_STORAGE_PATH" # create public volume -if [ ! -d /var/www/app/public ] && [ -d "$BAK_PUBLIC_PATH" ]; then - mv "$BAK_PUBLIC_PATH" /var/www/app/public -elif [ ! -e /var/www/app/public/version ] || [ "$INVOICENINJA_VERSION" != "$(cat /var/www/app/public/version)" ]; then - # version mismatch, update all - cp -au "$BAK_PUBLIC_PATH/"* /var/www/app/public - echo "$INVOICENINJA_VERSION" >/var/www/app/public/version -elif [ ! -d /var/www/app/public/logo ] && [ -d "$BAK_PUBLIC_PATH/logo" ]; then - # missing logo folder only, copy folder - cp -a "$BAK_PUBLIC_PATH/logo" /var/www/app/public/logo -elif [ -d "$BAK_PUBLIC_PATH/logo" ]; then - # copy missing folders in logo - IN_LOGO_BACKUP="$(ls "$BAK_PUBLIC_PATH/logo")" - for path in $IN_LOGO_BACKUP; do - if [ ! -e "/var/www/app/public/logo/$path" ]; then - cp -a "$BAK_PUBLIC_PATH/logo/$path" "/var/www/app/public/logo/" - fi - done +if [ -d "$BAK_PUBLIC_PATH" ]; then + if [ ! -d /var/www/app/public ]; then + mv "$BAK_PUBLIC_PATH" /var/www/app/public + elif [ ! -f /var/www/app/public/version ] || [ "$INVOICENINJA_VERSION" != "$(cat /var/www/app/public/version)" ]; then + # version mismatch, update all + cp -au "$BAK_PUBLIC_PATH/"* /var/www/app/public + echo "$INVOICENINJA_VERSION" >/var/www/app/public/version + elif [ ! -d /var/www/app/public/logo ] && [ -d "$BAK_PUBLIC_PATH/logo" ]; then + # missing logo folder only, copy folder + cp -a "$BAK_PUBLIC_PATH/logo" /var/www/app/public/logo + elif [ -d "$BAK_PUBLIC_PATH/logo" ]; then + # copy missing folders in logo + IN_LOGO_BACKUP="$(ls "$BAK_PUBLIC_PATH/logo")" + for path in $IN_LOGO_BACKUP; do + if [ ! -e "/var/www/app/public/logo/$path" ]; then + cp -a "$BAK_PUBLIC_PATH/logo/$path" "/var/www/app/public/logo/" + fi + done + fi + rm -rf "$BAK_PUBLIC_PATH" fi -rm -rf "$BAK_PUBLIC_PATH" # Initialize values that might be stored in a file file_env 'APP_KEY' diff --git a/alpine/5/rootfs/usr/local/bin/laravel-init.sh b/alpine/5/rootfs/usr/local/bin/laravel-init.sh index 5e875f2..eb9a2c5 100755 --- a/alpine/5/rootfs/usr/local/bin/laravel-init.sh +++ b/alpine/5/rootfs/usr/local/bin/laravel-init.sh @@ -1,5 +1,45 @@ #!/bin/sh +# usage: docker_process_init_files [file [file [...]]] +# ie: docker_process_init_files /always-initdb.d/* +# process initializer files, based on file extensions +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 "$0: running $f" + "$f" + else + in_log "$0: sourcing $f" + . "$f" + fi + ;; + *) in_log "$0: ignoring $f" ;; + esac + echo + done +} + php artisan config:cache php artisan optimize + +# Check if DB works, if not crash the app. +DB_READY=$(php artisan tinker --execute='echo app()->call("App\Utils\SystemHealth@dbCheck")["success"];') +if [ "$DB_READY" != "1" ]; then + echo "Error connecting to DB" + php artisan migrate:status # Print verbose error + exit 1 +fi + php artisan migrate --force + +# If first IN run, it needs to be initialized +if [ ! -f /var/www/app/storage/.initialized ]; then + docker_process_init_files /docker-entrypoint-init.d/* + touch /var/www/app/storage/.initialized +fi diff --git a/env b/env index 2d2980f..f969d9f 100644 --- a/env +++ b/env @@ -12,6 +12,13 @@ DB_DATABASE=ninja DB_USERNAME=ninja DB_PASSWORD=ninja +# Create initial user +# Default to these values if empty +# IN_USER_EMAIL=admin@example.com +# IN_PASSWORD=changeme! +IN_USER_EMAIL= +IN_PASSWORD= + # Mail options MAIL_MAILER=log MAIL_HOST=smtp.mailtrap.io