From a9004fa1d256109d683652122ad647f1c7453409 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 16 Nov 2018 14:16:16 +0400 Subject: [PATCH 01/10] =?UTF-8?q?dk:=20PROFILE=20est=20export=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dk | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dk b/dk index d41741d..a7e67cb 100755 --- a/dk +++ b/dk @@ -57,12 +57,12 @@ function docker_parse_build_args() { function docker_parse_env_args() { [ -f .build.env ] && eval "$(docker_parse_build_args .build.env)" [ -f build.env ] && eval "$(docker_parse_build_args build.env)" - [ -n "$profile" -a -f ".build.$profile.env" ] && eval "$(docker_parse_build_args ".build.$profile.env")" + [ -n "$PROFILE" -a -f ".build.$PROFILE.env" ] && eval "$(docker_parse_build_args ".build.$PROFILE.env")" } function docker_set_env_args() { [ -f .build.env ] && source ./.build.env [ -f build.env ] && source ./build.env - [ -n "$profile" -a -f ".build.$profile.env" ] && source "./.build.$profile.env" + [ -n "$PROFILE" -a -f ".build.$PROFILE.env" ] && source "./.build.$PROFILE.env" } function docker_set_run_args() { replace_run_args+=(--env-file "$1") @@ -82,14 +82,14 @@ function compose_set_env_args() { fi local PROJECT_NAME=--none-- [ -f .compose.env ] && source ./.compose.env - if [ -n "$profile" ]; then - if [ -f "docker-compose.$profile.yml" ]; then - replace_env_args+=(-f "docker-compose.$profile.yml") + if [ -n "$PROFILE" ]; then + if [ -f "docker-compose.$PROFILE.yml" ]; then + replace_env_args+=(-f "docker-compose.$PROFILE.yml") fi if [ "$PROJECT_NAME" != --none-- ]; then if [ -z "$COMPOSE_PROJECT_NAME" ]; then [ -n "$PROJECT_NAME" ] || PROJECT_NAME="$(basename -- "$(pwd)")" - COMPOSE_PROJECT_NAME="${PROJECT_NAME}_${profile}" + COMPOSE_PROJECT_NAME="${PROJECT_NAME}_${PROFILE}" fi export COMPOSE_PROJECT_NAME fi @@ -281,21 +281,21 @@ function auto_down() { DEFAULT_PROFILE=devel PROFILE= set_defaults dk +export PROFILE chdir= -profile="$PROFILE" args=( --help '$exit_with display_help' -d:,--chdir: chdir= - -p:,--profile: profile= - -P,--prod profile=prod - -T,--test profile=test + -p:,--profile: PROFILE= + -P,--prod PROFILE=prod + -T,--test PROFILE=test ) parse_args "$@"; set -- "${args[@]}" # construire par défaut [ $# -eq 0 ] && set -- build -[ -n "$profile" ] || profile="$DEFAULT_PROFILE" +[ -n "$PROFILE" ] || PROFILE="$DEFAULT_PROFILE" [ -n "$chdir" ] && { cd "$chdir" || die; } @@ -310,7 +310,7 @@ while [ $# -gt 0 ]; do while [ $# -gt 0 -a "$1" != -- ]; do args+=("$1"); shift done - enote "Profil $profile" + enote "Profil $PROFILE" auto_build "${args[@]}" || die ;; push) @@ -320,7 +320,7 @@ while [ $# -gt 0 ]; do while [ $# -gt 0 -a "$1" != -- ]; do args+=("$1"); shift done - enote "Profil $profile" + enote "Profil $PROFILE" auto_push "${args[@]}" || die ;; s|run|start) @@ -328,11 +328,11 @@ while [ $# -gt 0 ]; do while [ $# -gt 0 -a "$1" != -- ]; do args+=("$1"); shift done - enote "Profil $profile" + enote "Profil $PROFILE" auto_up "${args[@]}" || die ;; k|stop) - enote "Profil $profile" + enote "Profil $PROFILE" auto_stop || die ;; 1|up) @@ -340,7 +340,7 @@ while [ $# -gt 0 ]; do while [ $# -gt 0 -a "$1" != -- ]; do args+=("$1"); shift done - enote "Profil $profile" + enote "Profil $PROFILE" auto_up "${args[@]}" && auto_logs || die ;; l|logs) auto_logs || die;; @@ -358,7 +358,7 @@ while [ $# -gt 0 ]; do while [ $# -gt 0 -a "$1" != -- ]; do args+=("$1"); shift done - enote "Profil $profile" + enote "Profil $PROFILE" if auto_build; then auto_up "${args[@]}" && auto_logs || die else From 45c6422e628fb9d9a0dd5f014d4814e2d531afbd Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 16 Nov 2018 16:25:33 +0400 Subject: [PATCH 02/10] profils pour docker-machine --- dk | 12 ++++++++++++ lib/default/dk | 3 +++ 2 files changed, 15 insertions(+) diff --git a/dk b/dk index a7e67cb..cfc5343 100755 --- a/dk +++ b/dk @@ -280,9 +280,21 @@ function auto_down() { DEFAULT_PROFILE=devel PROFILE= +DM_PROFILES=() set_defaults dk export PROFILE +if progexists docker-machine; then + setx active_dm=docker-machine active + 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= args=( --help '$exit_with display_help' diff --git a/lib/default/dk b/lib/default/dk index 0923449..39be464 100644 --- a/lib/default/dk +++ b/lib/default/dk @@ -2,3 +2,6 @@ # Profil par défaut #PROFILE=prod + +# Profiles pour docker-machine +#DM_PROFILES=(name:profile...) From 307fa4827af79a07f26f4b1aaa1f3aa5927a47c0 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 16 Nov 2018 20:48:51 +0400 Subject: [PATCH 03/10] =?UTF-8?q?dk:=20option=20-j=20pour=20d=C3=A9sactive?= =?UTF-8?q?r=20le=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dk b/dk index cfc5343..0e24c3a 100755 --- a/dk +++ b/dk @@ -120,6 +120,7 @@ function default_docker_build() { replace_build_args+=(-t "$NAME:$tag") done docker build \ + ${NO_CACHE:+--no-cache} \ "${replace_env_args[@]}" "${env_args[@]}" \ "${replace_build_args[@]}" "${build_args[@]}" \ "$@" "$CTXDIR" @@ -285,7 +286,7 @@ set_defaults dk export PROFILE if progexists docker-machine; then - setx active_dm=docker-machine active + 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 @@ -296,12 +297,14 @@ if progexists docker-machine; then fi chdir= +NO_CACHE= args=( --help '$exit_with display_help' -d:,--chdir: chdir= -p:,--profile: PROFILE= -P,--prod PROFILE=prod -T,--test PROFILE=test + -j,--no-cache NO_CACHE=1 ) parse_args "$@"; set -- "${args[@]}" From 764dd53bf85a44df0e37728bfd59d5afd565b8c6 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 16 Nov 2018 20:53:33 +0400 Subject: [PATCH 04/10] maj prefixe et meilleur affichage des erreurs --- lib/default/pcrone | 22 +++++++-- uproject | 120 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 110 insertions(+), 32 deletions(-) diff --git a/lib/default/pcrone b/lib/default/pcrone index d7e56a7..f64e5ae 100644 --- a/lib/default/pcrone +++ b/lib/default/pcrone @@ -1,15 +1,31 @@ # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 +# Liste de préfixes permettant de taper le nom d'un dépôt plus rapidement e.g +# pcrone g/ssi-php/myproj +# pcrone v:modules/myproj +# sont équivalents à +# pcrone https://git.univ-reunion.fr/ssi-php/myproj +# pcrone git@vcs.univ.run:modules/myproj +# Ces définitions fonctionnent aussi pour pclone +# Le format est ALIAS=ACTUAL +REPO_PREFIXES=( + s:=git@git.univ-reunion.fr: + g/=https://git.univ-reunion.fr/ + v:=git@vcs.univ.run: av/=https://vcs.univ-reunion.fr/anongit/ + p:=pgit@vcs.univ.run: ap/=https://pvcs.univ-reunion.fr/anongit/ +) + # Définitions des types de dépôt. Le format est NAME:TYPE:PREFIX # * NAME est utilisé pour définir des configurations supplémentaires -# * TYPE peut valoir gitolite ou gogs. Le type par défaut est 'gitolite' +# * TYPE peut valoir gitolite ou gogs (ou gitea qui est un alias de gogs). Le +# type par défaut est 'gitolite' REPO_TYPES=( - ur:gogs:https://gogs.univ-reunion.fr/ + ur:gitea:https://git.univ-reunion.fr/ ) # Configuration de l'accès à l'API gogs # un nom de dépôt est de la forme user/repo. Si user != $GOGS_USER alors on crée # dans une organisation -#ur_GOGS_URL=https://gogs.univ-reunion.fr +#ur_GOGS_URL=https://git.univ-reunion.fr #ur_GOGS_USER="$USER" #ur_GOGS_KEY= diff --git a/uproject b/uproject index 5b21760..1dcab3b 100755 --- a/uproject +++ b/uproject @@ -241,6 +241,78 @@ done ################################################################################ # Traiter les commandes +function cxone_init() { + repourl="${1%.git}" + [ -n "$repourl" ] || return + rname= + rtype=gitolite + rprefix= + + REPO_PREFIXES=() + REPO_TYPES=() + set_defaults pcrone + + # Traduire les aliases éventuels + local asrcdest asrc adest + for asrcdest in "${REPO_PREFIXES[@]}"; do + splitfsep "$asrcdest" = asrc adest + if [ "${repourl#$asrc}" != "$repourl" ]; then + newurl="$adest${repourl#$asrc}" + if [ "$newurl" != "$repourl" ]; then + enote "$repourl --> $newurl" + repourl="$newurl" + break + fi + fi + done + + local rnametypeprefix tmp found + for rnametypeprefix in "${REPO_TYPES[@]}"; do + splitfsep "$rnametypeprefix" : rname tmp + splitfsep "$tmp" : rtype rprefix + if [ "${repourl#$rprefix}" != "$repourl" ]; then + found=1 + break + fi + done + if [ -z "$found" ]; then + rname= + rtype=gitolite + rprefix= + fi +} +function curlto() { + local url="$1"; shift + local payload="$1"; shift + local outfile="$1"; shift + local tmpfile + if [ -z "$outfile" ]; then + ac_set_tmpfile tmpfile + outfile="$tmpfile" + fi + + local -a args + local r http_code + args=(-s -w '%{http_code}' -o "$outfile") + [ -n "$payload" ] && args+=(-d "$payload") + args+=("$@" "$url") + setx http_code=curl "${args[@]}" + + case "$http_code" in + 2*) r=0;; + 4*) r=1;; + 5*) r=3;; + *) r=11;; + esac + if [ -n "$tmpfile" ]; then + cat "$tmpfile" + ac_clean "$tmpfile" + fi + + upvar http_code "$http_code" + return "$r" +} + if [ "$CMD" == "grep" ]; then ## grep if [ $# -eq 1 -a "$1" == "--help" ]; then @@ -339,9 +411,14 @@ NR <= 2 { next } -r,--recursive recursive=1 \ @ args -- "$@" && set -- "${args[@]}" || die "$args" + cxone_init "$@" + [ -n "$repourl" ] && set -- "$repourl" "${@:2}" + if [ -n "$recursive" ]; then repobase="$1" [ -n "$repobase" ] || die "Vous devez spécifier l'url de base des dépôts à cloner" + [ "$rtype" == gitolite ] || die "Le clonage récursif n'est supporté que pour les dépôts de type gitolite" + if [ "${repobase#http://}" != "$repobase" -o "${repobase#https://}" != "$repobase" ]; then # accès par http mode=http @@ -417,27 +494,10 @@ NR <= 2 { next } fi elif [ "$CMD" == crone ]; then - REPO_TYPES=() - set_defaults pcrone - - repourl="${1%.git}" + cxone_init "$@" [ -n "$repourl" ] || die "Vous devez spécifier l'url du dépôt git" - found= - for repo_ntp in "${REPO_TYPES[@]}"; do - splitfsep "$repo_ntp" : name tmp - splitfsep "$tmp" : type prefix - if [ "${repourl#$prefix}" != "$repourl" ]; then - found=1 - break - fi - done - if [ -z "$found" ]; then - name= - type=gitolite - prefix= - fi - if [ "$type" == "gitolite" ]; then + if [ "$rtype" == "gitolite" ]; then if [ "${repourl#http://}" != "$repourl" -o "${repourl#https://}" != "$repourl" ]; then # accès par http mode=gitolite_http @@ -455,15 +515,15 @@ elif [ "$CMD" == crone ]; then [ -n "$host" ] || die "Vous devez spécifier l'hôte" userhost="$user@$host" fi - elif [ "$type" == "gogs" ]; then + elif [ "$rtype" == gogs -o "$rtype" == gitea ]; then mode=gogs_http - gogs_url="${name}_GOGS_URL"; gogs_url="${!gogs_url}" - gogs_user="${name}_GOGS_USER"; gogs_user="${!gogs_user}" - gogs_key="${name}_GOGS_KEY"; gogs_key="${!gogs_key}" - userpath="${repourl#$prefix}" + gogs_url="${rname}_GOGS_URL"; gogs_url="${!gogs_url}" + gogs_user="${rname}_GOGS_USER"; gogs_user="${!gogs_user}" + gogs_key="${rname}_GOGS_KEY"; gogs_key="${!gogs_key}" + userpath="${repourl#$rprefix}" splitfsep "$userpath" / user path else - die "$type: type de dépôt non supporté" + die "$rtype: type de dépôt non supporté" fi [ -n "$path" ] || die "Vous devez spécifier le chemin du dépôt git" @@ -508,11 +568,13 @@ elif [ "$CMD" == crone ]; then else url="$gogs_url/api/v1/user/repos" fi - setx result=curl -fs \ + setx result=curlto "$url" "$payload" "" \ -H 'Content-Type: application/json' \ - -H "Authorization: token $gogs_key" \ - -d "$payload" \ - "$url" || die "Une erreur s'est produite lors de la tentative de création du dépôt" + -H "Authorization: token $gogs_key" || \ + die "Une erreur s'est produite lors de la tentative de création du dépôt +url: $url +payload: $payload +result: $result" echo "$result" if [ -n "$tmpdestdir" ]; then setxx destname=abspath "$destdir" // basename From dcb637e0544022c33b823a1663ba8604b97382c1 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 16 Nov 2018 21:22:05 +0400 Subject: [PATCH 05/10] dk: support de --no-cache pour docker-compose build --- dk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dk b/dk index 0e24c3a..6c87311 100755 --- a/dk +++ b/dk @@ -111,7 +111,9 @@ function update_build_env() { default_update_build_env; } function default_compose_build() { docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ - build "${replace_build_args[@]}" "${build_args[@]}" \ + build \ + ${NO_CACHE:+--no-cache} \ + "${replace_build_args[@]}" "${build_args[@]}" \ "$@" } function default_docker_build() { From 45da7267042c4a23ca6cd062c4eb5de2ab072137 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 19 Nov 2018 09:56:04 +0400 Subject: [PATCH 06/10] dk: ajout de l'option --fake pour afficher les commandes --- dk | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/dk b/dk index 6c87311..aec3197 100755 --- a/dk +++ b/dk @@ -11,7 +11,8 @@ USAGE COMMANDES build push - run + start, run + stop up logs down @@ -19,7 +20,15 @@ COMMANDES ps ls rm - prune" + prune + +OPTIONS + -d, --chdir PROJDIR + -p, --profile PROFILE + -P, --prod + -T, --test + -j, --no-cache + -n, --fake" } function get_version() { @@ -109,7 +118,7 @@ function default_update_build_env() { function update_build_env() { default_update_build_env; } function default_compose_build() { - docker-compose \ + ${FAKE:+qvals} docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ build \ ${NO_CACHE:+--no-cache} \ @@ -121,7 +130,7 @@ function default_docker_build() { for tag in "${TAGS[@]}"; do replace_build_args+=(-t "$NAME:$tag") done - docker build \ + ${FAKE:+qvals} docker build \ ${NO_CACHE:+--no-cache} \ "${replace_env_args[@]}" "${env_args[@]}" \ "${replace_build_args[@]}" "${build_args[@]}" \ @@ -160,18 +169,18 @@ function auto_push() { update_build_env fi for tag in "${TAGS[@]}"; do - docker push "$NAME:$tag" + ${FAKE:+qvals} docker push "$NAME:$tag" done } function default_compose_up() { - docker-compose \ + ${FAKE:+qvals} docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ up "${replace_run_args[@]}" "${run_args[@]}" \ "${replace_user_args[@]}" "${user_args[@]}" "$@" } function default_docker_up() { - docker run \ + ${FAKE:+qvals} docker run \ "${replace_env_args[@]}" "${env_args[@]}" \ "${replace_run_args[@]}" "${run_args[@]}" \ "$NAME" \ @@ -196,13 +205,13 @@ function auto_up() { } function default_compose_stop() { - docker-compose \ + ${FAKE:+qvals} docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ stop "${replace_stop_args[@]}" "${stop_args[@]}" \ "$@" } function default_docker_stop() { - docker container stop \ + ${FAKE:+qvals} docker container stop \ "${replace_stop_args[@]}" "${stop_args[@]}" \ "$name" "$@" } @@ -222,13 +231,13 @@ function auto_stop() { } function default_compose_logs() { - docker-compose \ + ${FAKE:+qvals} docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ logs "${replace_logs_args[@]}" "${logs_args[@]}" \ "$@" } function default_docker_logs() { - docker logs \ + ${FAKE:+qvals} docker logs \ "${replace_logs_args[@]}" "${logs_args[@]}" \ "$name" "$@" } @@ -250,18 +259,18 @@ function auto_logs() { } function default_compose_down() { - docker-compose \ + ${FAKE:+qvals} docker-compose \ "${replace_env_args[@]}" "${env_args[@]}" \ down "${replace_down_args[@]}" "${down_args[@]}" \ "$@" } function default_docker_down() { estep "stop" - docker container stop \ + ${FAKE:+qvals} docker container stop \ "${replace_down_args[@]}" "${down_args[@]}" \ "$name" "$@" estep "rm" - docker container rm \ + ${FAKE:+qvals} docker container rm \ "${replace_rm_args[@]}" "${rm_args[@]}" \ "$name" } @@ -300,6 +309,7 @@ fi chdir= NO_CACHE= +FAKE= args=( --help '$exit_with display_help' -d:,--chdir: chdir= @@ -307,6 +317,7 @@ args=( -P,--prod PROFILE=prod -T,--test PROFILE=test -j,--no-cache NO_CACHE=1 + -n,--fake FAKE=1 ) parse_args "$@"; set -- "${args[@]}" From 01325d0c237473877f504beccf7f4d63011a5db1 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 19 Nov 2018 22:24:28 +0400 Subject: [PATCH 07/10] sqlmig: support chemin config/sqlmig et bug avec csv_null --- sqlmig | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/sqlmig b/sqlmig index 3b084db..979bbad 100755 --- a/sqlmig +++ b/sqlmig @@ -980,6 +980,8 @@ if [ -z "$dbdir" -a -z "$updatedir" ]; then setx parentdir=dirname -- "$cwd" if __check_devel_dir src/main/resources/database; then enote "Autosélection src/main/resources/database/" + elif __check_devel_dir config/sqlmig; then + enote "Autosélection config/sqlmig/" elif __check_devel_dir support/database; then enote "Autosélection support/database/" elif __check_devel_dir database; then @@ -1086,7 +1088,8 @@ grant resource to $dbname;" echo >"$dbdir/ora.conf" "\ # Paramètres de connexion par défaut ORACLE_SID=orcl -NLS_LANG=AMERICAN_AMERICA.AL32UTF8 +NLS_LANG=FRENCH_FRANCE.AL32UTF8 +#NLS_LANG=AMERICAN_AMERICA.AL32UTF8 # paramètres de connexion pour les mises à jour administratives # si aucune valeur n'est spécifiée, la valeur effective est '/ as sysdba' mais # cela requière que la mise à jour soit faite avec une connexion locale. @@ -1334,19 +1337,24 @@ for dbdir in "${dbdirs[@]}"; do ensure_dbtype "$dbdir" "$type" ensure_dbmode "$dbtype" "$mode" - # Conversion csv --> sql - array_lsfiles csvs "$dbdir" "*.csv" - if [ "$dbtype" == mysql -a -n "$data_csv" ]; then - etitled "Conversion" - for csv in "${csvs[@]}"; do - setx csvname=basename -- "$csv" - sql="${csv%.csv}.sql" - if [ "$data_csv" != force ]; then - testnewer "$csv" "$sql" || continue - fi + if [ -n "$data_csv" ]; then + # Conversion csv --> sql + array_lsfiles csvs "$dbdir" "*.csv" + if [ "$dbtype" == mysql ]; then + setx defaults=mysql_get_defaults "$dbdir" + set_csv_null=1 + mysql__mconf_get "$defaults" - estep "$csvname --> ${csvname%.csv}.sql" - eval "$(awk '{ + etitled "Conversion" + for csv in "${csvs[@]}"; do + setx csvname=basename -- "$csv" + sql="${csv%.csv}.sql" + if [ "$data_csv" != force ]; then + testnewer "$csv" "$sql" || continue + fi + + estep "$csvname --> ${csvname%.csv}.sql" + script='{ truncate = ($0 ~ /-data_truncate(.devel)?.csv$/)? "1": "" sub(/^.*\//, "") sub(/^[A-Z0-9.]*[0-9]-?/, "") @@ -1356,10 +1364,12 @@ for dbdir in "${dbdirs[@]}"; do print "truncate=" truncate gsub(/'\''/, "'\'\\\\\'\''") print "table='\''" $0 "'\''" -}' <<<"$csvname")" #" - "$scriptdir/mysqlloadcsv" >"$sql" ${truncate:+-T} -Z "$csv_null" -nIf "$csv" "$table" --prefix "-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8" - done - eend; eclearp +}' + eval "$(awk "$script" <<<"$csvname")" + "$scriptdir/mysqlloadcsv" >"$sql" ${truncate:+-T} -Z "$csv_null" -nIf "$csv" "$table" --prefix "-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8" + done + eend; eclearp + fi fi # lister les mises à jour disponibles From f72dd865846f84eea0389cb0f16d0395e4373217 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 21 Nov 2018 22:19:35 +0400 Subject: [PATCH 08/10] =?UTF-8?q?option=20-n=20pour=20pcrone=20le=20clone?= =?UTF-8?q?=20pas=20le=20d=C3=A9p=C3=B4t=20nouvellement=20cr=C3=A9=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uproject | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/uproject b/uproject index 1dcab3b..8e81620 100755 --- a/uproject +++ b/uproject @@ -494,6 +494,11 @@ NR <= 2 { next } fi elif [ "$CMD" == crone ]; then + no_clone= + parse_opts "${PRETTYOPTS[@]}" \ + -n,--no-clone no_clone=1 \ + @ args -- "$@" && set -- "${args[@]}" || die "$args" + cxone_init "$@" [ -n "$repourl" ] || die "Vous devez spécifier l'url du dépôt git" @@ -533,7 +538,7 @@ elif [ "$CMD" == crone ]; then destdir="${destdir%.git}" fi tmpdestdir= - if [ -d "$destdir" ]; then + if [ -d "$destdir" -a -z "$no_clone" ]; then [ -d "$destdir/.git" ] && die "$(ppath2 "$destdir"): un dépôt existe déjà" ac_set_tmpdir tmpdestdir fi @@ -542,6 +547,8 @@ elif [ "$CMD" == crone ]; then setx result=curl -fs "$hostuser/create?$path" || die echo "$result" [[ "$result" == FATAL:* ]] && die + [ -n "$no_clone" ] && exit 0 + if [ -n "$tmpdestdir" ]; then setxx destname=abspath "$destdir" // basename git clone "$hostuser/$path" "$tmpdestdir/$destname" || die @@ -550,9 +557,12 @@ elif [ "$CMD" == crone ]; then else git clone "$hostuser/$path" "$destdir" || die fi + elif [ "$mode" == gitolite_ssh ]; then git_annex_use_ssh_wrapper ssh "$userhost" create "$path" || die + [ -n "$no_clone" ] && exit 0 + if [ -n "$tmpdestdir" ]; then setxx destname=abspath "$destdir" // basename git clone "$userhost:$path" "$tmpdestdir/$destname" || die @@ -561,6 +571,7 @@ elif [ "$CMD" == crone ]; then else git clone "$userhost:$path" "$destdir" || die fi + elif [ "$mode" == gogs_http ]; then payload='{"private":true,"name":"'"$path"'"}' if [ "$gogs_user" != "$user" ]; then @@ -576,6 +587,8 @@ url: $url payload: $payload result: $result" echo "$result" + [ -n "$no_clone" ] && exit 0 + if [ -n "$tmpdestdir" ]; then setxx destname=abspath "$destdir" // basename git clone "$repourl" "$tmpdestdir/$destname" || die @@ -587,26 +600,23 @@ result: $result" else die "bug: mode non prévu" fi - if [ ! -f "$destdir/.gitignore" -o ! -f "$destdir/.gitattributes" ]; then - if ask_yesno "Voulez-vous créer les fichiers initiaux .gitignore et/ou .gitattributes?" O; then - if [ -f "$destdir/.gitignore" ]; then - einfo "Refus d'écraser le fichier .gitignore existant" - else - echo >"$destdir/.gitignore" "\ + + if [ -f "$destdir/.gitignore" ]; then + : + elif ask_yesno "Voulez-vous créer le fichier initial .gitignore?" O; then + echo >"$destdir/.gitignore" "\ .~lock*# .*.swp" - fi - if [ -f "$destdir/.gitattributes" ]; then - einfo "Refus d'écraser le fichier .gitattributes existant" - else - echo >"$destdir/.gitattributes" "\ + fi + if [ -f "$destdir/.gitattributes" ]; then + : + elif ask_yesno "Voulez-vous créer le fichier initial .gitattributes?" N; then + echo >"$destdir/.gitattributes" "\ *.zip -delta *.gz -delta *.bz2 -delta *.whl -delta *.exe -delta" - fi - fi fi elif [ "$CMD" == xconfig-export ]; then From ba29496150d12dadf64e401f86a74ac50c8418c6 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 22 Nov 2018 15:34:07 +0400 Subject: [PATCH 09/10] =?UTF-8?q?dk:=20g=C3=A9n=C3=A9ration=20d'un=20servi?= =?UTF-8?q?ce=20systemd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dk | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 161 insertions(+), 14 deletions(-) diff --git a/dk b/dk index aec3197..b7a2330 100755 --- a/dk +++ b/dk @@ -12,6 +12,7 @@ COMMANDES build push start, run + service stop up logs @@ -27,8 +28,9 @@ OPTIONS -p, --profile PROFILE -P, --prod -T, --test + -n, --fake -j, --no-cache - -n, --fake" + -h, --host HOST" } function get_version() { @@ -79,8 +81,10 @@ function docker_set_run_args() { } function docker_check_name() { [ -n "$NAME" ] || die "Vous devez définir NAME dans .build.env" - if [ "$1" == set_name ]; then - name="${NAME//[^a-zA-Z0-9_.-]/_}" + if [ "$1" == set_container_name ]; then + project_name="$NAME" + container_name="${project_name//[^a-zA-Z0-9_-]/}" + [ -n "$PROFILE" ] && container_name="${container_name}_$PROFILE" fi } @@ -103,6 +107,62 @@ function compose_set_env_args() { export COMPOSE_PROJECT_NAME fi fi + if [ "$1" == set_container_name ]; then + if [ "$PROJECT_NAME" == --none-- ]; then + project_name="$(basename -- "$(pwd)")" + else + project_name="$PROJECT_NAME" + fi + container_name="${project_name//[^a-zA-Z0-9_-]/}" + [ -n "$PROFILE" ] && container_name="${container_name}_$PROFILE" + fi +} + +function host_run() { + # lancer le script $2..@ sur l'hôte $1 + # si $1 n'est pas défini ou est le nom l'hôte local, lancer le script en + # local avec les droits root + # sinon, si docker-machine existe, l'hôte doit correspondre à la machine active + # sinon, lancer inconditionnellement le script sur l'hôte distant + local host="$1" script="$2"; shift; shift + if [ -n "$host" ]; then + if check_hostname "$host"; then + 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 + 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)" + fi + else + 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" + fi + else + estep "Lancement de $script localement" + runscript_as_root "$script" "$@" + fi +} +function local_run() { + # lancer le script $2..@ sur l'hôte $1 uniquement si c'est l'hôte courant + local host="$1" script="$2"; shift; shift + if [ -n "$host" ]; then + if ! check_hostname "$host"; then + eerror "Cette commande doit obligatoirement être lancée depuis l'hôte $host" + return 1 + fi + fi + estep "Lancement de $script localement" + runscript_as_root "$script" "$@" } function initialize_build_env() { @@ -192,18 +252,92 @@ function auto_up() { local -a replace_env_args env_args local -a replace_run_args run_args local -a replace_user_args user_args + local project_name container_name if [ -f docker-compose.yml ]; then compose_set_env_args replace_run_args=(-d) compose_up "$@" else docker_set_env_args - docker_check_name set_name - replace_run_args=(-d --name "$name") + docker_check_name set_container_name + replace_run_args=(-d --name "$container_name") docker_up "$@" fi } +function default_compose_service() { + local docker_compose="$(which 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 +} +function default_docker_service() { + local docker="$(which docker)" + setx startcmd=qvals "$docker" run \ + "${replace_env_args[@]}" "${env_args[@]}" \ + "${replace_run_args[@]}" "${run_args[@]}" \ + "$NAME" \ + "${replace_user_args[@]}" "${user_args[@]}" "$@" + setx stopcmd=qvals "$docker" stop "$container_name" +} +function compose_service() { default_compose_service "$@"; } +function docker_service() { default_docker_service "$@"; } +function auto_service() { + local -a replace_env_args env_args + local -a replace_run_args run_args + local -a replace_user_args user_args + local project_name container_name startcmd stopcmd + local tmpscript; ac_set_tmpfile tmpscript + + estep "Génération du service" + export COMPOSE_PROJECT_NAME= + if [ -f docker-compose.yml ]; then + compose_set_env_args set_container_name + replace_run_args=(-d --no-color) + compose_service "$@" + if [ -z "$HOST" -a -f .env ]; then + source ./.env + if [ -n "$PROFILE" ]; then + HOST="${PROFILE^^}_HOST"; HOST="${!HOST}" + fi + fi + else + docker_set_env_args + docker_check_name set_container_name + replace_run_args=(-d --name "$container_name") + docker_service "$@" + fi + [ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$project_name" + chmod 755 "$tmpscript" + cat >"$tmpscript" </etc/systemd/system/$container_name.service < Date: Thu, 22 Nov 2018 15:40:33 +0400 Subject: [PATCH 10/10] Init changelog & version 9.1.0 --- CHANGES.md | 13 +++++++++++++ VERSION.txt | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 795a185..c44af77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,16 @@ +## Version 9.1.0 du 22/11/2018-15:40 + +* `ba29496` dk: génération d'un service systemd +* `f72dd86` option -n pour pcrone le clone pas le dépôt nouvellement créé +* `01325d0` sqlmig: support chemin config/sqlmig et bug avec csv_null +* `45da726` dk: ajout de l'option --fake pour afficher les commandes +* `dcb637e` dk: support de --no-cache pour docker-compose build +* `9c6f606` Intégration de la branche update-pcrone + * `764dd53` maj prefixe et meilleur affichage des erreurs +* `307fa48` dk: option -j pour désactiver le cache +* `45c6422` profils pour docker-machine +* `a9004fa` dk: PROFILE est exporté + ## Version 9.0.0 du 15/11/2018-09:40 * `af969e4` maj de l'url source de nutools diff --git a/VERSION.txt b/VERSION.txt index f7ee066..47da986 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -9.0.0 +9.1.0