Issues (1426)

bin/dbconsole (1 issue)

1
#!/usr/bin/env bash
2
3
# Shortcut to run the dbconsole command in the Worker Container from the Host
4
5
# consts
6
COMPOSE_DEFAULT_ENV_FILE=.env
7
WORKER_SERVICE=worker
8
# vars
9
COMPOSE_LOCAL_ENV_FILE=${COMPOSE_LOCAL_ENV_FILE:-.env.local}
10
WORKER_CONTAINER=
11
WORKER_USER=
12
13
check_requirements() {
0 ignored issues
show
The mentioned parser error was in this brace group.
Loading history...
14
    which docker >/dev/null 2>&1
15
    if [ $? -ne 0 ]; then
16
        printf "\n\e[31mPlease install docker & add it to \$PATH\e[0m\n\n" >&2
17
        exit 1
18
    fi
19
}
20
21
load_config() {
22
    source ${COMPOSE_DEFAULT_ENV_FILE}
23
24
    if [ -f "${COMPOSE_LOCAL_ENV_FILE}" ]; then
25
        # these vars we have to export as otherwise they are not taken into account by docker-compose
26
        set -a
27
        source "${COMPOSE_LOCAL_ENV_FILE}"
28
        set +a
29
    fi
30
31
    # @todo run `docker-compose ps` to retrieve the WORKER_CONTAINER id instead of parsing the config
32
    if [ -z "${COMPOSE_PROJECT_NAME}" ]; then
33
        printf "\n\e[31mCan not find the name of the composer project name in ${COMPOSE_DEFAULT_ENV_FILE} / ${COMPOSE_LOCAL_ENV_FILE}\e[0m\n\n" >&2
34
        exit 1
35
    fi
36
    # @todo the value for WORKER_USER could be hardcoded instead of being variable...
37
    if [ -z "${CONTAINER_USER}" ]; then
38
        printf "\n\e[31mCan not find the name of the container user account in ${COMPOSE_DEFAULT_ENV_FILE} / ${COMPOSE_LOCAL_ENV_FILE}\e[0m\n\n" >&2
39
        exit 1
40
    fi
41
42
    WORKER_CONTAINER="${COMPOSE_PROJECT_NAME}_${WORKER_SERVICE}"
43
    WORKER_USER=${CONTAINER_USER}
44
}
45
46
### Begin live code
47
48
check_requirements
49
50
cd "$(dirname -- ${BASH_SOURCE[0]})/../docker"
51
52
load_config
53
54
# @todo check that stack has been built, and that worker bootstrap is done
55
56
docker exec -ti "${WORKER_CONTAINER}" su - "${WORKER_USER}" -c '"$0" "$@"' -- "/usr/bin/php" "app/bin/dbconsole" "$@"
57