From 152145af96cc01c4acf03a60a95f8ef4fad5cc63 Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Mon, 3 Jul 2023 10:44:57 +0100 Subject: [PATCH 1/9] Remove .env file generation from entrypoint --- docker-entrypoint.sh | 82 ++------------------------------------------ 1 file changed, 2 insertions(+), 80 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 36988d89..529889a6 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,86 +7,8 @@ echoerr() { echo "$@" 1>&2; } IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST" DB_PORT=${DB_PORT:-3306} -if [ ! -f ".env" ]; then - if [[ "${DB_HOST}" ]]; then - cat > ".env" <&2 'error: missing DB_HOST environment variable' - exit 1 - fi -fi +# Ensure these is no local .env file +[ -f ".env" ] && rm .env echoerr "wait-for-db: waiting for ${DB_HOST_NAME}:${DB_PORT}" From 7d861ffc8d14a655fb0b14f0075ed3dfa731738d Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Mon, 3 Jul 2023 10:53:03 +0100 Subject: [PATCH 2/9] Create function to check if vars exist --- docker-entrypoint.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 529889a6..ccc1bdb3 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,6 +3,17 @@ set -e echoerr() { echo "$@" 1>&2; } +check_vars_exist() { + var_names=("$@") + + for var_name in "${var_names[@]}"; do + if [ -z "${!var_name}" ]; then + echoerr "error: missing ${var_name} environment variable" + exit 1 + fi + done +} + # Split out host and port from DB_HOST env variable IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST" DB_PORT=${DB_PORT:-3306} From 03907ddc2b52239e1e39847e04f9571f37242b58 Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Mon, 3 Jul 2023 11:06:13 +0100 Subject: [PATCH 3/9] Ensure a number of variables exist --- docker-entrypoint.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index ccc1bdb3..4494e4a8 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,6 +21,16 @@ DB_PORT=${DB_PORT:-3306} # Ensure these is no local .env file [ -f ".env" ] && rm .env +# Check a number of essential variables are set +check_vars_exist \ + APP_KEY \ + APP_URL \ + DB_DATABASE \ + DB_HOST \ + DB_PASSWORD \ + DB_PORT \ + DB_USERNAME + echoerr "wait-for-db: waiting for ${DB_HOST_NAME}:${DB_PORT}" timeout 15 bash < Date: Mon, 3 Jul 2023 11:17:59 +0100 Subject: [PATCH 4/9] Add env vars to docker-compose --- docker-compose.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index f7eafa79..6fe713f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,10 @@ services: - DB_PASSWORD=secret #set the APP_ to the URL of bookstack without without a trailing slash APP_URL=https://example.com - APP_URL=http://example.com + # APP_KEY is used for encryption where needed, so needs to be persisted to + # preserve decryption abilities. + # Can run `php artisan key:generate` to generate a key + - APP_KEY=SomeRandomString volumes: - uploads:/var/www/bookstack/public/uploads - storage-uploads:/var/www/bookstack/storage/uploads From 0728a23067a76c0b22ae66692d542e2296efa63d Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Wed, 5 Jul 2023 15:03:32 +0100 Subject: [PATCH 5/9] Patch test compose file to specify required vars --- docker-compose.test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 71e50543..55dc8315 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -21,6 +21,7 @@ services: - mysql environment: - APP_URL=http://localhost:${DEV_PORT:-8080} + - APP_KEY=SomeRandomString - DB_HOST=mysql:3306 - DB_DATABASE=bookstack - DB_USERNAME=bookstack From c5219c8ec331586dbde6d87b71e07700846d51d2 Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Wed, 5 Jul 2023 18:18:41 +0100 Subject: [PATCH 6/9] Make note of required arguments --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 915af9e7..ade07241 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,14 @@ Networking changed in Docker v1.9, so you need to do one of the following steps. `APP_URL=http://example.com` + The following environment variables are required for Bookstack to start: + - `APP_KEY` + - `APP_URL` + - `DB_HOST` (in the form `${hostname_or_ip_address}:${port}`) + - `DB_DATABASE` + - `DB_USERNAME` + - `DB_PASSWORD` + ### Volumes To access your `.env` file and important bookstack folders on your host system @@ -115,7 +123,7 @@ your run command: In case of a windows host machine the .env file has to be already created in the host directory otherwise a folder named .env will be created. -After these steps you can visit [http://localhost:8080](http://localhost:8080) . +After these steps you can visit [http://localhost:8080](http://localhost:8080). You can login with username `admin@admin.com` and password `password`. ## Inspiration From ab52487162e6730deca40214545c9f5b2ac0a31e Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Wed, 5 Jul 2023 18:24:57 +0100 Subject: [PATCH 7/9] Add notes on breaking change --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index ade07241..5eb55016 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,16 @@ ## Changes +Versions higher than 23.6.2 no longer use an in-container `.env` file for +environment variable management. Instead, the preferred approach is to manage +them directly with the container runtime (e.g. Docker's `-e`). This is to +simplify troubleshooting if and when errors occur. The most important change is +that `${APP_KEY}` is no longer provided for you, instead it is up to the +operator to ensure this value is present. Versions prior to this supplied +`${APP_KEY}` (with a default of `SomeRandomStringWith32Characters`. A full +reference of available environment variables is available in the [Bookstack +repository](https://github.com/BookStackApp/BookStack/blob/development/.env.example.complete) + The version 23.6.0 is broken due to a bad `.env` configuration created by the entrypoint script. This is fixed in version 23.6.0-1. From f5338810adff8a1c125093853c386cc5a98155b0 Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Fri, 7 Jul 2023 12:03:23 +0100 Subject: [PATCH 8/9] Adjust entrypoint script to move env file instead of removing --- docker-entrypoint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 4494e4a8..85dffed2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -19,7 +19,11 @@ IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST" DB_PORT=${DB_PORT:-3306} # Ensure these is no local .env file -[ -f ".env" ] && rm .env +if [ -f ".env" ]; then + mv .env .env.bak + echoerr ".env file detected - moved to .env.bak" + echoerr "Please update your configuration to use environment variables in the container!" +fi # Check a number of essential variables are set check_vars_exist \ From 2bfe6aadfe59ec45c3eddcd144762a7f6d94db78 Mon Sep 17 00:00:00 2001 From: Rick Henry Date: Fri, 7 Jul 2023 12:04:43 +0100 Subject: [PATCH 9/9] Remove key generation from entrypoint script --- docker-entrypoint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 85dffed2..b1e93d81 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -52,9 +52,6 @@ else echoerr "wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST_NAME}:${DB_PORT}" fi -echo "Generating Key..." -php artisan key:generate --show - echo "Starting Migration..." php artisan migrate --force