Skip to content

Commit 4cb4610

Browse files
committed
Simplify init, prefer envs, make fewer assumptions
1 parent e32e3ce commit 4cb4610

File tree

7 files changed

+44
-175
lines changed

7 files changed

+44
-175
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG BUILD_DATE
77
ARG VERSION
88
ARG BOOKSTACK_RELEASE
99
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
10-
LABEL maintainer="homerr"
10+
LABEL maintainer="thespad"
1111

1212
ENV S6_STAGE2_HOOK="/init-hook"
1313

Dockerfile.aarch64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG BUILD_DATE
77
ARG VERSION
88
ARG BOOKSTACK_RELEASE
99
LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
10-
LABEL maintainer="homerr"
10+
LABEL maintainer="thespad"
1111

1212
ENV S6_STAGE2_HOOK="/init-hook"
1313

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ pipeline {
3131
PR_DOCKERHUB_IMAGE = 'lspipepr/bookstack'
3232
DIST_IMAGE = 'alpine'
3333
MULTIARCH = 'true'
34-
CI = 'true'
34+
CI = 'false'
3535
CI_WEB = 'false'
3636
CI_PORT = '80'
3737
CI_SSL = 'false'
3838
CI_DELAY = '60'
39-
CI_DOCKERENV='TEST_RUN=1'
39+
CI_DOCKERENV=''
4040
CI_AUTH = ''
4141
CI_WEBPATH = ''
4242
}

