From d7c981d257423d8958907d03a69b4cd286900c65 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 17 Apr 2019 02:31:09 +0400 Subject: [PATCH] dk: afficher l'adresse ip --- dk | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/dk b/dk index b26f85c..11327bc 100755 --- a/dk +++ b/dk @@ -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