dk: ajouter un frontend pour composer
This commit is contained in:
parent
29c54e7548
commit
2b5ed18ee3
90
dk
90
dk
|
@ -136,6 +136,17 @@ COMMANDES
|
|||
X|prune
|
||||
Supprimer les containers et les images inutilisées
|
||||
|
||||
composer|ci|cu [args...]
|
||||
Frontend pour lancer composer à l'intérieur d'un container. 'ci' est un
|
||||
alias pour 'composer install' et 'cu' un alias pour 'composer update'
|
||||
Le répertoire \$HOME est monté à l'intérieur du container et le script
|
||||
composer.phar du projet est utilisé le cas échéant.
|
||||
L'image utilisée pour lancer composer est indiquée par la variable
|
||||
d'environnement COMPOSER_IMAGE et vaut par défaut:
|
||||
$DEFAULT_COMPOSER_IMAGE
|
||||
Cette image doit disposer de la commande 'su-exec' afin de pouvoir
|
||||
lancer la commande avec l'utilisateur courant.
|
||||
|
||||
OPTIONS générales
|
||||
(ces options sont communes à toutes les commandes)
|
||||
-d, --chdir PROJDIR
|
||||
|
@ -154,7 +165,7 @@ OPTIONS générales
|
|||
Spécifier le profil
|
||||
-m, --set-machine MACHINE
|
||||
Choisir l'environnement docker-machine spécifié avant de lancer les
|
||||
commandes
|
||||
commandes. Utiliser -u pour desélectionner la machine en cours, e.g -m-u
|
||||
-n, --fake
|
||||
Ne pas lancer les commandes, simplement les afficher
|
||||
-h, --host HOST
|
||||
|
@ -1191,7 +1202,56 @@ EOF
|
|||
local_run "$HOST" "$tmpscript"
|
||||
}
|
||||
|
||||
function auto_composer() {
|
||||
local -a replace_env_args env_args
|
||||
if [ -f docker-compose.yml ]; then compose_set_env_args
|
||||
else docker_set_env_args
|
||||
fi
|
||||
|
||||
local user group projdir args
|
||||
setx user=id -un; setx user=getent passwd "$user"
|
||||
setx group=id -gn; setx group=getent group "$group"
|
||||
setx projdir=pwd
|
||||
setx args=qvals "$@"
|
||||
|
||||
local -a cmd
|
||||
cmd=(
|
||||
docker run -it --rm
|
||||
-e user="$user"
|
||||
-e group="$group"
|
||||
-e home="$HOME"
|
||||
-e projdir="$projdir"
|
||||
-e args="$args"
|
||||
-v "$HOME:$HOME"
|
||||
)
|
||||
if [ "${projdir#$HOME/}" == "$projdir" ]; then
|
||||
# si le répertoire de projet ne se trouve pas dans $HOME, le monter aussi
|
||||
cmd+=(-v "$projdir:$projdir")
|
||||
fi
|
||||
cmd+=(
|
||||
"${COMPOSER_IMAGE:-$DEFAULT_COMPOSER_IMAGE}"
|
||||
bash -c '
|
||||
echo "$user" >>/etc/passwd; user="${user%%:*}"
|
||||
echo "$group" >>/etc/group; group="${group%%:*}"
|
||||
|
||||
cd "$projdir"
|
||||
if [ -x composer.phar ]; then composer=./composer.phar
|
||||
elif [ -x /usr/bin/composer ]; then composer=/usr/bin/composer
|
||||
else
|
||||
echo "ERROR: unable to find composer"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval "su-exec \"$user\" \"$composer\" $args"
|
||||
'
|
||||
)
|
||||
"${cmd[@]}"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
DEFAULT_PROFILE=devel
|
||||
DEFAULT_COMPOSER_IMAGE=docker.univ-reunion.fr/image/utils-icmycas-php-apache:d9
|
||||
PROFILE=
|
||||
DM_PROFILES=()
|
||||
set_defaults dk
|
||||
|
@ -1233,6 +1293,7 @@ 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"
|
||||
[ "$DM_SET_MACHINE" == - ] && DM_SET_MACHINE=-u
|
||||
setx dm_env=docker-machine env "$DM_SET_MACHINE" || die
|
||||
eval "$dm_env"
|
||||
fi
|
||||
|
@ -1261,7 +1322,7 @@ while [ $# -gt 0 ]; do
|
|||
cmd="$1"; shift
|
||||
case "$cmd" in
|
||||
b|build)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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=()
|
||||
|
@ -1344,7 +1405,7 @@ while [ $# -gt 0 ]; do
|
|||
}
|
||||
trap auto_down_trap 1 3 15 EXIT
|
||||
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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=()
|
||||
|
@ -1359,7 +1420,7 @@ while [ $# -gt 0 ]; do
|
|||
fi
|
||||
;;
|
||||
bs)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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
|
||||
|
@ -1371,7 +1432,7 @@ while [ $# -gt 0 ]; do
|
|||
auto_build && auto_up "${args[@]}"
|
||||
;;
|
||||
br)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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
|
||||
|
@ -1392,7 +1453,7 @@ while [ $# -gt 0 ]; do
|
|||
auto_deploy "${args[@]}" || die
|
||||
;;
|
||||
by|bd)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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
|
||||
|
@ -1404,7 +1465,7 @@ while [ $# -gt 0 ]; do
|
|||
auto_build && auto_deploy "${args[@]}"
|
||||
;;
|
||||
bp)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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=()
|
||||
|
@ -1415,7 +1476,7 @@ while [ $# -gt 0 ]; do
|
|||
auto_build && auto_push "${args[@]}"
|
||||
;;
|
||||
bpy|bpd)
|
||||
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
||||
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=()
|
||||
|
@ -1604,6 +1665,19 @@ NR == 1 { print; next }
|
|||
docker container prune -f || die
|
||||
docker image prune -f || die
|
||||
;;
|
||||
composer|c|ci|cu)
|
||||
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=()
|
||||
if [ "$cmd" == ci ]; then args+=(install)
|
||||
elif [ "$cmd" == cu ]; then args+=(update)
|
||||
fi
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
auto_composer "${args[@]}"
|
||||
;;
|
||||
*) die "$cmd: commande inconnue";;
|
||||
esac
|
||||
done
|
||||
|
|
|
@ -5,3 +5,6 @@
|
|||
|
||||
# Profiles pour docker-machine
|
||||
#DM_PROFILES=(name:profile...)
|
||||
|
||||
# Image à utiliser pour lancer composer
|
||||
#COMPOSER_IMAGE=docker.univ-reunion.fr/image/utils-icmycas-php-apache:d9
|
||||
|
|
Loading…
Reference in New Issue