Skip to content

Commit 703a0eb

Browse files
committed
fix substitution of APP_URL when provided
linuxserver/docker-bookstack#62
1 parent 85c1837 commit 703a0eb

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Application envionment variables apply to all services within the application, a
2424
|---|---|---|
2525
|`TZ`|`America/Toronto`|(optional) inform services of the [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) in your location|
2626
|`MYSQL_ROOT_PASSWORD`|`********`|password that will be set for the MariaDB root account|
27-
|`APP_URL`|`http://bookstack.192.168.8.4.nip.io`|for specifying the url your application will be accessed on (required for correct operation of reverse proxy)|
27+
|`APP_URL`|`https://<UUID>.balena-devices.com`|for specifying the url your application will be accessed on (required for correct operation of reverse proxy)|
2828

2929
## Usage
3030

@@ -51,6 +51,7 @@ Kyle Harding <https://klutchell.dev>
5151
## References
5252

5353
- <https://docs.linuxserver.io/images/docker-bookstack>
54+
- <https://www.bookstackapp.com/docs/>
5455
- <https://www.bookstackapp.com/docs/admin/backup-restore/#database>
5556

5657
## License

bookstack/50-config

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# create directory structure
4+
mkdir -p \
5+
/config/www/{uploads,files,images}
6+
7+
# check for .env and copy default if needed
8+
[[ ! -f "/config/www/.env" ]] && \
9+
cp /var/www/html/.env.example /config/www/.env
10+
11+
# create symlinks
12+
symlinks=( \
13+
/var/www/html/storage/uploads/files \
14+
/var/www/html/storage/uploads/images \
15+
/var/www/html/public/uploads \
16+
/var/www/html/.env \
17+
/var/www/html/storage/logs/laravel.log
18+
)
19+
20+
for i in "${symlinks[@]}"
21+
do
22+
[[ -e "$i" && ! -L "$i" ]] && rm -rf "$i"
23+
[[ ! -L "$i" ]] && ln -s /config/www/"$(basename "$i")" "$i"
24+
done
25+
26+
# Echo init finish for test runs
27+
if [ -n "${TEST_RUN}" ]; then
28+
echo '[services.d] done.'
29+
fi
30+
31+
# Create API key if needed
32+
if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ];
33+
then
34+
echo "Generating BookStack app key for first run"
35+
key=$(php /var/www/html/artisan key:generate --show)
36+
echo $key > /config/BOOKSTACK_APP_KEY.txt
37+
echo "App Key set to $key you can modify the file to update /config/BOOKSTACK_APP_KEY.txt"
38+
elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ];
39+
then
40+
echo "App Key found - setting variable for seds"
41+
key=$(cat /config/BOOKSTACK_APP_KEY.txt)
42+
fi
43+
44+
# .env file setup
45+
# check for the default app key or if it has been updated
46+
if grep -Fxq "APP_KEY=SomeRandomString" /config/www/.env || \
47+
! grep -Fxq "APP_KEY=${key}" /config/www/.env; then
48+
sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env
49+
fi
50+
# check to see if db_user is set, if it is then run seds and if not then leave them
51+
if [ "${DB_USER}" ];
52+
then
53+
echo "Running config - db_user set"
54+
sed -i "s/DB_HOST=localhost/DB_HOST=${DB_HOST}/g" /config/www/.env
55+
sed -i "s/DB_DATABASE=database_database/DB_DATABASE=${DB_DATABASE}/g" /config/www/.env
56+
sed -i "s/DB_USERNAME=database_username/DB_USERNAME=${DB_USER}/g" /config/www/.env
57+
sed -i "s/DB_PASSWORD=database_user_password/DB_PASSWORD=${DB_PASS}/g" /config/www/.env
58+
fi
59+
60+
# set appurl if detected
61+
[ -n "${APP_URL}" ] && sed -r "s,([#\s]*)?APP_URL=.*,APP_URL=${APP_URL},g" -i /config/www/.env
62+
63+
# check for the mysql endpoint for 30 seconds
64+
END=$((SECONDS+30))
65+
while [ ${SECONDS} -lt ${END} ] && [ -n "${DB_HOST+x}" ]; do
66+
/usr/bin/nc -z ${DB_HOST} 3306 && \
67+
if [ ! -z "$(/usr/bin/nc -w1 ${DB_HOST} 3306)" ]; then
68+
[ ! -z "${RUN}" ] && break
69+
RUN="RAN"
70+
# we sleep here again due to first run init on DB containers
71+
[ ! -f /dbwait.lock ] && sleep 5
72+
else
73+
sleep 1
74+
fi
75+
sleep 1
76+
done
77+
78+
# update database - will set up database if fresh, or, migrate existing
79+
if [ -z "${CI_RUN+x}" ]; then
80+
php /var/www/html/artisan migrate --force
81+
fi
82+
83+
# set permissions
84+
chown -R abc:abc \
85+
/config \
86+
/var/www/
87+
88+
# set lockfile to avoid DB waits for this specific container
89+
touch /dbwait.lock

bookstack/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM linuxserver/bookstack:v0.29.3-ls99
2+
3+
COPY 50-config /etc/cont-init.d/50-config
4+
5+
RUN chmod 0755 /etc/cont-init.d/50-config

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ volumes:
88
services:
99
# https://hub.docker.com/r/linuxserver/bookstack/
1010
bookstack:
11-
image: linuxserver/bookstack:v0.29.3-ls97
11+
build: bookstack
1212
environment:
1313
DB_HOST: mariadb
1414
DB_DATABASE: bookstack

0 commit comments

Comments
 (0)