-
Notifications
You must be signed in to change notification settings - Fork 168
/
docker-entrypoint
executable file
·66 lines (51 loc) · 1.43 KB
/
docker-entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Exit build script on first failure.
set -e
# Exit on unset variable.
set -u
PS_ARGS="$*"
readonly PS_ARGS
# Parse the -db flag to PicoShare since we need to know it before passing it
# along.
while [ "$#" -gt 0 ]; do
case "$1" in
-db) DB_PATH="$2"; shift 2;;
-db=*) DB_PATH="${1#*=}"; shift 1;;
*) shift 1;;
esac
done
readonly DB_PATH
# We need to export DB_PATH because litestream.yml references it.
export DB_PATH
is_litestream_enabled() {
set +ux
local IS_ENABLED='false'
if [[ -n "${LITESTREAM_BUCKET}" ]]; then
IS_ENABLED='true';
fi
set -ux
echo "${IS_ENABLED}"
}
IS_LITESTREAM_ENABLED="$(is_litestream_enabled)"
readonly IS_LITESTREAM_ENABLED
# Echo commands to stdout.
set -x
PS_LAUNCH_CMD="/app/picoshare ${PS_ARGS}"
if [[ "${IS_LITESTREAM_ENABLED}" == 'true' ]]; then
/app/litestream version
echo "LITESTREAM_BUCKET=${LITESTREAM_BUCKET}"
echo "LITESTREAM_ENDPOINT=${LITESTREAM_ENDPOINT}"
echo "LITESTREAM_RETENTION=${LITESTREAM_RETENTION}"
if [[ -f "$DB_PATH" ]]; then
echo "Existing database is $(stat -c %s "${DB_PATH}") bytes"
else
echo "No existing database found"
# Restore database from remote storage.
/app/litestream restore -if-replica-exists "${DB_PATH}"
fi
# Let Litestream start PicoShare as a child process
exec /app/litestream replicate -exec "$PS_LAUNCH_CMD"
else
echo "Starting without litestream"
eval "exec ${PS_LAUNCH_CMD}"
fi