dk: afficher l'adresse ip

This commit is contained in:
Jephté Clain 2019-04-17 02:31:09 +04:00
parent 7ec538187b
commit d7c981d257
1 changed files with 48 additions and 0 deletions

48
dk
View File

@ -32,6 +32,8 @@ COMMANDES
bs
Construire les images (comme avec build) puis démarrer les services
(comme avec start)
ip [SERVICE]
Afficher l'adresse IP interne du service
exec SERVICE COMMAND
Lancer la commande dans le container spécifié
systemd-unit
@ -546,6 +548,44 @@ function auto_down() {
fi
}
function default_compose_show_ip() {
local -a cmd cids; local cid
cmd=(
docker-compose
"${replace_env_args[@]}" "${env_args[@]}"
ps -q "${replace_show_ip_args[@]}" "${show_ip_args[@]}"
"$@"
)
if [ -n "$FAKE" ]; then
echo "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \"\$($(qvals "${cmd[@]}"))\""
else
setx -a cids="${cmd[@]}" 2>/dev/null
for cid in "${cids[@]}"; do
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$cid"
done
fi
}
function default_docker_show_ip() {
${FAKE:+qvals} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
"${replace_show_ip_args[@]}" "${show_ip_args[@]}" \
"$container_name" "$@"
}
function compose_show_ip() { default_compose_show_ip "$@"; }
function docker_show_ip() { default_docker_show_ip "$@"; }
function auto_show_ip() {
local -a replace_env_args env_args
local -a replace_show_ip_args show_ip_args
local project_name container_name
if [ -f docker-compose.yml ]; then
compose_set_env_args
compose_show_ip "$@"
else
docker_set_env_args
docker_check_name set_container_name
docker_show_ip "$@"
fi
}
function default_compose_exec() {
${FAKE:+qvals} docker-compose \
"${replace_env_args[@]}" "${env_args[@]}" \
@ -809,6 +849,14 @@ while [ $# -gt 0 ]; do
enote "Profil $PROFILE"
auto_build && auto_up "${args[@]}"
;;
ip|show-ip)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_show_ip "${args[@]}" || die
;;
x|exec)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do