Skip to content

Commit fc5bea8

Browse files
authored
Merge pull request #409 from solidnerd/rjh_remove_entrypoint_script
Remove .env file creation
2 parents cd66a5e + 2bfe6aa commit fc5bea8

File tree

4 files changed

+50
-83
lines changed

4 files changed

+50
-83
lines changed

Diff for: README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
## Changes
88

9+
Versions higher than 23.6.2 no longer use an in-container `.env` file for
10+
environment variable management. Instead, the preferred approach is to manage
11+
them directly with the container runtime (e.g. Docker's `-e`). This is to
12+
simplify troubleshooting if and when errors occur. The most important change is
13+
that `${APP_KEY}` is no longer provided for you, instead it is up to the
14+
operator to ensure this value is present. Versions prior to this supplied
15+
`${APP_KEY}` (with a default of `SomeRandomStringWith32Characters`. A full
16+
reference of available environment variables is available in the [Bookstack
17+
repository](https://github.com/BookStackApp/BookStack/blob/development/.env.example.complete)
18+
919
The version 23.6.0 is broken due to a bad `.env` configuration created by the
1020
entrypoint script. This is fixed in version 23.6.0-1.
1121

@@ -100,6 +110,14 @@ Networking changed in Docker v1.9, so you need to do one of the following steps.
100110

101111
`APP_URL=http://example.com`
102112

113+
The following environment variables are required for Bookstack to start:
114+
- `APP_KEY`
115+
- `APP_URL`
116+
- `DB_HOST` (in the form `${hostname_or_ip_address}:${port}`)
117+
- `DB_DATABASE`
118+
- `DB_USERNAME`
119+
- `DB_PASSWORD`
120+
103121
### Volumes
104122

105123
To access your `.env` file and important bookstack folders on your host system
@@ -115,7 +133,7 @@ your run command:
115133
In case of a windows host machine the .env file has to be already created in the
116134
host directory otherwise a folder named .env will be created.
117135

118-
After these steps you can visit [http://localhost:8080](http://localhost:8080) .
136+
After these steps you can visit [http://localhost:8080](http://localhost:8080).
119137
You can login with username `admin@admin.com` and password `password`.
120138

121139
## Inspiration

Diff for: docker-compose.test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ services:
2121
- mysql
2222
environment:
2323
- APP_URL=http://localhost:${DEV_PORT:-8080}
24+
- APP_KEY=SomeRandomString
2425
- DB_HOST=mysql:3306
2526
- DB_DATABASE=bookstack
2627
- DB_USERNAME=bookstack

Diff for: docker-compose.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ services:
2121
- DB_PASSWORD=secret
2222
#set the APP_ to the URL of bookstack without without a trailing slash APP_URL=https://example.com
2323
- APP_URL=http://example.com
24+
# APP_KEY is used for encryption where needed, so needs to be persisted to
25+
# preserve decryption abilities.
26+
# Can run `php artisan key:generate` to generate a key
27+
- APP_KEY=SomeRandomString
2428
volumes:
2529
- uploads:/var/www/bookstack/public/uploads
2630
- storage-uploads:/var/www/bookstack/storage/uploads

Diff for: docker-entrypoint.sh

+26-82
Original file line numberDiff line numberDiff line change
@@ -3,91 +3,38 @@ set -e
33

44
echoerr() { echo "$@" 1>&2; }
55

6+
check_vars_exist() {
7+
var_names=("$@")
8+
9+
for var_name in "${var_names[@]}"; do
10+
if [ -z "${!var_name}" ]; then
11+
echoerr "error: missing ${var_name} environment variable"
12+
exit 1
13+
fi
14+
done
15+
}
16+
617
# Split out host and port from DB_HOST env variable
718
IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST"
819
DB_PORT=${DB_PORT:-3306}
920

10-
if [ ! -f ".env" ]; then
11-
if [[ "${DB_HOST}" ]]; then
12-
cat > ".env" <<EOF
13-
# Environment
14-
APP_ENV=production
15-
APP_DEBUG=${APP_DEBUG:-false}
16-
APP_KEY=${APP_KEY:-SomeRandomStringWith32Characters}
17-
18-
# The below url has to be set if using social auth options
19-
# or if you are not using BookStack at the root path of your domain.
20-
APP_URL=${APP_URL:-null}
21-
22-
# Database details
23-
DB_HOST=${DB_HOST:-localhost}
24-
DB_DATABASE=${DB_DATABASE:-bookstack}
25-
DB_USERNAME=${DB_USERNAME:-bookstack}
26-
DB_PASSWORD=${DB_PASSWORD:-password}
27-
28-
# Cache and session
29-
CACHE_DRIVER=file
30-
SESSION_DRIVER=file
31-
# If using Memcached, comment the above and uncomment these
32-
#CACHE_DRIVER=memcached
33-
#SESSION_DRIVER=memcached
34-
QUEUE_DRIVER=sync
35-
36-
# Memcached settings
37-
# If using a UNIX socket path for the host, set the port to 0
38-
# This follows the following format: HOST:PORT:WEIGHT
39-
# For multiple servers separate with a comma
40-
MEMCACHED_SERVERS=127.0.0.1:11211:100
41-
42-
# Storage
43-
STORAGE_TYPE=${STORAGE_TYPE:-local}
44-
# Amazon S3 Config
45-
STORAGE_S3_KEY=${STORAGE_S3_KEY:-false}
46-
STORAGE_S3_SECRET=${STORAGE_S3_SECRET:-false}
47-
STORAGE_S3_REGION=${STORAGE_S3_REGION:-false}
48-
STORAGE_S3_BUCKET=${STORAGE_S3_BUCKET:-false}
49-
# Storage URL
50-
# Used to prefix image urls for when using custom domains/cdns
51-
STORAGE_URL=${STORAGE_URL:-false}
52-
53-
# General auth
54-
AUTH_METHOD=${AUTH_METHOD:-standard}
55-
56-
# Social Authentication information. Defaults as off.
57-
GITHUB_APP_ID=${GITHUB_APP_ID:-false}
58-
GITHUB_APP_SECRET=${GITHUB_APP_SECRET:-false}
59-
GOOGLE_APP_ID=${GOOGLE_APP_ID:-false}
60-
GOOGLE_APP_SECRET=${GOOGLE_APP_SECRET:-false}
61-
62-
# External services such as Gravatar
63-
DISABLE_EXTERNAL_SERVICES=${DISABLE_EXTERNAL_SERVICES:-false}
64-
65-
# LDAP Settings
66-
LDAP_SERVER=${LDAP_SERVER:-false}
67-
LDAP_BASE_DN=${LDAP_BASE_DN:-false}
68-
LDAP_DN=${LDAP_DN:-false}
69-
LDAP_PASS=${LDAP_PASS:-false}
70-
LDAP_USER_FILTER=${LDAP_USER_FILTER:-false}
71-
LDAP_VERSION=${LDAP_VERSION:-false}
72-
LDAP_ID_ATTRIBUTE=${LDAP_ID_ATTRIBUTE:-false}
73-
LDAP_TLS_INSECURE=${LDAP_TLS_INSECURE:-false}
74-
LDAP_DISPLAY_NAME_ATTRIBUTE=${LDAP_DISPLAY_NAME_ATTRIBUTE:-false}
75-
76-
# Mail settings
77-
MAIL_DRIVER=${MAIL_DRIVER:-smtp}
78-
MAIL_HOST=${MAIL_HOST:-localhost}
79-
MAIL_PORT=${MAIL_PORT:-1025}
80-
MAIL_USERNAME=${MAIL_USERNAME:-null}
81-
MAIL_PASSWORD=${MAIL_PASSWORD:-null}
82-
MAIL_ENCRYPTION=${MAIL_ENCRYPTION:-null}
83-
# URL used for social login redirects, NO TRAILING SLASH
84-
EOF
85-
else
86-
echo >&2 'error: missing DB_HOST environment variable'
87-
exit 1
88-
fi
21+
# Ensure these is no local .env file
22+
if [ -f ".env" ]; then
23+
mv .env .env.bak
24+
echoerr ".env file detected - moved to .env.bak"
25+
echoerr "Please update your configuration to use environment variables in the container!"
8926
fi
9027

28+
# Check a number of essential variables are set
29+
check_vars_exist \
30+
APP_KEY \
31+
APP_URL \
32+
DB_DATABASE \
33+
DB_HOST \
34+
DB_PASSWORD \
35+
DB_PORT \
36+
DB_USERNAME
37+
9138
echoerr "wait-for-db: waiting for ${DB_HOST_NAME}:${DB_PORT}"
9239

9340
timeout 15 bash <<EOT
@@ -105,9 +52,6 @@ else
10552
echoerr "wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST_NAME}:${DB_PORT}"
10653
fi
10754

108-
echo "Generating Key..."
109-
php artisan key:generate --show
110-
11155
echo "Starting Migration..."
11256
php artisan migrate --force
11357

0 commit comments

Comments
 (0)