From 6462bec2c6bddb37f6d0ba1e1a1b5836d2779c5f Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 28 Mar 2019 10:53:50 +0400 Subject: [PATCH] dk: ajouter exec, maj doc --- dk | 258 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 157 insertions(+), 101 deletions(-) diff --git a/dk b/dk index 1005dd0..8d1e22c 100755 --- a/dk +++ b/dk @@ -10,19 +10,40 @@ USAGE COMMANDES build + Construire les images push - start, run - service - stop + Pousser les images vers le serveur + start, run [SERVICE] + Démarrer le(s) service(s) + stop [SERVICE] + Arrêter le(s) service(s) up - logs + Créer l'environnement, démarrer les services et suivre les logs de façon + interactive. + logs [SERVICE] + Afficher les logs down + Arrêter les services et supprimer l'environnement brd + Construire les images (comme avec build), démarrer les services et + suivre les logs de façon interactive (comme avec up). Dès que l'on + arrête l'affichage des logs avec Ctrl+C, arrêter les services et + supprimer l'environnement (comme avec down) bs + Construire les images (comme avec build) puis démarrer les services + (comme avec start) + exec SERVICE COMMAND + Lancer la commande dans le container spécifié + service + Générer une unité systemd qui démarre les services ps + Afficher les containers en cours d'exécution ls + Lister les images actuellement présentes rm + Supprimer une image prune + Supprimer les containers et les images inutilisées OPTIONS -d, --chdir PROJDIR @@ -266,6 +287,122 @@ function auto_up() { fi } +function default_compose_stop() { + ${FAKE:+qvals} docker-compose \ + "${replace_env_args[@]}" "${env_args[@]}" \ + stop "${replace_stop_args[@]}" "${stop_args[@]}" \ + "$@" +} +function default_docker_stop() { + ${FAKE:+qvals} docker container stop \ + "${replace_stop_args[@]}" "${stop_args[@]}" \ + "$container_name" "$@" +} +function compose_stop() { default_compose_stop "$@"; } +function docker_stop() { default_docker_stop "$@"; } +function auto_stop() { + local -a replace_env_args env_args + local -a replace_stop_args stop_args + local project_name container_name + if [ -f docker-compose.yml ]; then + compose_set_env_args + compose_stop "$@" + else + docker_set_env_args + docker_check_name set_container_name + docker_stop "$@" + fi +} + +function default_compose_logs() { + ${FAKE:+qvals} docker-compose \ + "${replace_env_args[@]}" "${env_args[@]}" \ + logs "${replace_logs_args[@]}" "${logs_args[@]}" \ + "$@" +} +function default_docker_logs() { + ${FAKE:+qvals} docker logs \ + "${replace_logs_args[@]}" "${logs_args[@]}" \ + "$container_name" "$@" +} +function compose_logs() { default_compose_logs "$@"; } +function docker_logs() { default_docker_logs "$@"; } +function auto_logs() { + local -a replace_env_args env_args + local -a replace_logs_args logs_args + local project_name container_name + if [ -f docker-compose.yml ]; then + compose_set_env_args + replace_logs_args=(-f) + compose_logs "$@" + else + docker_set_env_args + docker_check_name set_container_name + replace_logs_args=(-f) + docker_logs "$@" + fi +} + +function default_compose_down() { + ${FAKE:+qvals} docker-compose \ + "${replace_env_args[@]}" "${env_args[@]}" \ + down "${replace_down_args[@]}" "${down_args[@]}" \ + "$@" +} +function default_docker_down() { + estep "stop" + ${FAKE:+qvals} docker container stop \ + "${replace_down_args[@]}" "${down_args[@]}" \ + "$container_name" "$@" + estep "rm" + ${FAKE:+qvals} docker container rm \ + "${replace_rm_args[@]}" "${rm_args[@]}" \ + "$container_name" +} +function compose_down() { default_compose_down "$@"; } +function docker_down() { default_docker_down "$@"; } +function auto_down() { + local -a replace_env_args env_args + local -a replace_down_args down_args + local -a replace_rm_args rm_args + local project_name container_name + if [ -f docker-compose.yml ]; then + compose_set_env_args + compose_down "$@" + else + docker_set_env_args + docker_check_name set_container_name + docker_down "$@" + fi +} + +function default_compose_exec() { + ${FAKE:+qvals} docker-compose \ + "${replace_env_args[@]}" "${env_args[@]}" \ + exec "${replace_exec_args[@]}" "${exec_args[@]}" \ + "$@" +} +function default_docker_exec() { + ${FAKE:+qvals} docker container exec \ + "${replace_exec_args[@]}" "${exec_args[@]}" \ + "$container_name" "$@" +} +function compose_exec() { default_compose_exec "$@"; } +function docker_exec() { default_docker_exec "$@"; } +function auto_exec() { + local -a replace_env_args env_args + local -a replace_exec_args exec_args + local project_name container_name + if [ -f docker-compose.yml ]; then + compose_set_env_args + compose_exec "$@" + else + docker_set_env_args + docker_check_name set_container_name + docker_exec "$@" + fi +} + function default_compose_service() { local docker_compose="$(which docker-compose 2>/dev/null)" if [ -z "$docker_compose" ]; then @@ -359,95 +496,6 @@ EOF local_run "$HOST" "$tmpscript" } -function default_compose_stop() { - ${FAKE:+qvals} docker-compose \ - "${replace_env_args[@]}" "${env_args[@]}" \ - stop "${replace_stop_args[@]}" "${stop_args[@]}" \ - "$@" -} -function default_docker_stop() { - ${FAKE:+qvals} docker container stop \ - "${replace_stop_args[@]}" "${stop_args[@]}" \ - "$container_name" "$@" -} -function compose_stop() { default_compose_stop "$@"; } -function docker_stop() { default_docker_stop "$@"; } -function auto_stop() { - local -a replace_env_args env_args - local -a replace_stop_args stop_args - local project_name container_name - if [ -f docker-compose.yml ]; then - compose_set_env_args - compose_stop "$@" - else - docker_set_env_args - docker_check_name set_container_name - docker_stop "$@" - fi -} - -function default_compose_logs() { - ${FAKE:+qvals} docker-compose \ - "${replace_env_args[@]}" "${env_args[@]}" \ - logs "${replace_logs_args[@]}" "${logs_args[@]}" \ - "$@" -} -function default_docker_logs() { - ${FAKE:+qvals} docker logs \ - "${replace_logs_args[@]}" "${logs_args[@]}" \ - "$container_name" "$@" -} -function compose_logs() { default_compose_logs "$@"; } -function docker_logs() { default_docker_logs "$@"; } -function auto_logs() { - local -a replace_env_args env_args - local -a replace_logs_args logs_args - local project_name container_name - if [ -f docker-compose.yml ]; then - compose_set_env_args - replace_logs_args=(-f) - compose_logs "$@" - else - docker_set_env_args - docker_check_name set_container_name - replace_logs_args=(-f) - docker_logs "$@" - fi -} - -function default_compose_down() { - ${FAKE:+qvals} docker-compose \ - "${replace_env_args[@]}" "${env_args[@]}" \ - down "${replace_down_args[@]}" "${down_args[@]}" \ - "$@" -} -function default_docker_down() { - estep "stop" - ${FAKE:+qvals} docker container stop \ - "${replace_down_args[@]}" "${down_args[@]}" \ - "$container_name" "$@" - estep "rm" - ${FAKE:+qvals} docker container rm \ - "${replace_rm_args[@]}" "${rm_args[@]}" \ - "$container_name" -} -function compose_down() { default_compose_down "$@"; } -function docker_down() { default_docker_down "$@"; } -function auto_down() { - local -a replace_env_args env_args - local -a replace_down_args down_args - local -a replace_rm_args rm_args - local project_name container_name - if [ -f docker-compose.yml ]; then - compose_set_env_args - compose_down "$@" - else - docker_set_env_args - docker_check_name set_container_name - docker_down "$@" - fi -} - DEFAULT_PROFILE=devel PROFILE= DM_PROFILES=() @@ -519,14 +567,6 @@ while [ $# -gt 0 ]; do enote "Profil $PROFILE" auto_up "${args[@]}" || die ;; - service) - args=() - while [ $# -gt 0 -a "$1" != -- ]; do - args+=("$1"); shift - done - enote "Profil $PROFILE" - auto_service "${args[@]}" || die - ;; k|stop) args=() while [ $# -gt 0 -a "$1" != -- ]; do @@ -589,6 +629,22 @@ while [ $# -gt 0 ]; do enote "Profil $PROFILE" auto_build && auto_up "${args[@]}" ;; + x|exec) + args=() + while [ $# -gt 0 -a "$1" != -- ]; do + args+=("$1"); shift + done + enote "Profil $PROFILE" + auto_exec "${args[@]}" || die + ;; + service) + args=() + while [ $# -gt 0 -a "$1" != -- ]; do + args+=("$1"); shift + done + enote "Profil $PROFILE" + auto_service "${args[@]}" || die + ;; ps) docker container ps -a || die;; ls) docker image ls || die;; rm)