Intégration de la branche release-8.1.0
This commit is contained in:
commit
7d451b00c7
|
@ -1,3 +1,12 @@
|
|||
## Version 8.1.0 du 28/09/2018-08:39
|
||||
|
||||
* `e74480c` dk: action build par défaut
|
||||
* `56b18a4` dk: rendre overridable VERSION
|
||||
* `ed180b5` dk pour faciliter l'utilisation de docker
|
||||
* `4ad84c0` sqlmig: ajout de la restauration de la base test à partir d'une copie de la prod
|
||||
* `a5be8d8` maj gitignore initial
|
||||
* `19267dd` utempl: support du datage automatique des fichiers
|
||||
|
||||
## Version 8.0.0 du 21/07/2018-10:21
|
||||
|
||||
* `a60f23a` maj version ulib
|
||||
|
|
|
@ -1 +1 @@
|
|||
8.0.0
|
||||
8.1.0
|
||||
|
|
|
@ -0,0 +1,317 @@
|
|||
#!/bin/bash
|
||||
# -*- 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
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: outil pour faciliter l'utilisation de docker
|
||||
|
||||
USAGE
|
||||
$scriptname CMDs...
|
||||
|
||||
COMMANDES
|
||||
build
|
||||
run
|
||||
up
|
||||
logs
|
||||
down
|
||||
brd
|
||||
ps
|
||||
ls
|
||||
rm
|
||||
prune"
|
||||
}
|
||||
|
||||
function get_version() {
|
||||
local GIT_DIR; unset GIT_DIR
|
||||
if git rev-parse --git-dir >/dev/null 2>&1; then
|
||||
local head commit tag
|
||||
commit="$(git rev-list --tags --max-count=1 2>/dev/null)"
|
||||
if [ -n "$commit" ]; then
|
||||
tag="$(git describe --tags "$commit" 2>/dev/null)"
|
||||
if [ -n "$tag" ]; then
|
||||
head="$(git rev-parse HEAD)"
|
||||
if [ "$commit" != "$head" ]; then
|
||||
echo "$tag-develop"
|
||||
else
|
||||
echo "$tag"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
fi
|
||||
elif [ -f VERSION.txt ]; then
|
||||
cat VERSION.txt
|
||||
fi
|
||||
echo develop
|
||||
}
|
||||
|
||||
function docker_add_build_arg() {
|
||||
eval "replace_build_args+=(--build-arg $1=\"$2\"); $1=\"$2\""
|
||||
}
|
||||
function docker_parse_build_args() {
|
||||
cat "$1" |
|
||||
grep -v '^#' |
|
||||
grep -v '^$' |
|
||||
sed -r 's/([^=]+)=(.*)/replace_build_args+=(--build-arg \1="\2"); \1="\2"/'
|
||||
}
|
||||
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")"
|
||||
}
|
||||
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"
|
||||
}
|
||||
function docker_set_run_args() {
|
||||
replace_run_args+=(--env-file "$1")
|
||||
source "$1"
|
||||
}
|
||||
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_.-]/_}"
|
||||
fi
|
||||
}
|
||||
|
||||
function compose_set_env_args() {
|
||||
replace_env_args+=(-f docker-compose.yml)
|
||||
if [ -f docker-compose.override.yml ]; then
|
||||
replace_env_args+=(-f docker-compose.override.yml)
|
||||
fi
|
||||
if [ -n "$profile" -a -f "docker-compose.$profile.yml" ]; then
|
||||
replace_env_args+=(-f "docker-compose.$profile.yml")
|
||||
fi
|
||||
}
|
||||
|
||||
function default_compose_build() {
|
||||
docker-compose \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
build "${replace_build_args[@]}" "${build_args[@]}" \
|
||||
"$@"
|
||||
}
|
||||
function default_docker_build() {
|
||||
[ -n "$VERSION" ] || docker_add_build_arg VERSION "$(get_version)"
|
||||
replace_build_args+=(-t "$NAME:$VERSION" -t "$NAME:latest")
|
||||
docker build \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
"${replace_build_args[@]}" "${build_args[@]}" \
|
||||
"$@" "$CTXDIR"
|
||||
}
|
||||
function compose_build() { default_compose_build "$@"; }
|
||||
function docker_build() { default_docker_build "$@"; }
|
||||
function auto_build() {
|
||||
local -a replace_env_args env_args
|
||||
local -a replace_build_args build_args
|
||||
CTXDIR=.
|
||||
NAME=
|
||||
VERSION=
|
||||
if [ -f docker-compose.yml ]; then
|
||||
compose_set_env_args
|
||||
compose_build
|
||||
else
|
||||
docker_parse_env_args
|
||||
docker_check_name
|
||||
docker_add_build_arg build_date "$(date +%y%m%d)"
|
||||
docker_build
|
||||
fi
|
||||
}
|
||||
|
||||
function default_compose_up() {
|
||||
docker-compose \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
up "${replace_run_args[@]}" "${run_args[@]}" \
|
||||
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
||||
}
|
||||
function default_docker_up() {
|
||||
docker run \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
"${replace_run_args[@]}" "${run_args[@]}" \
|
||||
"$NAME" \
|
||||
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
||||
}
|
||||
function compose_up() { default_compose_up "$@"; }
|
||||
function docker_up() { default_docker_up "$@"; }
|
||||
function auto_up() {
|
||||
local -a replace_env_args env_args
|
||||
local -a replace_run_args run_args
|
||||
local -a replace_user_args user_args
|
||||
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_up "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
function default_compose_stop() {
|
||||
docker-compose \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
stop "${replace_stop_args[@]}" "${stop_args[@]}" \
|
||||
"$@"
|
||||
}
|
||||
function default_docker_stop() {
|
||||
docker container stop \
|
||||
"${replace_stop_args[@]}" "${stop_args[@]}" \
|
||||
"$name" "$@"
|
||||
}
|
||||
function compose_stop() { default_compose_stop "$@"; }
|
||||
function docker_stop() { default_docker_stop "$@"; }
|
||||
function auto_stop() {
|
||||
local -a replace_env_args env_args
|
||||
local -a replace_stop_args stop_args
|
||||
if [ -f docker-compose.yml ]; then
|
||||
compose_set_env_args
|
||||
compose_stop "$@"
|
||||
else
|
||||
docker_set_env_args
|
||||
docker_check_name set_name
|
||||
docker_stop "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
function default_compose_logs() {
|
||||
docker-compose \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
logs "${replace_logs_args[@]}" "${logs_args[@]}" \
|
||||
"$@"
|
||||
}
|
||||
function default_docker_logs() {
|
||||
docker logs \
|
||||
"${replace_logs_args[@]}" "${logs_args[@]}" \
|
||||
"$name" "$@"
|
||||
}
|
||||
function compose_logs() { default_compose_logs "$@"; }
|
||||
function docker_logs() { default_docker_logs "$@"; }
|
||||
function auto_logs() {
|
||||
local -a replace_env_args env_args
|
||||
local -a replace_logs_args logs_args
|
||||
if [ -f docker-compose.yml ]; then
|
||||
compose_set_env_args
|
||||
replace_logs_args=(-f)
|
||||
compose_logs "$@"
|
||||
else
|
||||
docker_set_env_args
|
||||
docker_check_name set_name
|
||||
replace_logs_args=(-f)
|
||||
docker_logs "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
function default_compose_down() {
|
||||
docker-compose \
|
||||
"${replace_env_args[@]}" "${env_args[@]}" \
|
||||
down "${replace_down_args[@]}" "${down_args[@]}" \
|
||||
"$@"
|
||||
}
|
||||
function default_docker_down() {
|
||||
estep "stop"
|
||||
docker container stop \
|
||||
"${replace_down_args[@]}" "${down_args[@]}" \
|
||||
"$name" "$@"
|
||||
estep "rm"
|
||||
docker container rm \
|
||||
"${replace_rm_args[@]}" "${rm_args[@]}" \
|
||||
"$name"
|
||||
}
|
||||
function compose_down() { default_compose_down "$@"; }
|
||||
function docker_down() { default_docker_down "$@"; }
|
||||
function auto_down() {
|
||||
local -a replace_env_args env_args
|
||||
local -a replace_down_args down_args
|
||||
local -a replace_rm_args rm_args
|
||||
if [ -f docker-compose.yml ]; then
|
||||
compose_set_env_args
|
||||
compose_down "$@"
|
||||
else
|
||||
docker_set_env_args
|
||||
docker_check_name set_name
|
||||
docker_down "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
chdir=
|
||||
profile=devel
|
||||
args=(+
|
||||
--help '$exit_with display_help'
|
||||
-d:,--chdir: chdir=
|
||||
-p:,--profile: profile=
|
||||
-P,--prod profile=prod
|
||||
-T,--test profile=test
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
[ -n "$chdir" ] && { cd "$chdir" || die; }
|
||||
|
||||
# construire par défaut
|
||||
[ $# -eq 0 ] && set -- build
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
[ "$1" == -- ] && { shift; continue; }
|
||||
cmd="$1"; shift
|
||||
case "$cmd" in
|
||||
b|build)
|
||||
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
|
||||
[ -f build.scripts.sh ] && source ./build.scripts.sh
|
||||
args=()
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
auto_build "${args[@]}" || die
|
||||
;;
|
||||
s|run|start)
|
||||
args=()
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
auto_up "${args[@]}" || die
|
||||
;;
|
||||
k|stop)
|
||||
auto_stop || die
|
||||
;;
|
||||
1|up)
|
||||
args=()
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
auto_up "${args[@]}" && auto_logs || die
|
||||
;;
|
||||
l|logs) auto_logs || die;;
|
||||
0|down) auto_down || die;;
|
||||
d|brd)
|
||||
do_auto_down=1
|
||||
function auto_down_trap() {
|
||||
[ -n "$do_auto_down" ] && auto_down
|
||||
}
|
||||
trap auto_down_trap 1 3 15 EXIT
|
||||
|
||||
args=()
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
if auto_build; then
|
||||
auto_up "${args[@]}" && auto_logs || die
|
||||
else
|
||||
do_auto_down=
|
||||
fi
|
||||
;;
|
||||
ps) docker container ps -a || die;;
|
||||
ls) docker image ls || die;;
|
||||
rm)
|
||||
args=()
|
||||
while [ $# -gt 0 -a "$1" != -- ]; do
|
||||
args+=("$1"); shift
|
||||
done
|
||||
docker image rm "${args[@]}" || die
|
||||
;;
|
||||
X|prune)
|
||||
docker container prune -f || die
|
||||
docker image prune -f || die
|
||||
;;
|
||||
*) die "$cmd: commande inconnue";;
|
||||
esac
|
||||
done
|
4
fndate
4
fndate
|
@ -234,6 +234,7 @@ dcopy) action=copy;;
|
|||
dmove) action=move;;
|
||||
dcmd) action=cmd;;
|
||||
esac
|
||||
cmd_quiet=
|
||||
placeholder=
|
||||
auto_force_date=1
|
||||
force_date=
|
||||
|
@ -248,6 +249,7 @@ parse_opts "${PRETTYOPTS[@]}" \
|
|||
-m,--move action=move \
|
||||
-c,--cmd action=cmd \
|
||||
--string action=string \
|
||||
--cmd-quiet cmd_quiet=1 \
|
||||
-P:,--placeholder: placeholder= \
|
||||
--no-auto-force-date auto_force_date= \
|
||||
-@:,--force-date: force_date= \
|
||||
|
@ -293,7 +295,7 @@ if [ "$action" == cmd ]; then
|
|||
found=
|
||||
for arg in "$@"; do
|
||||
if have_ph "$arg"; then
|
||||
check_interaction -c && evalx qvals "${args[@]}" "$arg" // estepi "Commande:"
|
||||
[ -z "$cmd_quiet" ] && check_interaction -c && evalx qvals "${args[@]}" "$arg" // estepi "Commande:"
|
||||
setx arg=replace_ph "$arg" "$force_date"
|
||||
read_value "Veuillez confirmer le nom" arg "$arg"
|
||||
found=1
|
||||
|
|
66
sqlmig
66
sqlmig
|
@ -116,6 +116,15 @@ OPTIONS
|
|||
-c, --connect
|
||||
Se connecter avec le client natif (mysql ou sqlplus) sur la base de
|
||||
données courante.
|
||||
-r, --restore-test
|
||||
Restaurer une sauvegarde d'une base de production sur la test. Cette
|
||||
option n'est (actuellement) supportée que pour MySQL.
|
||||
L'argument attendu est un fichier de sauvegarde DATABASE.sql[.gz]
|
||||
effectué avec la commande
|
||||
mysqldump --databases --add-drop-database DATABASE
|
||||
Dans le fichier spécifié, on remplace toutes les occurences de DATABASE
|
||||
par DATABASE_test, ensuite on lance (re)création de la base de données
|
||||
mysql <DATABASE_test.sql
|
||||
--update-all
|
||||
Mettre à jour la base de données. C'est l'option par défaut
|
||||
-t, --updatedir UPDATEDIR
|
||||
|
@ -948,6 +957,7 @@ args=(
|
|||
-0,--init action=init
|
||||
-e:,--export: '$action=export; set@ exportdir'
|
||||
-c,--connect action=connect
|
||||
-r,--restore-test action=restore_test
|
||||
--update-all action=update
|
||||
-t:,--updatedir: updatedir=
|
||||
-d:,--databasedir: dbdir=
|
||||
|
@ -1185,6 +1195,62 @@ elif [ "$action" == connect ]; then
|
|||
done
|
||||
exit 0
|
||||
|
||||
################################################################################
|
||||
elif [ "$action" == restore_test ]; then
|
||||
set_dbdirs
|
||||
|
||||
if [ ${#dbdirs[*]} -gt 1 ]; then
|
||||
die "Avec --restore-test, une seule base de données doit être spécifiée"
|
||||
fi
|
||||
|
||||
dbdir="${dbdirs[0]}"
|
||||
[ -n "$dbname" ] || setx dbname=basename "$dbdir"
|
||||
|
||||
etitle "$dbname"
|
||||
|
||||
ensure_dbtype "$dbdir" "$type"
|
||||
ensure_dbmode "$dbtype" "$mode"
|
||||
|
||||
[ "$dbtype" == mysql ] || die "Seule les bases de type MySQL sont supportées"
|
||||
|
||||
# construire les paramètres pour mysql
|
||||
mysql_set_userargs "$dbdir" "$dbname"
|
||||
mysql_set_mysqlargs
|
||||
|
||||
if [ -n "$suffix" ]; then
|
||||
estepi "Suffixe: $dbname --> $dbname$suffix"
|
||||
dbname="$dbname$suffix"
|
||||
fi
|
||||
|
||||
dump="$1"
|
||||
[ -n "$dump" ] || die "Vous devez spécifier le fichier de dump"
|
||||
[ -f "$dump" ] || die "$dump: fichier de dump introuvable"
|
||||
|
||||
ac_set_tmpdir tmpdir
|
||||
if [[ "$dump" == *.gz ]]; then
|
||||
gzip -dc "$dump" >"$tmpdir/prod.sql"
|
||||
elif [[ "$dump" == *.sql ]]; then
|
||||
cat "$dump" >"$tmpdir/prod.sql"
|
||||
else
|
||||
die "$dump: n'est pas un fichier sql"
|
||||
fi
|
||||
dump="$tmpdir/prod.sql"
|
||||
|
||||
pname="$dbname"
|
||||
tname="${dbname}_test"
|
||||
sed <"$tmpdir/prod.sql" >"$tmpdir/test.sql" "\
|
||||
s/\`$pname\`/\`$tname\`/g
|
||||
s/\`${pname}_updates_\`/\`${tname}_updates_\`/g"
|
||||
|
||||
enote "Vous allez restaurer un fichier de sauvegarde de le base $pname vers la base $tname"
|
||||
ask_yesno "Voulez-vous continuer?" X || die
|
||||
|
||||
array_del mysqlargs -B # désactiver le mode batch
|
||||
mysql "${userargs[@]}" "${mysqlargs[@]}" <"$tmpdir/test.sql"
|
||||
ac_clean "$tmpdir"
|
||||
|
||||
exit 0
|
||||
|
||||
################################################################################
|
||||
elif [ "$action" != update ]; then
|
||||
die "BUG: $action: action non implémentée"
|
||||
|
|
4
uproject
4
uproject
|
@ -476,7 +476,9 @@ elif [ "$CMD" == crone ]; then
|
|||
die "bug: mode non prévu"
|
||||
fi
|
||||
if ask_yesno "Voulez-vous créer des fichiers .gitignore et .gitattributes initiaux?" O; then
|
||||
echo >"$destdir/.gitignore"
|
||||
echo >"$destdir/.gitignore" "\
|
||||
.~lock*#
|
||||
.*.swp"
|
||||
echo >"$destdir/.gitattributes" "\
|
||||
*.zip -delta
|
||||
*.gz -delta
|
||||
|
|
17
utempl
17
utempl
|
@ -18,6 +18,10 @@ Avant le nom du nouveau fichier, les options suivantes peuvent être utilisées:
|
|||
Editer le fichier après l'avoir créé
|
||||
-g, --no-edit
|
||||
Ne pas éditer le fichier après l'avoir créé
|
||||
--no-fndate
|
||||
Désactiver le support du marqueur ~~ pour dater le fichier.
|
||||
Par défaut, utiliser 'fndate -c $scriptname' si le nom du fichier
|
||||
contient le marqueur ~~
|
||||
|
||||
Après le nom du fichier, toutes les options sont spécifiques au modèle
|
||||
utilisé pour créer le nouveau fichier. Utiliser l'option --help pour
|
||||
|
@ -26,6 +30,7 @@ avoir une description des options disponibles."
|
|||
|
||||
template=
|
||||
edit=auto
|
||||
fndate=1
|
||||
overwrite=
|
||||
encoding=auto
|
||||
executable=auto
|
||||
|
@ -34,6 +39,7 @@ parse_opts + "${PRETTYOPTS[@]}" \
|
|||
--help '$exit_with display_help' \
|
||||
-t:,--template: template= \
|
||||
-e,--edit edit=1 \
|
||||
--no-fndate fndate= \
|
||||
-g,--no-edit edit= \
|
||||
-f,--overwrite overwrite=1 \
|
||||
-E:,--encoding: encoding= \
|
||||
|
@ -85,6 +91,12 @@ if [ ! -f "$templ" ]; then
|
|||
fi
|
||||
[ -n "$found" -a -x "$templ" ] || die "$file: Impossible de trouver le template $template${templ:+ ($(basename "$templ"))}"
|
||||
|
||||
if [ -n "$fndate" ]; then
|
||||
# n'utiliser fndate que si le marqueur est présent
|
||||
setx filename=basename -- "$file"
|
||||
[[ "$filename" == *~~* ]] || fndate=
|
||||
fi
|
||||
|
||||
args=()
|
||||
[ "$template" != "auto" ] && args=("${args[@]}" --template "$template")
|
||||
if [ "$edit" != "auto" ]; then
|
||||
|
@ -103,4 +115,7 @@ if [ "$executable" != "auto" ]; then
|
|||
args=("${args[@]}" --no-executable)
|
||||
fi
|
||||
fi
|
||||
exec "$templ" "$file" "${args[@]}" "${opts[@]}" "$@"
|
||||
|
||||
cmd=("$templ" "$file" "${args[@]}" "${opts[@]}" "$@")
|
||||
[ -n "$fndate" ] && cmd=("$scriptdir/fndate" -c --cmd-quiet -- "${cmd[@]}")
|
||||
exec "${cmd[@]}"
|
||||
|
|
Loading…
Reference in New Issue