2019-05-21 09:31:23 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
2023-01-25 17:14:03 +04:00
|
|
|
source "$(dirname -- "$0")/lib/ulib/auto" || exit 1
|
2019-05-21 09:31:23 +04:00
|
|
|
|
2023-03-15 16:15:44 +04:00
|
|
|
[ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose)
|
|
|
|
|
2019-05-21 09:31:23 +04:00
|
|
|
function display_help() {
|
|
|
|
uecho "$scriptname: ouvrir un shell dans le container
|
|
|
|
|
|
|
|
USAGE
|
2022-06-26 16:11:28 +04:00
|
|
|
$scriptname [CMD...]
|
2019-05-21 09:31:23 +04:00
|
|
|
|
|
|
|
OPTIONS
|
2023-03-15 16:15:44 +04:00
|
|
|
--compose-v1
|
|
|
|
Forcer l'utilisation de docker-compose v1
|
2019-05-21 09:31:23 +04:00
|
|
|
-h, -s, --service SERVICE
|
|
|
|
Spécifier le nom du service sur lequel ouvrir le shell
|
2022-06-26 16:11:28 +04:00
|
|
|
-d, --db
|
2019-05-21 09:31:23 +04:00
|
|
|
équivalent à -s db
|
2022-06-26 16:11:28 +04:00
|
|
|
-w, --web
|
2019-05-21 09:31:23 +04:00
|
|
|
équivalent à -s web (c'est la valeur par défaut)"
|
|
|
|
}
|
|
|
|
|
|
|
|
service=web
|
|
|
|
args=(
|
|
|
|
--help '$exit_with display_help'
|
2023-03-15 16:15:44 +04:00
|
|
|
--compose-v1 '$DOCKER_COMPOSE=(docker-compose)'
|
2019-05-21 09:31:23 +04:00
|
|
|
-h:,-s:,--service: service=
|
2022-06-26 16:11:28 +04:00
|
|
|
-d,--db service=db
|
|
|
|
-w,--web service=web
|
2019-05-21 09:31:23 +04:00
|
|
|
)
|
|
|
|
parse_args "$@"; set -- "${args[@]}"
|
|
|
|
|
|
|
|
[ -n "$service" ] || die "Vous devez spécifier le nom du service"
|
|
|
|
|
|
|
|
found=
|
|
|
|
first=1
|
|
|
|
while true; do
|
|
|
|
if [ -f composer.json ]; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
first=
|
|
|
|
cd ..
|
|
|
|
if [ "$(pwd)" == "$HOME" ]; then
|
|
|
|
die "Cette commande ne peut être lancée que depuis un projet Composer"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -z "$first" ]; then
|
|
|
|
enote "Le répertoire du projet est $(ppath . ~)"
|
|
|
|
fi
|
|
|
|
|
2019-05-21 09:40:15 +04:00
|
|
|
###
|
|
|
|
|
2023-03-15 16:15:44 +04:00
|
|
|
setx cid="${DOCKER_COMPOSE[@]}" ps -q "$service" 2>/dev/null || die "$service: service introuvable"
|
2019-05-21 09:31:23 +04:00
|
|
|
|
|
|
|
cmd=("$@")
|
|
|
|
[ ${#cmd[*]} -gt 0 ] || cmd=(bash)
|
|
|
|
|
2023-03-15 16:15:44 +04:00
|
|
|
"${DOCKER_COMPOSE[@]}" exec "$service" "${cmd[@]}"
|