Intégration de la branche release-9.3.0

This commit is contained in:
Jephté Clain 2019-04-02 16:03:38 +04:00
commit 7b191e94b6
5 changed files with 396 additions and 107 deletions

View File

@ -1,3 +1,13 @@
## Version 9.3.0 du 02/04/2019-16:03
* `6a03853` ajout de update-apps en natif
* `6462bec` dk: ajouter exec, maj doc
* `7a728a9` dk: stop, logs et down acceptent maintenant un argument
* `df788f6` support mariadb
* `edaaec1` bug
* `41089f7` dk: ajout de l'action bs
* `af2b74f` sqlmig: init crée aussi 02grants.sql
## Version 9.2.0 du 08/12/2018-11:58
* `71bb5aa` bug

View File

@ -1 +1 @@
9.2.0
9.3.0

478
dk
View File

@ -10,27 +10,71 @@ USAGE
COMMANDES
build
Construire les images
push
start, run
service
stop
Pousser les images vers le serveur
start, run [SERVICE]
Démarrer le(s) service(s)
stop [SERVICE]
Arrêter le(s) service(s)
up
logs
Créer l'environnement, démarrer les services et suivre les logs de façon
interactive.
logs [SERVICE]
Afficher les logs
down
Arrêter les services et supprimer l'environnement
brd
Construire les images (comme avec build), démarrer les services et
suivre les logs de façon interactive (comme avec up). Dès que l'on
arrête l'affichage des logs avec Ctrl+C, arrêter les services et
supprimer l'environnement (comme avec down)
bs
Construire les images (comme avec build) puis démarrer les services
(comme avec start)
exec SERVICE COMMAND
Lancer la commande dans le container spécifié
service
Générer une unité systemd qui démarre les services
ps
Afficher les containers en cours d'exécution
ls
Lister les images actuellement présentes
rm
Supprimer une image
prune
Supprimer les containers et les images inutilisées
OPTIONS
OPTIONS générales
(ces options sont communes à toutes les commandes)
-d, --chdir PROJDIR
-p, --profile PROFILE
-P, --prod
-T, --test
-n, --fake
-j, --no-cache
-h, --host HOST"
-h, --host HOST
OPTIONS build
(ces options ne sont valides que pour les commandes build, brd, bs)
-g, --ug, --no-update-apps
ne pas mettre à jour les dépôts dépendants. ces dépôts sont
définis dans le fichier update-apps.conf qui a le format
suivant:
DEFAULT_BRANCH=
APPS=()
app_URL=
app_DEST=
app_ORIGIN=
app_BRANCH=
app_TYPE=
app_AFTER_UPDATE=()
-u, --uu, --update-apps-only
Ne faire que la mise à jour depuis les dépôts dépendants.
--uo, --update-apps-origin ORIGIN
Spécifier l'origine par défaut pour update-apps
--ub, --update-apps-branch BRANCH
Spécifier la branche par défaut pour update-apps"
}
function get_version() {
@ -165,6 +209,145 @@ function local_run() {
runscript_as_root "$script" "$@"
}
BUILD_UPDATE_APPS=
BUILD_BUILD=
UPDATE_APPS_ORIGIN=
UPDATE_APPS_BRANCH=
function build_set_options() {
case "$1" in
u) BUILD_UPDATE_APPS=1; BUILD_BUILD=;;
b) BUILD_UPDATE_APPS=; BUILD_BUILD=1;;
*) BUILD_UPDATE_APPS=1; BUILD_BUILD=1;;
esac
UPDATE_APPS_ORIGIN="$2"
UPDATE_APPS_BRANCH="$3"
}
function update_apps_func_sqlmig() {
local destdir="$1" srcdir="$2"
[ -n "$destdir" ] || destdir=db
[ "${destdir%/config/mariadb/sqlmig}" != "$destdir" ] || destdir="$destdir/config/mariadb/sqlmig"
[ -n "$srcdir" ] || srcdir="$dest"
[ "${srcdir%/config/sqlmig}" != "$srcdir" ] || srcdir="$srcdir/config/sqlmig"
[ -d "$srcdir" ] || return 0
local -a sqlmigs; local sqlmig name
array_lsall sqlmigs "$srcdir"
mkdir -p "$destdir" || return 1
for sqlmig in "${sqlmigs[@]}"; do
if [ -d "$sqlmig" ]; then
setx name=basename -- "$sqlmig"
rsync -av --delete-after "$sqlmig/" "$destdir/$name"
else
rsync -av "$sqlmig" "$destdir"
fi
done
return 0
}
function build_update_apps() {
[ -n "$BUILD_UPDATE_APPS" ] || return 0
[ -f update-apps.conf ] || return 0
# charger le fichier de configuration
local DEFAULT_ORIGIN DEFAULT_BRANCH APPS
DEFAULT_ORIGIN="$UPDATE_APPS_ORIGIN"
[ -z "$DEFAULT_ORIGIN" ] && DEFAULT_ORIGIN=origin
DEFAULT_BRANCH="$UPDATE_APPS_BRANCH"
#XXX à terme, on déploiera la branche master en prod
[ -z "$DEFAULT_BRANCH" -a "$PROFILE" == prod ] && DEFAULT_BRANCH=develop #master
[ -z "$DEFAULT_BRANCH" ] && DEFAULT_BRANCH=develop
APPS=()
[ -f update-apps.conf ] && source ./update-apps.conf
[ ${#APPS[*]} -gt 0 ] || return 0
local PRODUCTION DEVELOPMENT
case "$PROFILE" in
prod) PRODUCTION=1; DEVELOPMENT=;;
test) PRODUCTION=1; DEVELOPMENT=1;;
devel) PRODUCTION=; DEVELOPMENT=;;
esac
etitle "Mise à jour des dépendances"
local app type url dest branch after_update after_updates
for app in "${APPS[@]}"; do
etitle "$app"
url="${app}_URL"; url="${!url}"
dest="${app}_DEST"; dest="${!dest}"
origin="${app}_ORIGIN"; origin="${!origin}"
branch="${app}_BRANCH"; branch="${!branch}"
type="${app}_TYPE"; type="${!type}"
after_updates="${app}_AFTER_UPDATE"
if is_defined "$after_updates"; then
after_updates="$after_updates[@]"; after_updates="${!after_updates}"
else
# script par défaut après update-apps
after_updates=(sqlmig)
fi
[ -n "$url" ] || {
ewarn "$app: vous devez définir l'url"
eend; return 1
}
[ -n "$dest" ] || dest="$app"
mkdir -p "$dest" || { eend; return 1; }
[ -n "$origin" ] || origin="$DEFAULT_ORIGIN"
[ -n "$branch" ] || branch="$DEFAULT_BRANCH"
dest="$dest/$app"
if [ ! -d "$dest" ]; then
# clonage initial
estep "Clonage $url:$branch --> $dest"
git clone -o "$origin" -b "$branch" "$url" "$dest" || { eend; return 1; }
else
# mise à jour
estep "Maj dépôt $url:$branch --> $dest"
setx cwd=pwd
cd "$dest"
git fetch --all -p -f || { eend; return 1; }
git reset --hard "$origin/$branch" || { eend; return 1; }
cd "$cwd"
fi
if [ -z "$type" ]; then
if [ -f "$dest/composer.json" ]; then
type=composer
else
type=inconnu
fi
fi
estep "Type de dépôt: $type"
if [ "$type" == composer ]; then
composer=/usr/bin/composer
[ -x "$dest/composer.phar" ] && composer="$dest/composer.phar"
estep "Installation des dépendances composer"
"$composer" -d"$dest" install ${PRODUCTION:+--no-dev -o} || { eend; return 1; }
fi
for after_update in "${after_updates[@]}"; do
if [ "${after_update#/}" != "$after_update" ]; then
# commande absolue, la lancer telle quelle
estep "$after_update"
eval "$after_update" || { eend; return 1; }
elif [ "${after_update#./}" != "$after_update" ]; then
# commande relative, la lancer telle quelle
estep "$after_update"
eval "$after_update" || { eend; return 1; }
else
# c'est une fonction update_apps_func_*
estep "$after_update"
eval "update_apps_func_$after_update" || { eend; return 1; }
fi
done
eend
done
eend
}
function initialize_build_env() {
CTXDIR=.
NAME=
@ -196,8 +379,14 @@ function default_docker_build() {
"${replace_build_args[@]}" "${build_args[@]}" \
"$@" "$CTXDIR"
}
function compose_build() { default_compose_build "$@"; }
function docker_build() { default_docker_build "$@"; }
function compose_build() {
[ -n "$BUILD_BUILD" ] || return 0
default_compose_build "$@"
}
function docker_build() {
[ -n "$BUILD_BUILD" ] || return 0
default_docker_build "$@"
}
function auto_build() {
local -a replace_env_args env_args
local -a replace_build_args build_args
@ -205,12 +394,14 @@ function auto_build() {
if [ -f docker-compose.yml ]; then
compose_set_env_args
update_build_env
build_update_apps || return 1
compose_build
else
docker_parse_env_args
docker_check_name
docker_add_build_arg build_date "$(date +%y%m%d)"
update_build_env
build_update_apps || return 1
docker_build
fi
}
@ -265,95 +456,6 @@ function auto_up() {
fi
}
function default_compose_service() {
local docker_compose="$(which docker-compose)"
if [ -z "$docker_compose" -a -x /usr/bin/docker-compose ]; then
docker_compose=/usr/bin/docker-compose
elif [ -z "$docker_compose" -a -x /usr/local/bin/docker-compose ]; then
docker_compose=/usr/local/bin/docker-compose
else
die "Impossible de trouver docker-compose"
fi
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)"
if [ -z "$docker" -a -x /usr/bin/docker ]; then
docker=/usr/bin/docker
elif [ -z "$docker" -a -x /usr/local/bin/docker ]; then
docker=/usr/local/bin/docker
else
die "Impossible de trouver docker"
fi
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" <<EOF
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
cat >/etc/systemd/system/$container_name.service <<EOD
[Unit]
Description=$project_name stack ($PROFILE)
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=$(pwd)
Environment=$(qval "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME")
ExecStart=$startcmd
ExecStop=$stopcmd
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
EOD
systemctl daemon-reload
systemctl enable $container_name.service
EOF
estep "Installation du service"
local_run "$HOST" "$tmpscript"
}
function default_compose_stop() {
${FAKE:+qvals} docker-compose \
"${replace_env_args[@]}" "${env_args[@]}" \
@ -443,6 +545,126 @@ function auto_down() {
fi
}
function default_compose_exec() {
${FAKE:+qvals} docker-compose \
"${replace_env_args[@]}" "${env_args[@]}" \
exec "${replace_exec_args[@]}" "${exec_args[@]}" \
"$@"
}
function default_docker_exec() {
${FAKE:+qvals} docker container exec \
"${replace_exec_args[@]}" "${exec_args[@]}" \
"$container_name" "$@"
}
function compose_exec() { default_compose_exec "$@"; }
function docker_exec() { default_docker_exec "$@"; }
function auto_exec() {
local -a replace_env_args env_args
local -a replace_exec_args exec_args
local project_name container_name
if [ -f docker-compose.yml ]; then
compose_set_env_args
compose_exec "$@"
else
docker_set_env_args
docker_check_name set_container_name
docker_exec "$@"
fi
}
function default_compose_service() {
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"
fi
fi
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 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
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" <<EOF
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
cat >/etc/systemd/system/$container_name.service <<EOD
[Unit]
Description=$project_name stack ($PROFILE)
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=$(pwd)
Environment=$(qval "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME")
ExecStart=$startcmd
ExecStop=$stopcmd
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target
EOD
systemctl daemon-reload
systemctl enable $container_name.service
EOF
estep "Installation du service"
local_run "$HOST" "$tmpscript"
}
DEFAULT_PROFILE=devel
PROFILE=
DM_PROFILES=()
@ -464,6 +686,9 @@ chdir=
FAKE=
NO_CACHE=
HOST=
update_apps_mode=ub
update_apps_origin=
update_apps_branch=
args=(
--help '$exit_with display_help'
-d:,--chdir: chdir=
@ -473,6 +698,10 @@ args=(
-n,--fake FAKE=1
-j,--no-cache NO_CACHE=1
-h:,--host: HOST=
-g,--ug,--no-update-apps update_apps_mode=b
-u,--uu,--update-apps-only update_apps_mode=u
--uo:,--update-apps-origin: update_apps_origin=
--ub:,--update-apps-branch: update_apps_branch=
)
parse_args "$@"; set -- "${args[@]}"
@ -487,6 +716,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"
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
[ -f build.scripts.sh ] && source ./build.scripts.sh
args=()
@ -514,17 +744,13 @@ while [ $# -gt 0 ]; do
enote "Profil $PROFILE"
auto_up "${args[@]}" || die
;;
service)
k|stop)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_service "${args[@]}" || die
;;
k|stop)
enote "Profil $PROFILE"
auto_stop || die
auto_stop "${args[@]}" || die
;;
1|up)
args=()
@ -534,8 +760,22 @@ while [ $# -gt 0 ]; do
enote "Profil $PROFILE"
auto_up "${args[@]}" && auto_logs || die
;;
l|logs) auto_logs || die;;
0|down) auto_down || die;;
l|logs)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_logs "${args[@]}" || die
;;
0|down)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_down "${args[@]}" || die
;;
d|brd)
do_auto_down=1
function auto_down_trap() {
@ -543,6 +783,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"
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
[ -f build.scripts.sh ] && source ./build.scripts.sh
args=()
@ -556,6 +797,33 @@ while [ $# -gt 0 ]; do
do_auto_down=
fi
;;
bs)
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=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_build && auto_up "${args[@]}"
;;
x|exec)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_exec "${args[@]}" || die
;;
service)
args=()
while [ $# -gt 0 -a "$1" != -- ]; do
args+=("$1"); shift
done
enote "Profil $PROFILE"
auto_service "${args[@]}" || die
;;
ps) docker container ps -a || die;;
ls) docker image ls || die;;
rm)

1
sqlcsv
View File

@ -568,6 +568,7 @@ public class sqlcsv {
}
static final String[] SUPPORTED_DRIVERS = new String[] {
"org.mariadb.jdbc.Driver",
"com.mysql.jdbc.Driver",
"oracle.jdbc.OracleDriver",
"org.hsqldb.jdbcDriver",

12
sqlmig
View File

@ -1034,6 +1034,16 @@ drop database if exists @@database@@;"
create database @@database@@;"
fi
if [ ! -f "$dbdir/02grants.sql" ]; then
estep "02grants.sql"
echo >"$dbdir/02grants.sql" "\
-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
-- @sqlmig admin
create user '$dbname' identified by '$dbname';
grant all privileges on $dbname.* to '$dbname';"
fi
if [ ! -f "$dbdir/my.cnf" ]; then
estep "my.cnf"
echo >"$dbdir/my.cnf" "\
@ -1078,7 +1088,7 @@ drop user $dbname cascade;"
-- -*- coding: utf-8 mode: sql -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
-- @sqlmig create
create user $dbname identified by \"password\";
create user $dbname identified by \"$dbname\";
grant connect to $dbname;
grant resource to $dbname;"
fi