support docker compose v2
This commit is contained in:
parent
432ab6f915
commit
3ecb127f33
|
@ -2,6 +2,8 @@
|
|||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/lib/ulib/auto" || exit 1
|
||||
|
||||
[ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose)
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: se connecter à la base MySQL
|
||||
|
||||
|
@ -11,6 +13,8 @@ USAGE
|
|||
$scriptname -c [-uUSER [-pPASSWORD]] <backup.sql
|
||||
|
||||
OPTIONS
|
||||
--compose-v1
|
||||
Forcer l'utilisation de docker-compose v1
|
||||
-h, -s, --service SERVICE
|
||||
Spécifier le nom du service. La valeur par défaut est db
|
||||
-i, --ipnum IPNUM
|
||||
|
@ -40,6 +44,7 @@ user=
|
|||
password=
|
||||
args=(
|
||||
--help '$exit_with display_help'
|
||||
--compose-v1 '$DOCKER_COMPOSE=(docker-compose)'
|
||||
-h:,-s:,--service: service=
|
||||
-i:,--ipnum: ipnum=
|
||||
-c,--mysql-cmd mysql_cmd=1
|
||||
|
@ -72,7 +77,7 @@ fi
|
|||
###
|
||||
|
||||
function die_not_found() { die "$service: service introuvable. vérifiez que le projet est actuellement up"; }
|
||||
setx cid=docker-compose ps -q "$service" 2>/dev/null || die_not_found
|
||||
setx cid="${DOCKER_COMPOSE[@]}" ps -q "$service" 2>/dev/null || die_not_found
|
||||
[ -n "$cid" ] || die_not_found
|
||||
edebug "$service id: $cid"
|
||||
|
||||
|
@ -107,7 +112,7 @@ elif [ -n "$klean" ]; then
|
|||
estep "wait 10sec..."
|
||||
sleep 10
|
||||
estep "start"
|
||||
docker-compose start "$service"
|
||||
"${DOCKER_COMPOSE[@]}" start "$service"
|
||||
|
||||
else
|
||||
[ -f bin/conndev.php ] || die "Impossible de trouver le script compagnon conndev.php"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/lib/ulib/auto" || exit 1
|
||||
|
||||
[ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose)
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: ouvrir un shell dans le container
|
||||
|
||||
|
@ -9,6 +11,8 @@ USAGE
|
|||
$scriptname [CMD...]
|
||||
|
||||
OPTIONS
|
||||
--compose-v1
|
||||
Forcer l'utilisation de docker-compose v1
|
||||
-h, -s, --service SERVICE
|
||||
Spécifier le nom du service sur lequel ouvrir le shell
|
||||
-d, --db
|
||||
|
@ -20,6 +24,7 @@ OPTIONS
|
|||
service=web
|
||||
args=(
|
||||
--help '$exit_with display_help'
|
||||
--compose-v1 '$DOCKER_COMPOSE=(docker-compose)'
|
||||
-h:,-s:,--service: service=
|
||||
-d,--db service=db
|
||||
-w,--web service=web
|
||||
|
@ -47,9 +52,9 @@ fi
|
|||
|
||||
###
|
||||
|
||||
setx cid=docker-compose ps -q "$service" 2>/dev/null || die "$service: service introuvable"
|
||||
setx cid="${DOCKER_COMPOSE[@]}" ps -q "$service" 2>/dev/null || die "$service: service introuvable"
|
||||
|
||||
cmd=("$@")
|
||||
[ ${#cmd[*]} -gt 0 ] || cmd=(bash)
|
||||
|
||||
docker-compose exec "$service" "${cmd[@]}"
|
||||
"${DOCKER_COMPOSE[@]}" exec "$service" "${cmd[@]}"
|
||||
|
|
58
dk
58
dk
|
@ -1237,7 +1237,7 @@ function default_update_build_env() {
|
|||
function update_build_env() { default_update_build_env "$@"; }
|
||||
|
||||
function default_compose_build() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
build \
|
||||
${NO_CACHE:+--no-cache} \
|
||||
|
@ -1307,7 +1307,7 @@ function auto_build() {
|
|||
}
|
||||
|
||||
function default_compose_push() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
push \
|
||||
"$@"
|
||||
|
@ -1345,7 +1345,7 @@ function auto_push() {
|
|||
}
|
||||
|
||||
function default_compose_up() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
up "${replace_run_args[@]}" "${run_args[@]}" \
|
||||
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
||||
|
@ -1379,7 +1379,7 @@ function auto_up() {
|
|||
}
|
||||
|
||||
function default_compose_stop() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
stop "${replace_stop_args[@]}" "${stop_args[@]}" \
|
||||
"$@"
|
||||
|
@ -1408,7 +1408,7 @@ function auto_stop() {
|
|||
}
|
||||
|
||||
function default_compose_logs() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
logs "${replace_logs_args[@]}" "${logs_args[@]}" \
|
||||
"$@"
|
||||
|
@ -1439,7 +1439,7 @@ function auto_logs() {
|
|||
}
|
||||
|
||||
function default_compose_down() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
down "${replace_down_args[@]}" "${down_args[@]}" \
|
||||
"$@"
|
||||
|
@ -1474,7 +1474,7 @@ function auto_down() {
|
|||
}
|
||||
|
||||
function default_compose_run() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
run "${replace_run_args[@]}" "${run_args[@]}" \
|
||||
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
||||
|
@ -1545,7 +1545,7 @@ function auto_run() {
|
|||
}
|
||||
|
||||
function default_compose_exec() {
|
||||
${FAKE:+qvals} docker-compose \
|
||||
${FAKE:+qvals} "${DOCKER_COMPOSE[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
exec "${replace_exec_args[@]}" "${exec_args[@]}" \
|
||||
"$@"
|
||||
|
@ -1759,7 +1759,7 @@ function auto_status() {
|
|||
function default_compose_show_ip() {
|
||||
local -a cmd cids; local cid
|
||||
cmd=(
|
||||
docker-compose
|
||||
"${DOCKER_COMPOSE[@]}"
|
||||
"${replace_env_args[@]}" "${env_args[@]}"
|
||||
ps -q "${replace_show_ip_args[@]}" "${show_ip_args[@]}"
|
||||
"$@"
|
||||
|
@ -1795,21 +1795,38 @@ function auto_show_ip() {
|
|||
}
|
||||
|
||||
function default_compose_systemd_unit() {
|
||||
local docker_compose="$(which docker-compose 2>/dev/null)"
|
||||
if [ -z "$docker_compose" ]; then
|
||||
if [ -x /usr/bin/docker-compose ]; then
|
||||
docker_compose=/usr/bin/docker-compose
|
||||
elif [ -x /usr/local/bin/docker-compose ]; then
|
||||
docker_compose=/usr/local/bin/docker-compose
|
||||
else
|
||||
die "Impossible de trouver docker-compose"
|
||||
local -a docker_compose
|
||||
if [ "${DOCKER_COMPOSE[0]}" == docker ]; then
|
||||
# compose v2
|
||||
local docker="$(which docker 2>/dev/null)"
|
||||
if [ -z "$docker" ]; then
|
||||
if [ -x /usr/bin/docker ]; then
|
||||
docker=/usr/bin/docker
|
||||
elif [ -x /usr/local/bin/docker ]; then
|
||||
docker=/usr/local/bin/docker
|
||||
else
|
||||
die "Impossible de trouver docker"
|
||||
fi
|
||||
fi
|
||||
docker_compose=("$docker" compose)
|
||||
else
|
||||
# compose v1
|
||||
docker_compose="$(which docker-compose 2>/dev/null)"
|
||||
if [ -z "$docker_compose" ]; then
|
||||
if [ -x /usr/bin/docker-compose ]; then
|
||||
docker_compose=/usr/bin/docker-compose
|
||||
elif [ -x /usr/local/bin/docker-compose ]; then
|
||||
docker_compose=/usr/local/bin/docker-compose
|
||||
else
|
||||
die "Impossible de trouver docker-compose"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
setx startcmd=qvals "$docker_compose" \
|
||||
setx startcmd=qvals "${docker_compose[@]}" \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
up "${replace_run_args[@]}" "${run_args[@]}" \
|
||||
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
||||
setx stopcmd=qvals "$docker_compose" down
|
||||
setx stopcmd=qvals "${docker_compose[@]}" down
|
||||
}
|
||||
function default_docker_systemd_unit() {
|
||||
local docker="$(which "$DOCKER" 2>/dev/null)"
|
||||
|
@ -2390,6 +2407,8 @@ elif progexists podman; then DOCKER=podman
|
|||
else DOCKER=docker
|
||||
fi
|
||||
|
||||
[ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose)
|
||||
|
||||
DEFAULT_PROFILE=devel
|
||||
PROFILE=
|
||||
DM_ALIASES=()
|
||||
|
@ -2431,6 +2450,7 @@ update_apps_origin=
|
|||
update_apps_branch=
|
||||
args=(
|
||||
--help '$exit_with display_help'
|
||||
--compose-v1 '$DOCKER_COMPOSE=(docker-compose)'
|
||||
-d:,--chdir: chdir=
|
||||
-c:,--config: CONFIG=
|
||||
-p:,--profile: PROFILE=
|
||||
|
|
8
dkbuild
8
dkbuild
|
@ -6,6 +6,8 @@ urequire ptools xmlsupport
|
|||
SELF="$script"
|
||||
TEMPLATEDIR="$scriptdir/lib/dkbuild/templates"
|
||||
|
||||
[ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose)
|
||||
|
||||
function get_default_phpbuilder_image() {
|
||||
echo "${REGISTRY:-docker.univ-reunion.fr}/image/phpbuilder:${DIST:-d11}"
|
||||
}
|
||||
|
@ -28,6 +30,8 @@ OPTIONS
|
|||
--href, --help-reference
|
||||
Afficher la référence sur les commandes utilisables dans un fichier
|
||||
dkbuild
|
||||
--compose-v1
|
||||
Forcer l'utilisation de docker-compose v1
|
||||
|
||||
ACTIONS
|
||||
|
||||
|
@ -2070,7 +2074,7 @@ function define_functions_cmd() {
|
|||
echo_setv "$evar=${ENVIRON[$evar]}" >>.env
|
||||
done
|
||||
|
||||
_runcmd docker-compose "${args[@]}" build "${bargs[@]}" "$@" || die
|
||||
_runcmd "${DOCKER_COMPOSE[@]}" "${args[@]}" build "${bargs[@]}" "$@" || die
|
||||
}
|
||||
function _local_composer() {
|
||||
case "$action" in
|
||||
|
@ -3011,6 +3015,7 @@ while [ $# -gt 0 ]; do
|
|||
--help) args+=("$1"); shift; continue;;
|
||||
--hdk|--help-dkbuild) args+=("$1"); shift; continue;;
|
||||
--href|--help-reference) args+=("$1"); shift; continue;;
|
||||
--compose-v1) args+=("$1"); shift; continue;;
|
||||
-*|*=*) # option quelconque: inférer build
|
||||
args+=(build)
|
||||
break
|
||||
|
@ -3026,6 +3031,7 @@ args=(+
|
|||
--help '$exit_with display_help'
|
||||
--hdk,--help-dkbuild '$exit_with display_help_dkbuild'
|
||||
--href,--help-reference '$exit_with display_help_reference'
|
||||
--compose-v1 '$DOCKER_COMPOSE=(docker-compose)'
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
|
|
Loading…
Reference in New Issue