From 0bf0f48ad075462930ecf5546137e5137456fa2a Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 3 Jan 2024 19:11:09 +0400 Subject: [PATCH] dk: support ~/.dkbuild.env --- dk | 79 ++++++++++++++++++++++++++++++++++---------------- lib/default/dk | 24 +-------------- lib/uinst/conf | 3 ++ 3 files changed, 58 insertions(+), 48 deletions(-) diff --git a/dk b/dk index c072cf8..bc8eb74 100755 --- a/dk +++ b/dk @@ -2062,7 +2062,16 @@ function auto_composer() { local COMPOSER_MACHINE=-u local COMPOSER_CMD= local COMPOSER_SETUP= - [ -f .composer.conf ] && source ./.composer.conf + if [ -f .composer.yaml ]; then + local registry + eval "$(<.composer.yaml grep ^composer_ | + sed 's/^composer_php_min: /COMPOSER_PHP=/; + s/^composer_php_max: /COMPOSER_PHP_MAX=/; + s/^composer_registry: /registry=/; + s/^composer_image: \(.*\)/COMPOSER_IMAGE="${registry:-$REGISTRY}\/\1"/')" + elif [ -f .composer.conf ]; then + source ./.composer.conf + fi # les premiers arguments peuvent servir à redéfinir les variables while [ $# -gt 0 ]; do case "$1" in @@ -2413,21 +2422,6 @@ fi [ -n "$COMPOSE_V1" ] && DOCKER_COMPOSE=(docker-compose) || DOCKER_COMPOSE=(docker compose) -DEFAULT_PROFILE=devel -case "$PROFILE" in -jclain) - REGISTRY=docker.jclain.fr - PRIVAREG=docker.jclain.fr - ;; -devel) - REGISTRY=docker.devel.self - PRIVAREG=docker.devel.self - ;; -prod|test|*) - REGISTRY=pubdocker.univ-reunion.fr - PRIVAREG=pridocker.univ-reunion.fr - ;; -esac PROFILE= DM_ALIASES=() DM_PROFILES=() @@ -2435,20 +2429,55 @@ CLUSTERDIRS=() DEFAULT_DEVEL_SRCDIR="$HOME/wop" COMPOSER_DEVEL_SRCDIR="$HOME/wop/php" MAVEN_DEVEL_SRCDIR="$HOME/wop/sn" -DEFAULT_COMPOSER_IMAGE="$REGISTRY/image/phpbuilder:d11" -DEFAULT_MAVEN_IMAGE="$REGISTRY/image/javabuilder:d11" +DEFAULT_COMPOSER_IMAGE= +DEFAULT_MAVEN_IMAGE= DEFAULT_HOST_MAPPINGS=() -prod_HOST_MAPPINGS=( - pridocker.univ-reunion.fr:10.85.1.56 - pubdocker.univ-reunion.fr:10.85.1.57 - repos.univ-reunion.fr:10.85.1.57 - git.univ-reunion.fr:10.85.1.55 -) -test_HOST_MAPPINGS=("${prod_HOST_MAPPINGS[@]}") set_defaults dk export PROFILE +DEFAULT_PROFILE=devel +REGISTRY= HOST_MAPPINGS=() +if [ -f ~/.dkbuild.env ]; then + function default_profile() { + DEFAULT_PROFILE="$1" + } + function profile() { + local profile + for profile in "$@"; do + [ "$profile" == "$DEFAULT_PROFILE" ] && return 0 + done + return 1 + } + function setenv() { + eval "export $1" + } + function default() { + local command="$1"; shift + local nv n v + case "$command" in + docker) + for nv in "$@"; do + [[ "$nv" == *=* ]] || continue + n="${nv%%=*}" + v="${nv#*=}" + case "$n" in + host-mappings) + read -a nv <<<"$v" + for v in "${ns[@]}"; do + HOST_MAPPINGS+=("$v") + done + ;; + esac + done + ;; + esac + } + source ~/.dkbuild.env +fi +[ -n "$REGISTRY" ] || REGISTRY=pubdocker.univ-reunion.fr +[ -n "$DEFAULT_COMPOSER_IMAGE" ] || DEFAULT_COMPOSER_IMAGE="$REGISTRY/image/php:d11" +[ -n "$DEFAULT_MAVEN_IMAGE" ] || DEFAULT_MAVEN_IMAGE="$REGISTRY/image/javabuilder:d11" chdir= CONFIG= diff --git a/lib/default/dk b/lib/default/dk index d39ef14..afb878e 100644 --- a/lib/default/dk +++ b/lib/default/dk @@ -20,27 +20,5 @@ #MAVEN_DEVEL_SRCDIR="$HOME/wop/sn" # Image à utiliser pour les builds -#DEFAULT_COMPOSER_IMAGE=pubdocker.univ-reunion.fr/image/phpbuilder:d11 +#DEFAULT_COMPOSER_IMAGE=pubdocker.univ-reunion.fr/image/php:d11 #DEFAULT_MAVEN_IMAGE=pubdocker.univ-reunion.fr/image/javabuilder:d11 - -# Mappings d'hôtes à activer pour les builds à base d'image -#DEFAULT_HOST_MAPPINGS=() -#prod_HOST_MAPPINGS=(pridocker.univ-reunion.fr:10.85.1.56 pubdocker.univ-reunion.fr:10.85.1.57 repos.univ-reunion.fr:10.85.1.57 git.univ-reunion.fr:10.85.1.55) -#test_HOST_MAPPINGS=("${prod_HOST_MAPPINGS}") - -#case "$PROFILE" in -#jclain) -# REGISTRY=docker.jclain.fr -# PRIVAREG=docker.jclain.fr -# ;; -#devel) -# REGISTRY=docker.devel.self -# PRIVAREG=docker.devel.self -# ;; -#prod|test|*) -# REGISTRY=pubdocker.univ-reunion.fr -# PRIVAREG=pridocker.univ-reunion.fr -# ;; -#esac -#: ${DEFAULT_COMPOSER_IMAGE:=$REGISTRY/image/phpbuilder:d11} -#: ${DEFAULT_MAVEN_IMAGE:=$REGISTRY/image/javabuilder:d11} diff --git a/lib/uinst/conf b/lib/uinst/conf index 16c0e43..bd9ce5b 100644 --- a/lib/uinst/conf +++ b/lib/uinst/conf @@ -68,6 +68,9 @@ if [ "$UINST_LOCAL_PROFILES" != auto ]; then export UTOOLS_LOCAL_PROFILES=$(qvalr "$UINST_LOCAL_PROFILES")" ~/.nutoolsrc fi +# copier .dkbuild.env +[ -f ~/.dkbuild.env ] || cp lib/dkbuild/dot-dkbuild.env ~/.dkbuild.env + # identification du système echo "##@before *" >lib/profile.d/0nutools echo_setv UNAME_SYSTEM "$UNAME_SYSTEM" >>lib/profile.d/0nutools