README.md

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Find us at:
3737
[![Docker Pulls](https://img.shields.io/docker/pulls/linuxserver/bookstack.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/r/linuxserver/bookstack)
3838
[![Docker Stars](https://img.shields.io/docker/stars/linuxserver/bookstack.svg?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=stars&logo=docker)](https://hub.docker.com/r/linuxserver/bookstack)
3939
[![Jenkins Build](https://img.shields.io/jenkins/build?labelColor=555555&logoColor=ffffff&style=for-the-badge&jobUrl=https%3A%2F%2Fci.linuxserver.io%2Fjob%2FDocker-Pipeline-Builders%2Fjob%2Fdocker-bookstack%2Fjob%2Fmaster%2F&logo=jenkins)](https://ci.linuxserver.io/job/Docker-Pipeline-Builders/job/docker-bookstack/job/master/)
40-
[![LSIO CI](https://img.shields.io/badge/dynamic/yaml?color=94398d&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=CI&query=CI&url=https%3A%2F%2Fci-tests.linuxserver.io%2Flinuxserver%2Fbookstack%2Flatest%2Fci-status.yml)](https://ci-tests.linuxserver.io/linuxserver/bookstack/latest/index.html)
4140

4241
[Bookstack](https://github.com/BookStackApp/BookStack) is a free and open source Wiki designed for creating beautiful documentation. Featuring a simple, but powerful WYSIWYG editor it allows for teams to create detailed and useful documentation with ease.
4342

@@ -63,11 +62,10 @@ The architectures supported by this image are:
6362

6463
## Application Setup
6564

66-
The default username is admin@admin.com with the password of **password**, access the container at http://dockerhost:6875.
65+
The default username is admin@admin.com with the password of **password**, access the container at http://<host ip>:6875.
6766

6867
This application is dependent on a MySQL database be it one you already have or a new one. If you do not already have one, set up our MariaDB container here https://hub.docker.com/r/linuxserver/mariadb/.
6968

70-
7169
If you intend to use this application behind a subfolder reverse proxy, such as our SWAG container or Traefik you will need to make sure that the `APP_URL` environment variable is set to your external domain, or it will not work.
7270

7371
Documentation for BookStack can be found at https://www.bookstackapp.com/docs/.
@@ -79,8 +77,8 @@ Below is a mapping of container `/config` paths to those relative within a BookS
7977

8078
- **/config container path** => **BookStack relative path**
8179
- `/config/www/.env` => `.env`
82-
- `/config/www/laravel.log` => `storage/logs/laravel.log`
83-
- `/config/www/backups/` => `storage/backups/`
80+
- `/config/log/bookstack/laravel.log` => `storage/logs/laravel.log`
81+
- `/config/backups/` => `storage/backups/`
8482
- `/config/www/files/` => `storage/uploads/files/`
8583
- `/config/www/images/` => `storage/uploads/images/`
8684
- `/config/www/themes/` => `themes/`
@@ -101,40 +99,24 @@ To help you get started creating a container from this image you can either use
10199
---
102100
services:
103101
bookstack:
104-
image: lscr.io/linuxserver/bookstack
102+
image: lscr.io/linuxserver/bookstack:latest
105103
container_name: bookstack
106104
environment:
107105
- PUID=1000
108106
- PGID=1000
109-
- TZ=Europe/London
110-
- APP_URL=https://bookstack.example.com
111-
- DB_HOST=bookstack_db
112-
- DB_PORT=3306
113-
- DB_USER=bookstack
114-
- DB_PASS=<yourdbpass>
107+
- TZ=Etc/UTC
108+
- APP_URL=yourbaseurl
109+
- DB_HOST=yourdbhost
110+
- DB_PORT=yourdbport
111+
- DB_USERNAME=yourdbuser
112+
- DB_PASSWORD=yourdbpass
115113
- DB_DATABASE=bookstackapp
114+
- QUEUE_CONNECTION= #optional
116115
volumes:
117-
- /path/to/bookstack_app_data:/config
116+
- /path/to/bookstack/config:/config
118117
ports:
119118
- 6875:80
120119
restart: unless-stopped
121-
depends_on:
122-
- bookstack_db
123-
124-
bookstack_db:
125-
image: lscr.io/linuxserver/mariadb
126-
container_name: bookstack_db
127-
environment:
128-
- PUID=1000
129-
- PGID=1000
130-
- TZ=Europe/London
131-
- MYSQL_ROOT_PASSWORD=<yourdbpass>
132-
- MYSQL_DATABASE=bookstackapp
133-
- MYSQL_USER=bookstack
134-
- MYSQL_PASSWORD=<yourdbpass>
135-
volumes:
136-
- /path/to/bookstack_db_data:/config
137-
restart: unless-stopped
138120
```
139121
140122
### docker cli ([click here for more info](https://docs.docker.com/engine/reference/commandline/cli/))
@@ -148,8 +130,8 @@ docker run -d \
148130
-e APP_URL=yourbaseurl \
149131
-e DB_HOST=yourdbhost \
150132
-e DB_PORT=yourdbport \
151-
-e DB_USER=yourdbuser \
152-
-e DB_PASS=yourdbpass \
133+
-e DB_USERNAME=yourdbuser \
134+
-e DB_PASSWORD=yourdbpass \
153135
-e DB_DATABASE=bookstackapp \
154136
-e QUEUE_CONNECTION= `#optional` \
155137
-p 6875:80 \
@@ -171,8 +153,8 @@ Containers are configured using parameters passed at runtime (such as those abov
171153
| `-e APP_URL=yourbaseurl` | for specifying the IP:port or URL your application will be accessed on (ie. `http://192.168.1.1:6875` or `https://bookstack.mydomain.com` |
172154
| `-e DB_HOST=yourdbhost` | for specifying the database host |
173155
| `-e DB_PORT=yourdbport` | for specifying the database port if not default 3306 |
174-
| `-e DB_USER=yourdbuser` | for specifying the database user |
175-
| `-e DB_PASS=yourdbpass` | for specifying the database password (minimum 4 characters & non-alphanumeric passwords must be properly escaped.) |
156+
| `-e DB_USERNAME=yourdbuser` | for specifying the database user |
157+
| `-e DB_PASSWORD=yourdbpass` | for specifying the database password (minimum 4 characters & non-alphanumeric passwords must be properly escaped.) |
176158
| `-e DB_DATABASE=bookstackapp` | for specifying the database to be used |
177159
| `-e QUEUE_CONNECTION=` | Set to `database` to enable async actions like sending email or triggering webhooks. See [documentation](https://www.bookstackapp.com/docs/admin/email-webhooks/#async-action-handling). |
178160
| `-v /config` | Persistent config files |
@@ -339,6 +321,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
339321

340322
## Versions
341323

324+
* **11.10.24:** - Default to environment config over .env file config.
342325
* **06.09.24:** - Add php-exif for reading image EXIF data.
343326
* **27.05.24:** - Rebase to Alpine 3.20. Existing users should update their nginx confs to avoid http2 deprecation warnings.
344327
* **25.01.24:** - Existing users should update: site-confs/default.conf - Cleanup default site conf.

jenkins-vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ repo_vars:
1919
- PR_DOCKERHUB_IMAGE = 'lspipepr/bookstack'
2020
- DIST_IMAGE = 'alpine'
2121
- MULTIARCH = 'true'
22-
- CI = 'true'
22+
- CI = 'false'
2323
- CI_WEB = 'false'
2424
- CI_PORT = '80'
2525
- CI_SSL = 'false'
2626
- CI_DELAY = '60'
27-
- CI_DOCKERENV='TEST_RUN=1'
27+
- CI_DOCKERENV=''
2828
- CI_AUTH = ''
2929
- CI_WEBPATH = ''

readme-vars.yml

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ param_env_vars:
2727
- { env_var: "APP_URL", env_value: "yourbaseurl", desc: "for specifying the IP:port or URL your application will be accessed on (ie. `http://192.168.1.1:6875` or `https://bookstack.mydomain.com`"}
2828
- { env_var: "DB_HOST", env_value: "yourdbhost", desc: "for specifying the database host" }
2929
- { env_var: "DB_PORT", env_value: "yourdbport", desc: "for specifying the database port if not default 3306" }
30-
- { env_var: "DB_USER", env_value: "yourdbuser", desc: "for specifying the database user" }
31-
- { env_var: "DB_PASS", env_value: "yourdbpass", desc: "for specifying the database password (minimum 4 characters & non-alphanumeric passwords must be properly escaped.)" }
30+
- { env_var: "DB_USERNAME", env_value: "yourdbuser", desc: "for specifying the database user" }
31+
- { env_var: "DB_PASSWORD", env_value: "yourdbpass", desc: "for specifying the database password (minimum 4 characters & non-alphanumeric passwords must be properly escaped.)" }
3232
- { env_var: "DB_DATABASE", env_value: "bookstackapp", desc: "for specifying the database to be used" }
3333

3434
param_usage_include_ports: true
@@ -39,80 +39,42 @@ opt_param_usage_include_env: true
3939
opt_param_env_vars:
4040
- { env_var: "QUEUE_CONNECTION", env_value: "", desc: "Set to `database` to enable async actions like sending email or triggering webhooks. See [documentation](https://www.bookstackapp.com/docs/admin/email-webhooks/#async-action-handling)." }
4141

42-
custom_compose: |
43-
---
44-
services:
45-
bookstack:
46-
image: lscr.io/linuxserver/bookstack
47-
container_name: bookstack
48-
environment:
49-
- PUID=1000
50-
- PGID=1000
51-
- TZ=Europe/London
52-
- APP_URL=https://bookstack.example.com
53-
- DB_HOST=bookstack_db
54-
- DB_PORT=3306
55-
- DB_USER=bookstack
56-
- DB_PASS=<yourdbpass>
57-
- DB_DATABASE=bookstackapp
58-
volumes:
59-
- /path/to/bookstack_app_data:/config
60-
ports:
61-
- 6875:80
62-
restart: unless-stopped
63-
depends_on:
64-
- bookstack_db
65-
66-
bookstack_db:
67-
image: lscr.io/linuxserver/mariadb
68-
container_name: bookstack_db
69-
environment:
70-
- PUID=1000
71-
- PGID=1000
72-
- TZ=Europe/London
73-
- MYSQL_ROOT_PASSWORD=<yourdbpass>
74-
- MYSQL_DATABASE=bookstackapp
75-
- MYSQL_USER=bookstack
76-
- MYSQL_PASSWORD=<yourdbpass>
77-
volumes:
78-
- /path/to/bookstack_db_data:/config
79-
restart: unless-stopped
80-
8142
# application setup block
8243
app_setup_block_enabled: true
8344
app_setup_block: |
8445
85-
The default username is admin@admin.com with the password of **password**, access the container at http://dockerhost:6875.
46+
The default username is admin@admin.com with the password of **password**, access the container at http://<host ip>:6875.
8647
8748
This application is dependent on a MySQL database be it one you already have or a new one. If you do not already have one, set up our MariaDB container here https://hub.docker.com/r/linuxserver/mariadb/.
8849
89-
9050
If you intend to use this application behind a subfolder reverse proxy, such as our SWAG container or Traefik you will need to make sure that the `APP_URL` environment variable is set to your external domain, or it will not work.
9151
9252
Documentation for BookStack can be found at https://www.bookstackapp.com/docs/.
9353
9454
### BookStack File & Directory Paths
55+
9556
This container ensures certain BookStack application files & folders, such as user file upload folders, are retained within the `/config` folder so that they are persistent & accessible when the `/config` container path is bound as a volume. There may be cases, when following the BookStack documentation, that you'll need to know how these files and folders are used relative to a non-container BookStack installation.
9657
9758
Below is a mapping of container `/config` paths to those relative within a BookStack install directory:
9859
9960
- **/config container path** => **BookStack relative path**
10061
- `/config/www/.env` => `.env`
101-
- `/config/www/laravel.log` => `storage/logs/laravel.log`
102-
- `/config/www/backups/` => `storage/backups/`
62+
- `/config/log/bookstack/laravel.log` => `storage/logs/laravel.log`
63+
- `/config/backups/` => `storage/backups/`
10364
- `/config/www/files/` => `storage/uploads/files/`
10465
- `/config/www/images/` => `storage/uploads/images/`
10566
- `/config/www/themes/` => `themes/`
10667
- `/config/www/uploads/` => `public/uploads/`
10768
10869
### Advanced Users (full control over the .env file)
70+
10971
If you wish to use the extra functionality of BookStack such as email, Memcache, LDAP and so on you will need to make your own .env file with guidance from the BookStack documentation.
11072
11173
When you create the container, do not set any arguments for any SQL settings. The container will copy an exemplary .env file to /config/www/.env on your host system for you to edit.
11274
113-
11475
# changelog
11576
changelogs:
77+
- { date: "11.10.24:", desc: "Default to environment config over .env file config."}
11678
- { date: "06.09.24:", desc: "Add php-exif for reading image EXIF data."}
11779
- { date: "27.05.24:", desc: "Rebase to Alpine 3.20. Existing users should update their nginx confs to avoid http2 deprecation warnings."}
11880
- { date: "25.01.24:", desc: "Existing users should update: site-confs/default.conf - Cleanup default site conf." }

root/etc/s6-overlay/s6-rc.d/init-bookstack-config/run

Lines changed: 13 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -44,86 +44,13 @@ if [[ ! -L "/app/www/storage/logs" ]]; then
4444
ln -s "/config/log/bookstack" "/app/www/storage/logs"
4545
fi
4646

47-
# Echo init finish for test runs
48-
if [ -n "${TEST_RUN}" ]; then
49-
echo '[ls.io-init] done.'
50-
fi
51-
52-
# Create API key if needed
53-
if [ ! -f "/config/BOOKSTACK_APP_KEY.txt" ]; then
54-
echo "Generating BookStack app key for first run"
55-
key=$(php /app/www/artisan key:generate --show)
56-
echo "${key}" >/config/BOOKSTACK_APP_KEY.txt
57-
echo "App Key set to ${key} you can modify the file to update /config/BOOKSTACK_APP_KEY.txt"
58-
elif [ -f "/config/BOOKSTACK_APP_KEY.txt" ]; then
59-
echo "App Key found - setting variable for seds"
60-
key=$(cat /config/BOOKSTACK_APP_KEY.txt)
61-
fi
62-
63-
# .env file setup
64-
# check for the default app key or if it has been updated
65-
if ! grep -Fxq "APP_KEY=${key}" /config/www/.env; then
66-
sed -i "s#^APP_KEY=.*#APP_KEY=${key}#" /config/www/.env
67-
fi
68-
69-
# if DB_HOST contains a port and DB_HOST is not a IPv6 without brackets [..]
70-
# support ipv4:port, [ipv6]:port, and domain:port
71-
if [[ ${DB_HOST} =~ :[0-9]+$ ]] && ! [[ ${DB_HOST} =~ ^(:{0,2}[a-fA-F0-9]{1,4})+$ ]]; then
72-
DB_HOST_PORT="${DB_HOST}"
73-
fi
74-
75-
# if DB_HOST_PORT is set
76-
if [[ -n "${DB_HOST_PORT}" ]]; then
77-
# if DB_PORT is set
78-
if [[ -n "${DB_PORT}" ]]; then
79-
echo "DB_PORT is not supported when using DB_HOST with port"
47+
# Check for app key
48+
if [[ -z ${APP_KEY} ]]; then
49+
if ! grep -qE "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /app/www/.env 2> /dev/null; then
50+
echo "An application key is missing, halting init!"
51+
echo "You can generate a key with: docker exec -it bookstack php /app/www/artisan key:generate --show"
8052
sleep infinity
8153
fi
82-
DB_HOST="${DB_HOST_PORT%:*}"
83-
DB_PORT="${DB_HOST_PORT##*:}"
84-
fi
85-
86-
# if DB_PORT is not set
87-
if [[ -z "${DB_PORT}" ]]; then
88-
DB_PORT="3306"
89-
fi
90-
91-
# check to see if DB_HOST is set, if it is then run seds and if not then leave them
92-
if [[ -n "${DB_HOST}" ]]; then
93-
echo "Running config - DB_HOST set"
94-
95-
if ! grep -xqE "^[#]?DB_PORT=.*" /config/www/.env; then
96-
# add DB_PORT line to /config/www/.env because current /app/www/.env.example doesn't have it
97-
sed -i -E "/^[#]?DB_HOST=.*/a DB_PORT='${DB_PORT}'" /config/www/.env
98-
echo "**** Insert DB_PORT='${DB_PORT}' into /config/www/.env ****"
99-
fi
100-
101-
sed -i -E "s/^[#]?DB_HOST=.*/DB_HOST='${DB_HOST}'/g" /config/www/.env
102-
sed -i -E "s/^[#]?DB_PORT=.*/DB_PORT='${DB_PORT}'/g" /config/www/.env
103-
SED_DB_DATABASE=$(sed -e 's|[&\\/]|\\&|g; s|$|\\|; $s|\\$||' <<<"${DB_DATABASE}")
104-
sed -i -E "s/^[#]?DB_DATABASE=.*/DB_DATABASE='${SED_DB_DATABASE}'/g" /config/www/.env
105-
SED_DB_USER=$(sed -e 's|[&\\/]|\\&|g; s|$|\\|; $s|\\$||' <<<"${DB_USER}")
106-
sed -i -E "s/^[#]?DB_USERNAME=.*/DB_USERNAME='${SED_DB_USER}'/g" /config/www/.env
107-
SED_DB_PASS=$(sed -e 's|[&\\/]|\\&|g; s|$|\\|; $s|\\$||' <<<"${DB_PASS}")
108-
sed -i -E "s/^[#]?DB_PASSWORD=.*/DB_PASSWORD='${SED_DB_PASS}'/g" /config/www/.env
109-
fi
110-
111-
# set appurl
112-
if [ -z "${APP_URL}" ]; then
113-
EXT_IP=$(curl -s https://icanhazip.com)
114-
APP_URL="http://${EXT_IP}:6875"
115-
echo "**** Docker env var APP_URL is not set, setting it to ${APP_URL} ****"
116-
fi
117-
OLD_URL=$(grep APP_URL /config/www/.env | sed 's|.*APP_URL=||g')
118-
if [ "${APP_URL}" != "${OLD_URL}" ]; then
119-
sed -r "s,([#\s]*)?APP_URL=.*,APP_URL=${APP_URL},g" -i /config/www/.env
120-
echo "**** APP_URL in /config/www/.env is being updated from ${OLD_URL} to ${APP_URL} ****"
121-
if [ "${OLD_URL}" != "http://example.com" ]; then
122-
echo "**** If this is an existing install, you should run the following line from your host terminal to update the database URL entries: ****"
123-
echo "************************************************************************"
124-
echo "docker exec -it bookstack php /app/www/artisan bookstack:update-url ${OLD_URL} ${APP_URL}"
125-
echo "************************************************************************"
126-
fi
12754
fi
12855

12956
## Bump php upload max filesize and post max size to 100MB by default
@@ -134,33 +61,30 @@ if ! grep -qx '^post_max_size.*$' /config/php/php-local.ini; then
13461
echo 'post_max_size = 100M' >>/config/php/php-local.ini
13562
fi
13663

64+
# if DB_PORT is not set
65+
if [[ -z "${DB_PORT}" ]]; then
66+
DB_PORT="3306"
67+
fi
68+
13769
# check for the mysql endpoint
13870
echo "Waiting for DB to be available"
13971
END=$((SECONDS + 30))
14072
while [[ ${SECONDS} -lt ${END} ]] && [[ -n "${DB_HOST+x}" ]]; do
14173
if [[ $(/usr/bin/nc -w1 "${DB_HOST}" "${DB_PORT}" | tr -d '\0') ]]; then
142-
if [[ -n "${RUN}" ]]; then
143-
break
144-
fi
145-
RUN="RAN"
146-
# we sleep here again due to first run init on DB containers
14774
if [[ ! -f /dbwait.lock ]]; then
14875
sleep 5
14976
fi
77+
touch /dbwait.lock
78+
break
15079
else
15180
sleep 1
15281
fi
15382
done
15483

15584
# update database - will set up database if fresh, or, migrate existing
156-
if [ -z "${CI_RUN+x}" ]; then
157-
php /app/www/artisan migrate --force
158-
fi
85+
php /app/www/artisan migrate --force
15986

16087
# permissions
16188
lsiown -R abc:abc \
16289
/app/www/storage \
16390
/config
164-
165-
# set lockfile to avoid DB waits for this specific container
166-
touch /dbwait.lock

0 commit comments

Comments
 (0)