mirror of
https://github.com/invoiceninja/dockerfiles.git
synced 2025-12-31 19:47:25 +01:00
Automatically create user and skip setup page (#345)
* Added checks to docker-entrypoint * Add init scripts feature * Added backward compatibility * Added auto user creation * Updated README.md and env * Use dbCheck for checking DB connection
This commit is contained in:
14
README.md
14
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=<insert your generated key in here>
|
||||
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
|
||||
|
||||
14
alpine/5/rootfs/docker-entrypoint-init.d/10-init-in.sh
Executable file
14
alpine/5/rootfs/docker-entrypoint-init.d/10-init-in.sh
Executable file
@@ -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
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user