optimiser l'utilisation de docker-machine
This commit is contained in:
parent
8cb3b2fc57
commit
c2f43e6b6d
51
dk
51
dk
|
@ -203,11 +203,6 @@ function compose_set_project_name() {
|
||||||
PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}"
|
PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}"
|
||||||
|
|
||||||
if [ -n "$PROFILE" ]; then
|
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
|
|
||||||
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME${PROJECT_NAME_ADD_PROFILE:+_${PROFILE}}"
|
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME${PROJECT_NAME_ADD_PROFILE:+_${PROFILE}}"
|
||||||
else
|
else
|
||||||
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME"
|
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME"
|
||||||
|
@ -231,6 +226,13 @@ function compose_set_env_args() {
|
||||||
elif [ -f docker-compose.override.yml ]; then
|
elif [ -f docker-compose.override.yml ]; then
|
||||||
replace_env_args+=(-f docker-compose.override.yml)
|
replace_env_args+=(-f docker-compose.override.yml)
|
||||||
fi
|
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 "$@"
|
compose_set_project_name "$@"
|
||||||
}
|
}
|
||||||
|
@ -241,9 +243,16 @@ function compose_set_deploy_args() {
|
||||||
replace_deploy_args+=(-c docker-compose.yml)
|
replace_deploy_args+=(-c docker-compose.yml)
|
||||||
fi
|
fi
|
||||||
if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then
|
if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then
|
||||||
replace_deploy_args+=(-f docker-stack.override.yml)
|
replace_deploy_args+=(-c docker-stack.override.yml)
|
||||||
elif [ -f docker-compose.override.yml ]; then
|
elif [ -f docker-compose.override.yml ]; then
|
||||||
replace_deploy_args+=(-f docker-compose.override.yml)
|
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
|
fi
|
||||||
|
|
||||||
compose_set_project_name "$@"
|
compose_set_project_name "$@"
|
||||||
|
@ -261,15 +270,14 @@ function host_run() {
|
||||||
estep "Lancement de $script localement"
|
estep "Lancement de $script localement"
|
||||||
runscript_as_root "$script" "$@"
|
runscript_as_root "$script" "$@"
|
||||||
elif progexists docker-machine; then
|
elif progexists docker-machine; then
|
||||||
local dm; setx dm=docker-machine active 2>/dev/null
|
if [ "${host%%.*}" == "$DOCKER_MACHINE_NAME" ]; then
|
||||||
if [ "${host%%.*}" == "$dm" ]; then
|
|
||||||
estep "Copie du script vers root@$host"
|
estep "Copie du script vers root@$host"
|
||||||
scp "$script" "root@$host:/tmp/tmp-dk-service-script" || die
|
scp "$script" "root@$host:/tmp/tmp-dk-service-script" || die
|
||||||
estep "Lancement du script à distance"
|
estep "Lancement du script à distance"
|
||||||
local -a args; args=(/tmp/tmp-dk-service-script "$@")
|
local -a args; args=(/tmp/tmp-dk-service-script "$@")
|
||||||
ssh -qt "root@$host" "$(qvals "${args[@]}"); rm -f /tmp/tmp-dk-service-script"
|
ssh -qt "root@$host" "$(qvals "${args[@]}"); rm -f /tmp/tmp-dk-service-script"
|
||||||
else
|
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
|
fi
|
||||||
else
|
else
|
||||||
estep "Copie du script vers root@$host"
|
estep "Copie du script vers root@$host"
|
||||||
|
@ -847,19 +855,6 @@ DM_PROFILES=()
|
||||||
set_defaults dk
|
set_defaults dk
|
||||||
export PROFILE
|
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=
|
chdir=
|
||||||
DM_SET_MACHINE=
|
DM_SET_MACHINE=
|
||||||
USE_STACK=
|
USE_STACK=
|
||||||
|
@ -889,11 +884,21 @@ args=(
|
||||||
)
|
)
|
||||||
parse_args "$@"; set -- "${args[@]}"
|
parse_args "$@"; set -- "${args[@]}"
|
||||||
|
|
||||||
|
progexists docker-machine && DM_AVAILABLE=1 || DM_AVAILABLE=
|
||||||
if [ -n "$DM_SET_MACHINE" ]; then
|
if [ -n "$DM_SET_MACHINE" ]; then
|
||||||
[ -n "$DM_AVAILABLE" ] || die "docker-machine n'est pas disponible"
|
[ -n "$DM_AVAILABLE" ] || die "docker-machine n'est pas disponible"
|
||||||
setx dm_env=docker-machine env "$DM_SET_MACHINE" || die
|
setx dm_env=docker-machine env "$DM_SET_MACHINE" || die
|
||||||
eval "$dm_env"
|
eval "$dm_env"
|
||||||
fi
|
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
|
# construire par défaut
|
||||||
[ $# -eq 0 ] && set -- build
|
[ $# -eq 0 ] && set -- build
|
||||||
|
|
Loading…
Reference in New Issue