Skip to content

Commit 2aa908e

Browse files
authored
Refine docker deployment (#973)
2 parents 7e9eb05 + 1a78a02 commit 2aa908e

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

docker/caddy/Caddyfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,33 @@
1111
max_size {$TEKST_MAX_REQ_SIZE:250MB}
1212
}
1313

14+
# redirect root requests to use trailing slash
15+
@root expression {path} == "{$TEKST_WEB_PATH}"
16+
redir @root {$TEKST_WEB_PATH}/
17+
1418
# redirect API requests to use trailing slash
15-
redir /api /api/
19+
redir {$TEKST_WEB_PATH}/api {$TEKST_WEB_PATH}/api/
1620

1721
# proxy all API requests to API app
18-
handle_path /api/* {
22+
handle_path {$TEKST_WEB_PATH}/api/* {
1923
reverse_proxy http://127.0.0.1:8000
2024
}
2125

2226
# serve static files (custom assets)
23-
handle_path /static/* {
27+
handle_path {$TEKST_WEB_PATH}/static/* {
2428
root * /var/www/tekst/static
2529
file_server
2630
}
2731

2832
# help browsers to find the custom favicon at root
2933
# (ofc this only works if the app is served at root path "/")
30-
handle_path /favicon.ico {
31-
root * /var/www/tekst/static
34+
handle_path {$TEKST_WEB_PATH}/favicon.ico {
35+
root /var/www/tekst/static/favicon.ico
3236
file_server
3337
}
3438

3539
# serve web client files
36-
handle_path /* {
40+
handle_path {$TEKST_WEB_PATH}/* {
3741
root * /var/www/html
3842
try_files {path} /index.html
3943
file_server

docker/entrypoint.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
#!/bin/sh
1+
#!/bin/sh -e
22

33
# run DB migration if arg #1 is "migrate"
4-
if [ "$1" = "migrate" ]; then
4+
if [[ "$1" == "migrate" ]]; then
55
python3 -m tekst migrate
66
exit $?
7-
fi;
7+
fi
88

99
# run bootstrapping routine first
1010
python3 -m tekst bootstrap
11-
test $? -ne 0 && exit 1
1211

1312
# remove (all) trailing slashes from TEKST_WEB_PATH
1413
TEKST_WEB_PATH=$(echo "$TEKST_WEB_PATH" | sed 's|/*$||')
14+
1515
# remove existing base tag from client's index.html, if any
16-
sed -i 's|<base href=".*">||g' /var/www/html/index.html
17-
# inject base tag with base URL into client's index.html
18-
sed -i 's|<head>|<head><base href="'"$TEKST_WEB_PATH"'/" />|g' /var/www/html/index.html
16+
# and inject base tag with base URL into client's index.html
17+
sed -Ei /var/www/html/index.html -e 's|<base [^>]+>||' \
18+
-e 's|<head>|\0<base href="'"$TEKST_WEB_PATH/"'" />|'
1919

2020
# start caddy (will detach and run in background after startup)
2121
caddy start --config /etc/caddy/Caddyfile

0 commit comments

Comments
 (0)