Intégration de la branche dk-deploy
This commit is contained in:
		
						commit
						fb96852bf6
					
				
							
								
								
									
										279
									
								
								dk
									
									
									
									
									
								
							
							
						
						
									
										279
									
								
								dk
									
									
									
									
									
								
							| @ -9,39 +9,69 @@ USAGE | ||||
|     $scriptname CMDs... | ||||
| 
 | ||||
| COMMANDES | ||||
|     build [SERVICE] | ||||
|     b|build [SERVICE] | ||||
|         Construire les images | ||||
|     push | ||||
|     push [SERVICES...] | ||||
|     p|push | ||||
|     p|push [SERVICES...] | ||||
|         La première syntaxe est utilisable avec un projet docker. Elle permet de | ||||
|         pousser l'image qui a été construite avec build vers le serveur | ||||
|         La deuxième syntaxe est utilisée avec un projet docker-compose. Elle | ||||
|         permet de pousser les images correspondant aux services qui ont été | ||||
|         construit vers le serveur. | ||||
|     start, run [SERVICE] | ||||
|     s|start|run [SERVICE] | ||||
|         Démarrer le(s) service(s) | ||||
|     stop [SERVICE] | ||||
|     k|stop [SERVICE] | ||||
|         Arrêter le(s) service(s) | ||||
|     up | ||||
|     1|up | ||||
|         Créer l'environnement, démarrer les services et suivre les logs de façon | ||||
|         interactive. | ||||
|     logs [SERVICE] | ||||
|         Vaguement équivalent à -- start -- logs | ||||
|     l|logs [SERVICE] | ||||
|         Afficher les logs | ||||
|     down | ||||
|     0|down | ||||
|         Arrêter les services et supprimer l'environnement | ||||
|     brd | ||||
|     d|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) | ||||
|         Vaguement équivalent à -- build -- start [args] -- logs | ||||
|                       suivi de -- down | ||||
|     bs | ||||
|         Construire les images (comme avec build) puis démarrer les services | ||||
|         (comme avec start) | ||||
|     ip [SERVICE] | ||||
|         Equivalent à -- build -- start [args] | ||||
|     y|deploy [args...] | ||||
|         (Re)déployer un stack. Cette commande ne fonctionne qu'en mode swarm. | ||||
|         Implique --stack | ||||
|     by|bd [args...] | ||||
|         Equivalent à --stack -- build -- deploy args... | ||||
|         Utilisable notamment en développement | ||||
|     bp [args...] | ||||
|         Equivalent à --stack -- build -- push args... | ||||
|     bpy|bpd [args...] | ||||
|         Equivalent à --stack -- build -- push -- deploy args... | ||||
|     service COMMAND SERVICE [args...] | ||||
|         Frontend pour 'docker service COMMAND args... SERVICE' | ||||
|         Cette commande ne fonctionne qu'en mode swarm. Il n'est pas nécessaire | ||||
|         de préfixer le nom du service avec le nom du stack, pour être cohérent | ||||
|         avec les autres commandes | ||||
|         IMPORTANT: notez que les arguments sont placés avant le nom du service. | ||||
|         Celà signifie qu'on ne peut spécifier que des options à la commande. | ||||
|         Penser aussi à protéger ces options de l'analyse eg. | ||||
|             $scriptname -- service logs web -f | ||||
|         Pour des cas d'utilisation plus complexe, il faut lancer directement | ||||
|         docker service | ||||
|     u|update SERVICE [args...] | ||||
|         Mettre à jour un service, équivalent à 'service update SERVICE' | ||||
|     scale SERVICE=REPLICAS [args...] | ||||
|         Mettre à jour le nom de réplicas d'un service, équivalent à la commande | ||||
|         'service scale SERVICE=REPLICAS' | ||||
|     ip|show-ip [SERVICE] | ||||
|         Afficher l'adresse IP interne du service | ||||
|     exec SERVICE COMMAND | ||||
|     x|exec SERVICE COMMAND | ||||
|         Lancer la commande dans le container spécifié | ||||
|     systemd-unit | ||||
|     systemd|systemd-unit | ||||
|         Générer une unité systemd qui démarre les services. A priori, ce n'est | ||||
|         nécessaire que si aucune politique de redémarrage n'a été définie. | ||||
|     ps | ||||
| @ -50,7 +80,7 @@ COMMANDES | ||||
|         Lister les images actuellement présentes | ||||
|     rm | ||||
|         Supprimer une image | ||||
|     prune | ||||
|     X|prune | ||||
|         Supprimer les containers et les images inutilisées | ||||
| 
 | ||||
