docker/server/entrypoint.sh
author ymh <ymh.work@gmail.com>
Mon, 29 Jul 2024 23:18:55 +0200
changeset 131 2a18dfe8bfc0
parent 129 f6b392c37e10
permissions -rwxr-xr-x
last change before install
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
129
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env bash
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
set -Eeuo pipefail
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
# from https://stackoverflow.com/a/45977232
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
# Following regex is based on https://www.rfc-editor.org/rfc/rfc3986#appendix-B with
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
# additional sub-expressions to split authority into userinfo, host and port
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
#
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
readonly URI_REGEX='^(([^:/?#]+):)?(//((([^/?#]+)@)?([^:/?#]+)(:([0-9]+))?))?(/([^?#]*))(\?([^#]*))?(#(.*))?'
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
#                    ↑↑            ↑  ↑↑↑            ↑         ↑ ↑            ↑ ↑        ↑  ↑        ↑ ↑
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
#                    |2 scheme     |  ||6 userinfo   7 host    | 9 port       | 11 rpath |  13 query | 15 fragment
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
#                    1 scheme:     |  |5 userinfo@             8 :…           10 path    12 ?…       14 #…
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
#                                  |  4 authority
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
#                                  3 //…
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
parse_host () {
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[7]}"
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
}
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
parse_port () {
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[9]}"
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
}
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
dbhost=$(parse_host "${DATABASE_URL}")
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
dbport=$(parse_port "${DATABASE_URL}")
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
cd ${BASEDIR}
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
if [[ "$*" =~ 'uwsgi' ]]; then
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    echo "Waiting for postgres on ${dbhost}:${dbport}..."
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    while ! nc -z ${dbhost} ${dbport}; do
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        sleep 0.1
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    done
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    echo "PostgreSQL started"
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    python manage.py syncdb --migrate
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    python manage.py collectstatic --noinput --clear
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
fi
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
f6b392c37e10 lucene 7.7.1 compiled but not compatible with ldt indexation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
exec "$@"