Repository navigation
Expand file tree
/
Copy pathdocker-entrypoint
More file actions
executable file
·82 lines (64 loc) · 1.9 KB
/
Copy pathdocker-entrypoint
File metadata and controls
executable file
·82 lines (64 loc) · 1.9 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# Exit build script on first failure.
set -e
# Exit on unset variable.
set -u
PS_PROCESS_ARGS=("$@")
readonly -a PS_PROCESS_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}"
}
quote_litestream_command() {
local RESULT=''
local ARG
# Litestream 0.3 accepts -exec as one string and parses it with shellwords.
# Single-quote each argument so it reconstructs the original boundaries.
for ARG in "$@"; do
ARG=${ARG//\'/\'\\\'\'}
RESULT+="${RESULT:+ }'${ARG}'"
done
printf '%s\n' "${RESULT}"
}
IS_LITESTREAM_ENABLED="$(is_litestream_enabled)"
readonly IS_LITESTREAM_ENABLED
# Echo commands to stdout.
set -x
PS_LAUNCH_CMD="$(quote_litestream_command /app/picoshare "${PS_PROCESS_ARGS[@]}")"
readonly PS_LAUNCH_CMD
if [[ "${IS_LITESTREAM_ENABLED}" == 'true' ]]; then
/app/litestream version
echo "LITESTREAM_BUCKET=${LITESTREAM_BUCKET}"
echo "LITESTREAM_ENDPOINT=${LITESTREAM_ENDPOINT}"
echo "LITESTREAM_PATH=${LITESTREAM_PATH}"
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"
exec /app/picoshare "${PS_PROCESS_ARGS[@]}"
fi