| OPTIONS générales | ||||
| @ -70,7 +100,15 @@ OPTIONS générales | ||||
|         Spécifier l'hôte pour la commande systemd-unit | ||||
| 
 | ||||
| OPTIONS build | ||||
|     (ces options ne sont valides que pour les commandes build, brd, bs) | ||||
|     (ces options ne sont valides que pour les commandes build, brd, bs, bd, bpd) | ||||
|     --stack | ||||
|         Indiquer que le build est fait pour un déploiement avec deploy. | ||||
|         S'il existe un fichier docker-stack.yml, il est utilisé de préférence à | ||||
|         la place de docker-compose.yml. De même, les fichiers de profil de la | ||||
|         forme docker-stack.PROFILE.yml sont utilisés de préférence aux fichiers | ||||
|         docker-compose.PROFILE.yml | ||||
|         Cette option n'est nécessaire qu'avec build puisque les commandes | ||||
|         deploy, bd, bpd et update impliquent --stack | ||||
|     -j, --no-cache | ||||
|         Ne pas utiliser le cache lors du build | ||||
|     -g, --ug, --no-update-apps | ||||
| @ -93,6 +131,11 @@ OPTIONS build | ||||
|     --ub, --update-apps-branch BRANCH | ||||
|         Spécifier la branche par défaut pour update-apps | ||||
| 
 | ||||
| OPTIONS deploy | ||||
|     -l, --without-registry-auth | ||||
|         Ne pas transporter les informations d'autorisation aux agents swarm | ||||
|         (c'est à dire ne pas utiliser l'option --with-registry-auth) | ||||
| 
 | ||||
