-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
71 lines (55 loc) · 1.98 KB
/
docker-entrypoint.sh
File metadata and controls
71 lines (55 loc) · 1.98 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
#!/bin/sh
set -o errexit
set -o nounset
# Optional runtime settings (host-friendly permissions, TZ, umask).
if [ -n "${TZ:-}" ] && [ -e "/usr/share/zoneinfo/${TZ}" ]; then
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
fi
if [ -n "${UMASK:-}" ]; then
umask "${UMASK}"
fi
# Ensure Caddy data dir exists for storage (certs, etc.).
mkdir -p /data
# Create initial configuration:
mkdir -p /etc/caddy
if [ -n "${PUID:-}" ] || [ -n "${PGID:-}" ]; then
PUID="${PUID:-1000}"
PGID="${PGID:-1000}"
if [ "${PUID}" -ne 0 ] || [ "${PGID}" -ne 0 ]; then
if [ -S /tmp/docker.sock ]; then
DOCKER_GID="$(stat -c '%g' /tmp/docker.sock)"
if ! awk -F: -v gid="${DOCKER_GID}" '$3==gid{found=1} END{exit !found}' /etc/group; then
addgroup -g "${DOCKER_GID}" docker
fi
fi
group_name="$(awk -F: -v gid="${PGID}" '$3==gid{print $1}' /etc/group)"
if [ -z "${group_name}" ]; then
addgroup -g "${PGID}" caddy
group_name="caddy"
fi
if ! grep -q '^caddy:' /etc/passwd; then
adduser -D -H -u "${PUID}" -G "${group_name}" caddy
fi
if [ -S /tmp/docker.sock ]; then
DOCKER_GID="$(stat -c '%g' /tmp/docker.sock)"
docker_group="$(awk -F: -v gid="${DOCKER_GID}" '$3==gid{print $1}' /etc/group)"
if [ -n "${docker_group}" ]; then
addgroup caddy "${docker_group}"
fi
fi
fi
chown -R "${PUID}:${PGID}" /etc/caddy /data 2>/dev/null || true
fi
cp /code/caddy/Caddyfile /etc/caddy/Caddyfile
mkdir -p /etc/caddy/conf.d
mkdir -p /etc/caddy/default.d
docker-gen -only-exposed /code/templates/Caddyfile.tmpl /etc/caddy/default.d/default.caddy
echo "first execution success"
# Execute passed command:
if [ -n "${PUID:-}" ] || [ -n "${PGID:-}" ]; then
if [ "${PUID:-1000}" -ne 0 ] || [ "${PGID:-1000}" -ne 0 ]; then
exec su-exec caddy "$@"
fi
fi
exec "$@"