diff --git a/dk b/dk index f052389..f0e0a3f 100755 --- a/dk +++ b/dk @@ -203,11 +203,6 @@ function compose_set_project_name() { PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}" 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}}" else [ -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 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 "$@" } @@ -241,9 +243,16 @@ function compose_set_deploy_args() { replace_deploy_args+=(-c docker-compose.yml) fi 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 - 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 compose_set_project_name "$@" @@ -261,15 +270,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" @@ -847,19 +855,6 @@ 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= @@ -889,11 +884,21 @@ args=( ) 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