File: chp-docker-entrypoint

package info (click to toggle)
node-configurable-http-proxy 4.5.3%2B~cs15.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,580 kB
  • sloc: javascript: 10,340; sh: 27; makefile: 22
file content (44 lines) | stat: -rwxr-xr-x 1,228 bytes parent folder | download
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
#!/bin/sh
# Wrapper around CHP entrypoint that changes defaults slightly
# to be more appropriate when run in a container.

# usage: file_env VAR [DEFAULT]
#    ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
#  "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
    var=$1
    file_var="${var}_FILE"
    var_value=$(printenv $var || true)
    file_var_value=$(printenv $file_var || true)
    default_value=$2

    if [ -n "$var_value" -a -n "$file_var_value" ]; then
        echo >&2 "error: both $var and $file_var are set (but are exclusive)"
        exit 1
    fi

    if [ -z "${var_value}" ]; then
        if [ -z "${file_var_value}" ]; then
            export "${var}"="${default_value}"
        else
            export "${var}"="$(cat $file_var_value)"
        fi
    fi

    unset "$file_var"
}

file_env 'CONFIGPROXY_AUTH_TOKEN'

case "$@" in
    *"--api-ip"*)
        break ;;
    *)
        # Default api-ip to all interfaces in docker,
        # so that it is accessible to other containers
        # and when port-forwarding is requested.
        ARGS="--api-ip=0.0.0.0" ;;
esac

exec configurable-http-proxy $ARGS "$@"