| VARIABLES de update-apps.conf | ||||
|     ORIGIN | ||||
|         vaut 'origin' par défaut | ||||
| @ -168,12 +211,7 @@ function docker_check_name() { | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| function compose_set_env_args() { | ||||
|     replace_env_args+=(-f docker-compose.yml) | ||||
|     if [ -f docker-compose.override.yml ]; then | ||||
|         replace_env_args+=(-f docker-compose.override.yml) | ||||
|     fi | ||||
| 
 | ||||
| function compose_set_project_name() { | ||||
|     local PROJECT_NAME= PROJECT_NAME_REMOVE_SUFFIX=.service PROJECT_NAME_ADD_PROFILE=1 | ||||
|     [ -f .compose.env ] && source ./.compose.env | ||||
| 
 | ||||
| @ -181,9 +219,6 @@ function compose_set_env_args() { | ||||
|     PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}" | ||||
| 
 | ||||
|     if [ -n "$PROFILE" ]; then | ||||
|         if [ -f "docker-compose.$PROFILE.yml" ]; then | ||||
|             replace_env_args+=(-f "docker-compose.$PROFILE.yml") | ||||
|         fi | ||||
|         [ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME${PROJECT_NAME_ADD_PROFILE:+_${PROFILE}}" | ||||
|     else | ||||
|         [ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME" | ||||
| @ -196,6 +231,48 @@ function compose_set_env_args() { | ||||
|         [ -n "$PROFILE" -a -n "$PROJECT_NAME_ADD_PROFILE" ] && container_name="${container_name}_$PROFILE" | ||||
|     fi | ||||
| } | ||||
| function compose_set_env_args() { | ||||
|     if [ -n "$USE_STACK" -a -f docker-stack.yml ]; then | ||||
|         replace_env_args+=(-f docker-stack.yml) | ||||
|     else | ||||
|         replace_env_args+=(-f docker-compose.yml) | ||||
|     fi | ||||
|     if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then | ||||
|         replace_env_args+=(-f docker-stack.override.yml) | ||||
|     elif [ -f docker-compose.override.yml ]; then | ||||
|         replace_env_args+=(-f docker-compose.override.yml) | ||||
|     fi | ||||
|     if [ -n "$PROFILE" ]; then | ||||
|         if [ -n "$USE_STACK" -a -f "docker-stack.$PROFILE.yml" ]; then | ||||
|             replace_env_args+=(-f "docker-stack.$PROFILE.yml") | ||||
|         elif [ -f "docker-compose.$PROFILE.yml" ]; then | ||||
|             replace_env_args+=(-f "docker-compose.$PROFILE.yml") | ||||
|         fi | ||||
|     fi | ||||
| 
 | ||||
|     compose_set_project_name "$@" | ||||
| } | ||||
| function docker_set_deploy_args() { | ||||
|     if [ -n "$USE_STACK" -a -f docker-stack.yml ]; then | ||||
|         replace_deploy_args+=(-c docker-stack.yml) | ||||
|     else | ||||
|         replace_deploy_args+=(-c docker-compose.yml) | ||||
|     fi | ||||
|     if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then | ||||
|         replace_deploy_args+=(-c docker-stack.override.yml) | ||||
|     elif [ -f docker-compose.override.yml ]; then | ||||
|         replace_deploy_args+=(-c docker-compose.override.yml) | ||||
|     fi | ||||
|     if [ -n "$PROFILE" ]; then | ||||
|         if [ -n "$USE_STACK" -a -f "docker-stack.$PROFILE.yml" ]; then | ||||
|             replace_env_args+=(-c "docker-stack.$PROFILE.yml") | ||||
|         elif [ -f "docker-compose.$PROFILE.yml" ]; then | ||||
|             replace_env_args+=(-c "docker-compose.$PROFILE.yml") | ||||
|         fi | ||||
|     fi | ||||
| 
 | ||||
|     compose_set_project_name "$@" | ||||
| } | ||||
| 
 | ||||
| function host_run() { | ||||
|     # lancer le script $2..@ sur l'hôte $1 | ||||
| @ -209,15 +286,14 @@ function host_run() { | ||||
|             estep "Lancement de $script localement" | ||||
|             runscript_as_root "$script" "$@" | ||||
|         elif progexists docker-machine; then | ||||
|             local dm; setx dm=docker-machine active 2>/dev/null | ||||
|             if [ "${host%%.*}" == "$dm" ]; then | ||||
|             if [ "${host%%.*}" == "$DOCKER_MACHINE_NAME" ]; then | ||||
|                 estep "Copie du script vers root@$host" | ||||
|                 scp "$script" "root@$host:/tmp/tmp-dk-service-script" || die | ||||
|                 estep "Lancement du script à distance" | ||||
|                 local -a args; args=(/tmp/tmp-dk-service-script "$@") | ||||
|                 ssh -qt "root@$host" "$(qvals "${args[@]}"); rm -f /tmp/tmp-dk-service-script" | ||||
|             else | ||||
|                 ewarn "La machine active ($dm) n'est pas la destination ($host)" | ||||
|                 ewarn "La machine active ($DOCKER_MACHINE_NAME) n'est pas la destination ($host)" | ||||
|             fi | ||||
|         else | ||||
|             estep "Copie du script vers root@$host" | ||||
| @ -457,7 +533,7 @@ function auto_build() { | ||||
| function default_compose_push() { | ||||
|     ${FAKE:+qvals} docker-compose \ | ||||
|         "${replace_env_args[@]}" "${env_args[@]}" \ | ||||
|         push  \ | ||||
|         push \ | ||||
|         "$@" | ||||
| } | ||||
| function default_docker_push() { | ||||
| @ -611,6 +687,60 @@ function auto_down() { | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| function default_docker_deploy() { | ||||
|     ${FAKE:+qvals} docker \ | ||||
|         stack deploy \ | ||||
|         "${replace_deploy_args[@]}" "${deploy_args[@]}" \ | ||||
|         "$container_name" "$@" | ||||
| } | ||||
| function docker_deploy() { default_docker_deploy "$@"; } | ||||
| function auto_deploy() { | ||||
|     local -a replace_env_args env_args | ||||
|     local -a replace_deploy_args deploy_args | ||||
|     local project_name container_name | ||||
|     if [ -f docker-compose.yml -o -f docker-stack.yml ]; then | ||||
|         docker_set_deploy_args set_container_name | ||||
|         [ -n "$WITH_REGISTRY_AUTH" ] && replace_deploy_args+=(--with-registry-auth) | ||||
|         docker_deploy "$@" | ||||
|     else | ||||
|         die "Impossible de trouver ni docker-compose.yml ni docker-stack.yml" | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| function default_docker_service() { | ||||
|     ${FAKE:+qvals} docker service "$@" | ||||
| } | ||||
| function docker_service() { default_docker_service "$@"; } | ||||
| function auto_service() { | ||||
|     local -a replace_env_args env_args | ||||
|     local -a replace_deploy_args deploy_args | ||||
|     local project_name container_name | ||||
|     if [ -f docker-compose.yml -o -f docker-stack.yml ]; then | ||||
|         local command="$1"; shift | ||||
|         [ -n "$command" ] || { | ||||
|             eerror "Vous devez spécifier la commande" | ||||
|             return 1 | ||||
|         } | ||||
|         case "$command" in | ||||
|         ls) # ces commandes n'ont pas besoin du nom de service | ||||
|             docker_service "$command" "$@" | ||||
|             ;; | ||||
|         *) # ces commandes ont besoin du nom du service | ||||
|             local service="$1"; shift | ||||
|             [ -n "$service" ] || { | ||||
|                 eerror "Vous devez spécifier le nom du service" | ||||
|                 return 1 | ||||
|             } | ||||
|             docker_set_deploy_args set_container_name | ||||
|             service="${container_name}_${service#${container_name}_}" | ||||
|             docker_service "$command" "$@" "$service" | ||||
|             ;; | ||||
|         esac | ||||
|     else | ||||
|         die "Impossible de trouver ni docker-compose.yml ni docker-stack.yml" | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| function default_compose_show_ip() { | ||||
|     local -a cmd cids; local cid | ||||
|     cmd=( | ||||
| @ -775,24 +905,13 @@ DM_PROFILES=() | ||||
| set_defaults dk | ||||
| export PROFILE | ||||
| 
 | ||||
| DM_AVAILABLE= | ||||
| if progexists docker-machine; then | ||||
|     DM_AVAILABLE=1 | ||||
|     setx active_dm=docker-machine active 2>/dev/null | ||||
|     for dm_profile in "${DM_PROFILES[@]}"; do | ||||
|         splitpair "$dm_profile" dm profile | ||||
|         if [ "$dm" == "$active_dm" ]; then | ||||
|             DEFAULT_PROFILE="$profile" | ||||
|             break | ||||
|         fi | ||||
|     done | ||||
| fi | ||||
| 
 | ||||
| chdir= | ||||
| DM_SET_MACHINE= | ||||
| USE_STACK= | ||||
| FAKE= | ||||
| NO_CACHE= | ||||
| HOST= | ||||
| WITH_REGISTRY_AUTH=1 | ||||
| update_apps_mode=ub | ||||
| update_apps_origin= | ||||
| update_apps_branch= | ||||
| @ -803,6 +922,7 @@ args=( | ||||
|     -P,--prod PROFILE=prod | ||||
|     -T,--test PROFILE=test | ||||
|     -m:,--set-machine: DM_SET_MACHINE= | ||||
|     --stack USE_STACK=1 | ||||
|     -n,--fake FAKE=1 | ||||
|     -j,--no-cache NO_CACHE=1 | ||||
|     -h:,--host: HOST= | ||||
| @ -810,14 +930,25 @@ args=( | ||||
|     -u,--uu,--update-apps-only update_apps_mode=u | ||||
|     --uo:,--update-apps-origin: update_apps_origin= | ||||
|     --ub:,--update-apps-branch: update_apps_branch= | ||||
|     -l,--without-registry-auth WITH_REGISTRY_AUTH= | ||||
| ) | ||||
| parse_args "$@"; set -- "${args[@]}" | ||||
| 
 | ||||
| progexists docker-machine && DM_AVAILABLE=1 || DM_AVAILABLE= | ||||
| if [ -n "$DM_SET_MACHINE" ]; then | ||||
|     [ -n "$DM_AVAILABLE" ] || die "docker-machine n'est pas disponible" | ||||
|     setx dm_env=docker-machine env "$DM_SET_MACHINE" || die | ||||
|     eval "$dm_env" | ||||
| fi | ||||
| if [ -n "$DM_AVAILABLE" ]; then | ||||
|     for dm_profile in "${DM_PROFILES[@]}"; do | ||||
|         splitpair "$dm_profile" dm profile | ||||
|         if [ "$dm" == "$DOCKER_MACHINE_NAME" ]; then | ||||
|             DEFAULT_PROFILE="$profile" | ||||
|             break | ||||
|         fi | ||||
|     done | ||||
| fi | ||||
| 
 | ||||
| # construire par défaut | ||||
| [ $# -eq 0 ] && set -- build | ||||
| @ -915,6 +1046,7 @@ while [ $# -gt 0 ]; do | ||||
|         build_set_options "$update_apps_mode" "$update_apps_origin"  "$update_apps_branch" | ||||
|         [ -f .build.scripts.sh ] && source ./.build.scripts.sh | ||||
|         [ -f build.scripts.sh ] && source ./build.scripts.sh | ||||
|         USE_STACK=1 | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
| @ -922,6 +1054,73 @@ while [ $# -gt 0 ]; do | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_build && auto_up "${args[@]}" | ||||
|         ;; | ||||
|     y|deploy) | ||||
|         USE_STACK=1 | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_deploy "${args[@]}" || die | ||||
|         ;; | ||||
|     by|bd) | ||||
|         build_set_options "$update_apps_mode" "$update_apps_origin"  "$update_apps_branch" | ||||
|         [ -f .build.scripts.sh ] && source ./.build.scripts.sh | ||||
|         [ -f build.scripts.sh ] && source ./build.scripts.sh | ||||
|         USE_STACK=1 | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_build && auto_deploy "${args[@]}" | ||||
|         ;; | ||||
|     bp) | ||||
|         build_set_options "$update_apps_mode" "$update_apps_origin"  "$update_apps_branch" | ||||
|         [ -f .build.scripts.sh ] && source ./.build.scripts.sh | ||||
|         [ -f build.scripts.sh ] && source ./build.scripts.sh | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_build && auto_push "${args[@]}" | ||||
|         ;; | ||||
|     bpy|bpd) | ||||
|         build_set_options "$update_apps_mode" "$update_apps_origin"  "$update_apps_branch" | ||||
|         [ -f .build.scripts.sh ] && source ./.build.scripts.sh | ||||
|         [ -f build.scripts.sh ] && source ./build.scripts.sh | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_build && auto_push && auto_deploy "${args[@]}" | ||||
|         ;; | ||||
|     service) | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_service "${args[@]}" || die | ||||
|         ;; | ||||
|     u|update) | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_service update "${args[@]}" || die | ||||
|         ;; | ||||
|     scale) | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|             args+=("$1"); shift | ||||
|         done | ||||
|         enote "Profil $PROFILE" | ||||
|         auto_service scale "${args[@]}" || die | ||||
|         ;; | ||||
|     ip|show-ip) | ||||
|         args=() | ||||
|         while [ $# -gt 0 -a "$1" != -- ]; do | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user