2018-09-27 21:00:45 +04:00
|
|
|
#!/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
|
2019-09-18 10:57:12 +04:00
|
|
|
urequire pff
|
2018-09-27 21:00:45 +04:00
|
|
|
|
|
|
|
function display_help() {
|
|
|
|
uecho "$scriptname: outil pour faciliter l'utilisation de docker
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$scriptname CMDs...
|
|
|
|
|
|
|
|
COMMANDES
|
2019-11-21 08:55:09 +04:00
|
|
|
get-profile
|
|
|
|
Afficher le profil courant
|
2019-06-01 14:34:20 +04:00
|
|
|
b|build [SERVICE]
|
2019-03-28 10:53:50 +04:00
|
|
|
Construire les images
|
2019-06-01 14:34:20 +04:00
|
|
|
p|push
|
|
|
|
p|push [SERVICES...]
|
2019-05-31 17:14:59 +04:00
|
|
|
La première syntaxe est utilisable avec un projet docker. Elle permet de
|
|
|
|
pousser l'image qui a été construite avec build vers le serveur
|
|
|
|
La deuxième syntaxe est utilisée avec un projet docker-compose. Elle
|
|
|
|
permet de pousser les images correspondant aux services qui ont été
|
|
|
|
construit vers le serveur.
|
2019-06-24 23:57:02 +04:00
|
|
|
s|start [SERVICE]
|
2019-03-28 10:53:50 +04:00
|
|
|
Démarrer le(s) service(s)
|
2019-06-01 14:34:20 +04:00
|
|
|
k|stop [SERVICE]
|
2019-03-28 10:53:50 +04:00
|
|
|
Arrêter le(s) service(s)
|
2019-06-01 14:34:20 +04:00
|
|
|
1|up
|
2019-03-28 10:53:50 +04:00
|
|
|
Créer l'environnement, démarrer les services et suivre les logs de façon
|
|
|
|
interactive.
|
2019-06-01 14:34:20 +04:00
|
|
|
Vaguement équivalent à -- start -- logs
|
|
|
|
l|logs [SERVICE]
|
2019-03-28 10:53:50 +04:00
|
|
|
Afficher les logs
|
2019-06-01 14:34:20 +04:00
|
|
|
0|down
|
2019-03-28 10:53:50 +04:00
|
|
|
Arrêter les services et supprimer l'environnement
|
2019-06-24 23:57:02 +04:00
|
|
|
r|run SERVICE [COMMAND]
|
|
|
|
Démarrer le service en mode interactif avec la commande spécifiée
|
2019-06-25 11:02:52 +04:00
|
|
|
Les options suivantes sont supportées, mais il faut les spécifier avant
|
|
|
|
SERVICE:
|
|
|
|
* pour docker et docker-compose: --volume
|
|
|
|
* uniquement pour docker-compose: --detach, -e, --label, --no-deps,
|
|
|
|
--service-ports, --use-aliases
|
|
|
|
Par défaut, --rm est activé; utiliser --no-rm pour ne pas supprimer le
|
|
|
|
container après utilisation.
|
2019-06-24 23:57:02 +04:00
|
|
|
x|exec SERVICE COMMAND
|
|
|
|
Lancer une commande dans le container correspondant au service spécifié,
|
|
|
|
qui doit être en fonctionnement
|
2019-06-01 14:34:20 +04:00
|
|
|
d|brd
|
2019-03-28 10:53:50 +04:00
|
|
|
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)
|
2019-06-01 14:34:20 +04:00
|
|
|
Vaguement équivalent à -- build -- start [args] -- logs
|
|
|
|
suivi de -- down
|
2018-12-09 22:33:07 +04:00
|
|
|
bs
|
2019-03-28 10:53:50 +04:00
|
|
|
Construire les images (comme avec build) puis démarrer les services
|
|
|
|
(comme avec start)
|
2019-06-01 14:34:20 +04:00
|
|
|
Equivalent à -- build -- start [args]
|
2019-06-24 23:57:02 +04:00
|
|
|
br SERVICE [COMMAND]
|
|
|
|
Construire les images (comme avec build) puis démarrer le service avec
|
|
|
|
la commande spécifiée (comme avec run)
|
|
|
|
Equivalent à -- build -- run [args]
|
2019-06-05 10:13:20 +04:00
|
|
|
y|deploy [args...]
|
|
|
|
(Re)déployer un stack. Cette commande ne fonctionne qu'en mode swarm.
|
|
|
|
Implique --stack
|
|
|
|
by|bd [args...]
|
|
|
|
Equivalent à --stack -- build -- deploy args...
|
2019-06-01 14:34:20 +04:00
|
|
|
Utilisable notamment en développement
|
2019-06-05 10:13:20 +04:00
|
|
|
bp [args...]
|
|
|
|
Equivalent à --stack -- build -- push args...
|
|
|
|
bpy|bpd [args...]
|
|
|
|
Equivalent à --stack -- build -- push -- deploy args...
|
|
|
|
service COMMAND SERVICE [args...]
|
|
|
|
Frontend pour 'docker service COMMAND args... SERVICE'
|
|
|
|
Cette commande ne fonctionne qu'en mode swarm. Il n'est pas nécessaire
|
|
|
|
de préfixer le nom du service avec le nom du stack, pour être cohérent
|
|
|
|
avec les autres commandes
|
|
|
|
IMPORTANT: notez que les arguments sont placés avant le nom du service.
|
|
|
|
Celà signifie qu'on ne peut spécifier que des options à la commande.
|
|
|
|
Penser aussi à protéger ces options de l'analyse eg.
|
|
|
|
$scriptname -- service logs web -f
|
|
|
|
Pour des cas d'utilisation plus complexe, il faut lancer directement
|
|
|
|
docker service
|
|
|
|
u|update SERVICE [args...]
|
|
|
|
Mettre à jour un service, équivalent à 'service update SERVICE'
|
|
|
|
scale SERVICE=REPLICAS [args...]
|
|
|
|
Mettre à jour le nom de réplicas d'un service, équivalent à la commande
|
|
|
|
'service scale SERVICE=REPLICAS'
|
2019-06-01 14:34:20 +04:00
|
|
|
ip|show-ip [SERVICE]
|
2019-04-17 02:31:09 +04:00
|
|
|
Afficher l'adresse IP interne du service
|
2019-06-01 14:34:20 +04:00
|
|
|
systemd|systemd-unit
|
2019-04-10 07:25:20 +04:00
|
|
|
Générer une unité systemd qui démarre les services. A priori, ce n'est
|
|
|
|
nécessaire que si aucune politique de redémarrage n'a été définie.
|
2019-09-18 00:13:22 +04:00
|
|
|
ps [filter|name=value]
|
2019-03-28 10:53:50 +04:00
|
|
|
Afficher les containers en cours d'exécution
|
2019-09-18 00:13:22 +04:00
|
|
|
Le filtre est une expression régulière de type awk qui est mise en
|
|
|
|
correspondace avec les noms de l'image et de la tâche.
|
|
|
|
Il est aussi possible d'utiliser un filtre docker de la forme name=value
|
|
|
|
- ancestor=(<image-name>[:tag]|<image-id>| <image@digest>)
|
|
|
|
containers created from an image or a descendant.
|
|
|
|
- before=(<container-name>|<container-id>)
|
|
|
|
- expose=(<port>[/<proto>]|<startport-endport>/[<proto>])
|
|
|
|
- exited=<int> an exit code of <int>
|
|
|
|
- health=(starting|healthy|unhealthy|none)
|
|
|
|
- id=<ID> a container's ID
|
|
|
|
- is-task=(true|false)
|
|
|
|
- label=<key> or label=<key>=<value>
|
|
|
|
- name=<string> a container's name
|
|
|
|
- network=(<network-id>|<network-name>)
|
|
|
|
- publish=(<port>[/<proto>]|<startport-endport>/[<proto>])
|
|
|
|
- since=(<container-name>|<container-id>)
|
|
|
|
- status=(created|restarting|removing|running|paused|exited)
|
|
|
|
- volume=(<volume name>|<mount point destination>)
|
|
|
|
ls [filter|name=value]
|
2019-03-28 10:53:50 +04:00
|
|
|
Lister les images actuellement présentes
|
2019-09-18 00:13:22 +04:00
|
|
|
Le filtre est une expression régulière de type awk qui est mise en
|
|
|
|
correspondance avec le nom de l'image. Un suffixe :tag permet de ne
|
|
|
|
sélectionner que les images correspondant au filtre qui ont le tag
|
|
|
|
spécifié.
|
|
|
|
Il est aussi possible d'utiliser un filtre docker de la forme name=value
|
|
|
|
- dangling=(true|false) - find unused images
|
|
|
|
- label=<key> or label=<key>=<value>
|
|
|
|
- before=(<image-name>[:tag]|<image-id>| <image@digest>)
|
|
|
|
- since=(<image-name>[:tag]|<image-id>| <image@digest>)
|
|
|
|
- reference=(pattern of an image reference)
|
|
|
|
pull filter
|
|
|
|
Mettre à jour une ou plusieurs images
|
|
|
|
Le filtre est une expression régulière de type awk qui est mise en
|
|
|
|
correspondance avec le nom de l'image. Un suffixe :tag permet de ne
|
|
|
|
sélectionner que les images correspondant au filtre qui ont le tag
|
|
|
|
spécifié.
|
|
|
|
rm filter
|
|
|
|
Supprimer une ou plusieurs images
|
|
|
|
Le filtre est une expression régulière de type awk qui est mise en
|
|
|
|
correspondance avec le nom de l'image. Un suffixe :tag permet de ne
|
|
|
|
sélectionner que les images correspondant au filtre qui ont le tag
|
|
|
|
spécifié.
|
2019-06-01 14:34:20 +04:00
|
|
|
X|prune
|
2019-03-28 10:53:50 +04:00
|
|
|
Supprimer les containers et les images inutilisées
|
2018-11-19 09:56:04 +04:00
|
|
|
|
2019-10-02 22:16:40 +04:00
|
|
|
composer|ci|cu|cs [args...]
|
|
|
|
Frontend pour lancer composer à l'intérieur d'un container. Les
|
|
|
|
commandes 'ci', 'cu' et 'cs' sont respectivement des alias pour
|
|
|
|
'composer install', 'composer update' et 'composer shell'
|
2019-10-03 15:58:07 +04:00
|
|
|
S'il existe un fichier .composer.conf dans le répertoire du projet, il
|
|
|
|
est sourcé. Ce fichier définit des variables qui indiquent comment la
|
|
|
|
commande composer est lancée. Les variables suivantes peuvent être
|
|
|
|
définies:
|
2019-10-03 18:56:33 +04:00
|
|
|
* COMPOSER_IMAGE -- Image utilisée pour lancer composer. La valeur par
|
|
|
|
défaut est:
|
|
|
|
$DEFAULT_COMPOSER_IMAGE
|
|
|
|
Spécifier 'none' pour lancer directement composer sans passer par une
|
|
|
|
image docker.
|
2019-10-03 15:58:07 +04:00
|
|
|
L'image spécifiée doit disposer de la commande 'su-exec' afin de
|
|
|
|
pouvoir lancer la commande avec l'utilisateur courant. Le répertoire
|
|
|
|
\$HOME est monté à l'intérieur du container et le script composer.phar
|
|
|
|
du projet est utilisé le cas échéant.
|
2019-10-03 18:56:33 +04:00
|
|
|
* COMPOSER_MACHINE -- Nom de la docker machine sur laquelle se connecter
|
|
|
|
pour lancer l'image docker. La valeur par défaut est -u, ce qui force
|
|
|
|
l'utilisation de l'instance docker locale.
|
2019-10-03 15:58:07 +04:00
|
|
|
* COMPOSER_CMD -- Chemin vers l'exécutable composer. Par défaut,
|
|
|
|
utiliser composer.phar s'il existe dans le répertoire du projet. Sinon
|
|
|
|
utiliser /usr/bin/composer
|
|
|
|
* COMPOSER_SETUP -- Liste de commandes à lancer pour configurer le
|
|
|
|
container. Dans ce cas, un container ayant pour base \$COMPOSER_IMAGE
|
|
|
|
et nommé d'après le nom du projet est préparé et les commandes
|
|
|
|
spécifiées y sont lancées. Ce container est réutilisé à chaque fois.
|
|
|
|
Ce paramétrage est utilisé pour par exemple installer certains
|
|
|
|
packages nécessaire au projet.
|
|
|
|
La commande 'shell' est une extension qui lance un shell bash au lieu de
|
2019-10-02 22:16:40 +04:00
|
|
|
lancer la commande composer, ce qui permet de faire des opérations plus
|
2019-10-02 22:20:48 +04:00
|
|
|
complexes si le besoin s'en fait sentir. NB: le shell est lancé avec
|
2019-10-03 15:58:07 +04:00
|
|
|
l'utilisateur root. La commande alternative 'ushell' lance le shell avec
|
|
|
|
le compte utilisateur.
|
|
|
|
Pour faciliter l'utilisation dans un script, les premiers arguments
|
|
|
|
peuvent être utilisés pour redéfinir les variables COMPOSER_*, e.g
|
|
|
|
$scriptname composer COMPOSER_IMAGE=none install
|
2019-10-02 22:04:10 +04:00
|
|
|
|
2019-04-02 15:59:47 +04:00
|
|
|
OPTIONS générales
|
|
|
|
(ces options sont communes à toutes les commandes)
|
2018-11-19 09:56:04 +04:00
|
|
|
-d, --chdir PROJDIR
|
2019-05-31 17:14:59 +04:00
|
|
|
Spécifier le répertoire du projet
|
2019-06-11 08:18:43 +04:00
|
|
|
-c, --config CONFIG[.yml]
|
2019-06-11 08:06:29 +04:00
|
|
|
Spécifier le fichier de configuration à utiliser. le fichier de profil
|
2019-06-11 08:18:43 +04:00
|
|
|
CONFIG.PROFILE.yml est chargé aussi s'il existe.
|
|
|
|
NB: il n'est pas nécessaire d'ajouter l'extension .yml au nom, cela
|
|
|
|
permet de faciliter l'utilisation avec l'auto-complétion quand il existe
|
|
|
|
des fichiers de profil
|
2019-06-11 08:06:29 +04:00
|
|
|
Si cette option n'est pas spécifiée, docker-compose.yml est utilisé par
|
|
|
|
défaut (ou avec l'option --stack docker-stack.yml s'il existe)
|
2018-11-19 09:56:04 +04:00
|
|
|
-p, --profile PROFILE
|
|
|
|
-P, --prod
|
|
|
|
-T, --test
|
2019-05-31 17:14:59 +04:00
|
|
|
Spécifier le profil
|
|
|
|
-m, --set-machine MACHINE
|
|
|
|
Choisir l'environnement docker-machine spécifié avant de lancer les
|
2019-10-02 22:04:10 +04:00
|
|
|
commandes. Utiliser -u pour desélectionner la machine en cours, e.g -m-u
|
2018-11-22 15:34:07 +04:00
|
|
|
-n, --fake
|
2019-05-31 17:14:59 +04:00
|
|
|
Ne pas lancer les commandes, simplement les afficher
|
2019-11-07 12:09:39 +04:00
|
|
|
-f, --force
|
|
|
|
Forcer l'opération (là où cela a du sens)
|
2019-04-02 15:59:47 +04:00
|
|
|
-h, --host HOST
|
2019-05-31 17:14:59 +04:00
|
|
|
Spécifier l'hôte pour la commande systemd-unit
|
2019-04-02 15:59:47 +04:00
|
|
|
|
|
|
|
OPTIONS build
|
2019-06-01 14:34:20 +04:00
|
|
|
(ces options ne sont valides que pour les commandes build, brd, bs, bd, bpd)
|
|
|
|
--stack
|
|
|
|
Indiquer que le build est fait pour un déploiement avec deploy.
|
2019-06-05 10:13:20 +04:00
|
|
|
S'il existe un fichier docker-stack.yml, il est utilisé de préférence à
|
|
|
|
la place de docker-compose.yml. De même, les fichiers de profil de la
|
|
|
|
forme docker-stack.PROFILE.yml sont utilisés de préférence aux fichiers
|
|
|
|
docker-compose.PROFILE.yml
|
|
|
|
Cette option n'est nécessaire qu'avec build puisque les commandes
|
|
|
|
deploy, bd, bpd et update impliquent --stack
|
2019-05-31 17:14:59 +04:00
|
|
|
-j, --no-cache
|
|
|
|
Ne pas utiliser le cache lors du build
|
2019-04-02 15:59:47 +04:00
|
|
|
-g, --ug, --no-update-apps
|
2019-05-02 13:39:24 +04:00
|
|
|
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:
|
2019-10-03 15:58:07 +04:00
|
|
|
DEFAULT_DEVEL_SRCDIR=
|
2019-06-20 14:58:00 +04:00
|
|
|
DEFAULT_ORIGIN=
|
2019-04-02 15:59:47 +04:00
|
|
|
DEFAULT_BRANCH=
|
2019-10-03 15:58:07 +04:00
|
|
|
DEFAULT_COMPOSER_ACTION=
|
|
|
|
APPS=() # liste d'applications à mettre à jour
|
|
|
|
app_URL= # url du dépôt
|
|
|
|
app_DEVEL_SRCDIR= # répertoire source en mode devel
|
|
|
|
app_DEST= # répertoire dans lequel faire le checkout
|
|
|
|
app_PROFILE_ORIGIN= # origine spécifique au profil 'PROFILE'
|
|
|
|
app_ORIGIN= # ou... origine par défaut de la branche
|
|
|
|
app_PROFILE_BRANCH= # branche spécifique au profil 'PROFILE'
|
|
|
|
app_BRANCH= # ou... branche par défaut
|
|
|
|
app_TYPE= # type de projet (composer|none)
|
|
|
|
app_AFTER_UPDATE=() # liste de commandes à lancer après le checkout
|
|
|
|
app_COMPOSER_ACTION= # action projet composer (install|update|none)
|
2019-04-02 15:59:47 +04:00
|
|
|
-u, --uu, --update-apps-only
|
|
|
|
Ne faire que la mise à jour depuis les dépôts dépendants.
|
2019-06-20 14:58:00 +04:00
|
|
|
-w, --ww, --update-apps-devel
|
|
|
|
Faire la mise à jour en mode devel: le projet ainsi que ses fichiers des
|
|
|
|
répertoires vendor/lib et vendor/ur sont synchronisés via rsync depuis
|
|
|
|
\$DEFAULT_DEVEL_SRCDIR qui vaut par défaut \$HOME/wop/php
|
2019-04-02 15:59:47 +04:00
|
|
|
--uo, --update-apps-origin ORIGIN
|
|
|
|
Spécifier l'origine par défaut pour update-apps
|
|
|
|
--ub, --update-apps-branch BRANCH
|
2019-05-02 13:39:24 +04:00
|
|
|
Spécifier la branche par défaut pour update-apps
|
|
|
|
|
2019-06-01 14:34:20 +04:00
|
|
|
OPTIONS deploy
|
|
|
|
-l, --without-registry-auth
|
|
|
|
Ne pas transporter les informations d'autorisation aux agents swarm
|
|
|
|
(c'est à dire ne pas utiliser l'option --with-registry-auth)
|
|
|
|
|
2019-05-02 13:39:24 +04:00
|
|
|
VARIABLES de update-apps.conf
|
2019-06-20 14:58:00 +04:00
|
|
|
DEVEL_SRCDIR
|
|
|
|
répertoire source pour le mode devel. attention, il s'agit du répertoire
|
|
|
|
du projet, alors que DEFAULT_DEVEL_SRCDIR est le répertoire de base par
|
|
|
|
défaut des projets
|
2019-05-02 13:46:08 +04:00
|
|
|
ORIGIN
|
|
|
|
vaut 'origin' par défaut
|
|
|
|
BRANCH
|
|
|
|
vaut 'develop' par défaut
|
|
|
|
TYPE
|
|
|
|
vaut 'composer' par défaut si le fichier composer.json existe à la
|
2019-10-03 15:58:07 +04:00
|
|
|
racine du projet. sinon vaut 'none' par défaut
|
2019-05-02 13:39:24 +04:00
|
|
|
AFTER_UPDATE
|
|
|
|
Cette variable est une liste de commandes à lancer après la maj du dépôt
|
|
|
|
- si le chemin est absolu ou relatif, lancer la commande telle quelle
|
|
|
|
- s'il n'y a pas de chemin, alors ce doit être le nom d'une fonction
|
|
|
|
existante auquel on enlève le préfixe update_apps_func_
|
2019-09-18 10:57:12 +04:00
|
|
|
Au moment où la commande est lancée, le répertoire courant est celui du
|
|
|
|
projet. Les variables suivantes sont disponibles:
|
2019-10-03 15:58:07 +04:00
|
|
|
URL= # url du dépôt
|
|
|
|
DEVEL_SRCDIR= # répertoire source en mode devel
|
|
|
|
DEST= # répertoire dans lequel faire le checkout
|
|
|
|
ORIGIN= # origine de la branche
|
|
|
|
BRANCH= # branche sélectionnée dans le dépôt
|
|
|
|
TYPE= # type de projet (composer|none)
|
2019-08-26 16:12:53 +04:00
|
|
|
COMPOSER_ACTION
|
|
|
|
vaut 'install' par défaut. Indique ce qu'il faut faire pour un projet de
|
|
|
|
type 'composer' après avoir lancé les commandes de AFTER_UPDATE. Les
|
|
|
|
directives supporées sont 'install', 'update' et 'none'
|
|
|
|
|
2019-05-02 13:39:24 +04:00
|
|
|
FONCTIONS de update-apps.conf
|
2019-08-26 16:12:53 +04:00
|
|
|
sqlmig [DESTDIR [SRCDIR [NOFIX]]]
|
2019-05-02 13:39:24 +04:00
|
|
|
Copier les définitions des bases de données au format sqlmig de
|
2019-08-26 16:12:53 +04:00
|
|
|
SRCDIR/config/sqlmig vers DESTDIR/config/mariadb/sqlmig
|
|
|
|
Si SRCDIR ne se termine pas par '/config/sqlmig' ou si DESTDIR ne se
|
|
|
|
termine pas par '/config/mariadb/sqlmig', rajouter ces suffixes
|
2019-09-18 10:57:12 +04:00
|
|
|
automatiquement, sauf si une valeur NOFIX est spécifiée.
|
|
|
|
pff [MAPS [PFFDIR]]
|
|
|
|
Si PFFDIR est un projet pff, mettre à jour le profil pff en fonction du
|
|
|
|
profil de déploiement.
|
|
|
|
MAPS détermine le mapping entre profil de déploiement (prod, test,
|
|
|
|
devel) et le profil pff. Il s'agit d'une liste de valeurs séparées par
|
|
|
|
des virgules de la forme DEST[:SRC]
|
|
|
|
- Une valeur de la forme 'DEST:SRC' fait correspondre le profil de
|
|
|
|
déploiement SRC au profil pff 'DEST'
|
|
|
|
- Une valeur de la forme 'DEST' force le choix du profil pff DEST quel
|
|
|
|
que soit le profil de déploiement
|
2019-10-03 15:58:07 +04:00
|
|
|
Si aucun profil de déploiement ne correspond, le comportement par défaut
|
|
|
|
est de forcer le premier profil défini dans le projet pff"
|
2018-09-27 21:00:45 +04:00
|
|
|
}
|
|
|
|
|
2019-09-18 00:13:22 +04:00
|
|
|
function echo_lines() { local IFS=$'\n'; echo "$*"; }
|
|
|
|
|
2018-09-27 21:00:45 +04:00
|
|
|
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 '^$' |
|
2019-11-05 01:14:07 +04:00
|
|
|
sed -r 's/([^=]+)=(.*)/\1=\2; replace_build_args+=(--build-arg \1="$\1")/'
|
2018-09-27 21:00:45 +04:00
|
|
|
}
|
|
|
|
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)"
|
2018-11-16 14:16:16 +04:00
|
|
|
[ -n "$PROFILE" -a -f ".build.$PROFILE.env" ] && eval "$(docker_parse_build_args ".build.$PROFILE.env")"
|
2018-09-27 21:00:45 +04:00
|
|
|
}
|
|
|
|
function docker_set_env_args() {
|
|
|
|
[ -f .build.env ] && source ./.build.env
|
|
|
|
[ -f build.env ] && source ./build.env
|
2018-11-16 14:16:16 +04:00
|
|
|
[ -n "$PROFILE" -a -f ".build.$PROFILE.env" ] && source "./.build.$PROFILE.env"
|
2018-09-27 21:00:45 +04:00
|
|
|
}
|
|
|
|
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"
|
2019-05-31 15:42:11 +04:00
|
|
|
|
2018-11-22 15:34:07 +04:00
|
|
|
if [ "$1" == set_container_name ]; then
|
|
|
|
project_name="$NAME"
|
|
|
|
container_name="${project_name//[^a-zA-Z0-9_-]/}"
|
|
|
|
[ -n "$PROFILE" ] && container_name="${container_name}_$PROFILE"
|
2018-09-27 21:00:45 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-01 14:34:20 +04:00
|
|
|
function compose_set_project_name() {
|
2019-06-05 18:23:07 +04:00
|
|
|
local PROJECT_NAME= PROJECT_NAME_REMOVE_SUFFIX=.service PROJECT_NAME_ADD_PROFILE=
|
2018-10-09 19:12:07 +04:00
|
|
|
[ -f .compose.env ] && source ./.compose.env
|
2019-05-31 15:42:11 +04:00
|
|
|
|
|
|
|
[ -n "$PROJECT_NAME" ] || PROJECT_NAME="$(basename -- "$(pwd)")"
|
|
|
|
PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}"
|
|
|
|
|
2018-11-16 14:16:16 +04:00
|
|
|
if [ -n "$PROFILE" ]; then
|
2019-05-31 15:42:11 +04:00
|
|
|
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME${PROJECT_NAME_ADD_PROFILE:+_${PROFILE}}"
|
|
|
|
else
|
|
|
|
[ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME"
|
2018-09-27 21:00:45 +04:00
|
|
|
fi
|
2019-05-31 15:42:11 +04:00
|
|
|
export COMPOSE_PROJECT_NAME
|
|
|
|
|
2018-11-22 15:34:07 +04:00
|
|
|
if [ "$1" == set_container_name ]; then
|
2019-05-31 15:42:11 +04:00
|
|
|
project_name="$PROJECT_NAME"
|
2018-11-22 15:34:07 +04:00
|
|
|
container_name="${project_name//[^a-zA-Z0-9_-]/}"
|
2019-05-31 15:42:11 +04:00
|
|
|
[ -n "$PROFILE" -a -n "$PROJECT_NAME_ADD_PROFILE" ] && container_name="${container_name}_$PROFILE"
|
2018-11-22 15:34:07 +04:00
|
|
|
fi
|
|
|
|
}
|
2019-06-01 14:34:20 +04:00
|
|
|
function compose_set_env_args() {
|
2019-06-11 08:06:29 +04:00
|
|
|
if [ -n "$CONFIG" ]; then
|
2019-06-11 08:18:43 +04:00
|
|
|
# autocomplétion friendly
|
|
|
|
[ ! -f "$CONFIG" -a -f "${CONFIG}yml" ] && CONFIG="${CONFIG}yml"
|
|
|
|
[ ! -f "$CONFIG" -a -f "$CONFIG.yml" ] && CONFIG="$CONFIG.yml"
|
|
|
|
##
|
2019-06-11 08:06:29 +04:00
|
|
|
replace_env_args+=(-f "$CONFIG")
|
|
|
|
if [ -n "$PROFILE" -a -f "${CONFIG%.yml}.$PROFILE.yml" ]; then
|
|
|
|
replace_env_args+=(-f "${CONFIG%.yml}.$PROFILE.yml")
|
|
|
|
fi
|
2019-06-01 14:34:20 +04:00
|
|
|
else
|
2019-06-11 08:06:29 +04:00
|
|
|
if [ -n "$USE_STACK" -a -f docker-stack.yml ]; then
|
|
|
|
replace_env_args+=(-f docker-stack.yml)
|
|
|
|
else
|
|
|
|
replace_env_args+=(-f docker-compose.yml)
|
|
|
|
fi
|
|
|
|
if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then
|
|
|
|
replace_env_args+=(-f docker-stack.override.yml)
|
|
|
|
elif [ -f docker-compose.override.yml ]; then
|
|
|
|
replace_env_args+=(-f docker-compose.override.yml)
|
|
|
|
fi
|
|
|
|
if [ -n "$PROFILE" ]; then
|
|
|
|
if [ -n "$USE_STACK" -a -f "docker-stack.$PROFILE.yml" ]; then
|
|
|
|
replace_env_args+=(-f "docker-stack.$PROFILE.yml")
|
|
|
|
elif [ -f "docker-compose.$PROFILE.yml" ]; then
|
|
|
|
replace_env_args+=(-f "docker-compose.$PROFILE.yml")
|
|
|
|
fi
|
2019-06-01 19:34:37 +04:00
|
|
|
fi
|
|
|
|
fi
|
2019-06-01 14:34:20 +04:00
|
|
|
|
|
|
|
compose_set_project_name "$@"
|
|
|
|
}
|
2019-06-05 10:13:20 +04:00
|
|
|
function docker_set_deploy_args() {
|
2019-06-11 08:06:29 +04:00
|
|
|
if [ -n "$CONFIG" ]; then
|
2019-06-11 08:18:43 +04:00
|
|
|
# autocomplétion friendly
|
|
|
|
[ ! -f "$CONFIG" -a -f "${CONFIG}yml" ] && CONFIG="${CONFIG}yml"
|
|
|
|
[ ! -f "$CONFIG" -a -f "$CONFIG.yml" ] && CONFIG="$CONFIG.yml"
|
|
|
|
##
|
2019-06-11 08:06:29 +04:00
|
|
|
replace_deploy_args+=(-c "$CONFIG")
|
|
|
|
if [ -n "$PROFILE" -a -f "${CONFIG%.yml}.$PROFILE.yml" ]; then
|
|
|
|
replace_deploy_args+=(-c "${CONFIG%.yml}.$PROFILE.yml")
|
|
|
|
fi
|
2019-06-01 14:34:20 +04:00
|
|
|
else
|
2019-06-11 08:06:29 +04:00
|
|
|
if [ -n "$USE_STACK" -a -f docker-stack.yml ]; then
|
|
|
|
replace_deploy_args+=(-c docker-stack.yml)
|
|
|
|
else
|
|
|
|
replace_deploy_args+=(-c docker-compose.yml)
|
|
|
|
fi
|
|
|
|
if [ -n "$USE_STACK" -a -f docker-stack.override.yml ]; then
|
|
|
|
replace_deploy_args+=(-c docker-stack.override.yml)
|
|
|
|
elif [ -f docker-compose.override.yml ]; then
|
|
|
|
replace_deploy_args+=(-c docker-compose.override.yml)
|
|
|
|
fi
|
|
|
|
if [ -n "$PROFILE" ]; then
|
|
|
|
if [ -n "$USE_STACK" -a -f "docker-stack.$PROFILE.yml" ]; then
|
|
|
|
replace_deploy_args+=(-c "docker-stack.$PROFILE.yml")
|
|
|
|
elif [ -f "docker-compose.$PROFILE.yml" ]; then
|
|
|
|
replace_deploy_args+=(-c "docker-compose.$PROFILE.yml")
|
|
|
|
fi
|
2019-06-01 19:34:37 +04:00
|
|
|
fi
|
2019-06-01 14:34:20 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
compose_set_project_name "$@"
|
|
|
|
}
|
2018-11-22 15:34:07 +04:00
|
|
|
|
|
|
|
function host_run() {
|
|
|
|
# lancer le script $2..@ sur l'hôte $1
|
2019-04-10 07:25:20 +04:00
|
|
|
# si $1 n'est pas défini ou est le nom de l'hôte local ou vaut 'localhost',
|
|
|
|
# lancer le script en local avec les droits root
|
2018-11-22 15:34:07 +04:00
|
|
|
# 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
|
2019-04-10 07:25:20 +04:00
|
|
|
if [ -n "$host" -a "$host" != localhost ]; then
|
2018-11-22 15:34:07 +04:00
|
|
|
if check_hostname "$host"; then
|
|
|
|
estep "Lancement de $script localement"
|
|
|
|
runscript_as_root "$script" "$@"
|
|
|
|
elif progexists docker-machine; then
|
2019-06-01 19:34:37 +04:00
|
|
|
if [ "${host%%.*}" == "$DOCKER_MACHINE_NAME" ]; then
|
2018-11-22 15:34:07 +04:00
|
|
|
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
|
2019-06-01 19:34:37 +04:00
|
|
|
ewarn "La machine active ($DOCKER_MACHINE_NAME) n'est pas la destination ($host)"
|
2018-11-22 15:34:07 +04:00
|
|
|
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" "$@"
|
2018-09-27 21:00:45 +04:00
|
|
|
}
|
|
|
|
|
2019-04-02 15:59:47 +04:00
|
|
|
BUILD_UPDATE_APPS=
|
|
|
|
BUILD_BUILD=
|
|
|
|
UPDATE_APPS_ORIGIN=
|
|
|
|
UPDATE_APPS_BRANCH=
|
|
|
|
function build_set_options() {
|
2019-06-20 14:58:00 +04:00
|
|
|
BUILD_BUILD=
|
|
|
|
BUILD_UPDATE_APPS=
|
|
|
|
BUILD_UPDATE_DEVEL=
|
|
|
|
[[ "$1" == *b* ]] && BUILD_BUILD=1
|
|
|
|
[[ "$1" == *u* ]] && BUILD_UPDATE_APPS=1
|
|
|
|
[[ "$1" == *w* ]] && BUILD_UPDATE_DEVEL=1
|
2019-04-02 15:59:47 +04:00
|
|
|
UPDATE_APPS_ORIGIN="$2"
|
|
|
|
UPDATE_APPS_BRANCH="$3"
|
|
|
|
}
|
|
|
|
|
|
|
|
function update_apps_func_sqlmig() {
|
2019-08-26 16:12:53 +04:00
|
|
|
local destdir="$1" srcdir="$2" nofix="$3"
|
2019-04-02 15:59:47 +04:00
|
|
|
[ -n "$destdir" ] || destdir=db
|
2019-09-18 10:57:12 +04:00
|
|
|
[ -n "$srcdir" ] || srcdir="$DEST"
|
2019-08-26 16:12:53 +04:00
|
|
|
|
|
|
|
if [ -z "$nofix" ]; then
|
|
|
|
[ "${destdir%/config/mariadb/sqlmig}" != "$destdir" ] || destdir="$destdir/config/mariadb/sqlmig"
|
|
|
|
[ "${srcdir%/config/sqlmig}" != "$srcdir" ] || srcdir="$srcdir/config/sqlmig"
|
|
|
|
fi
|
2019-04-02 15:59:47 +04:00
|
|
|
|
2019-05-30 22:43:23 +04:00
|
|
|
if [ ! -d "$srcdir" ]; then
|
|
|
|
eerror "$srcdir: répertoire introuvable"
|
|
|
|
return 1
|
|
|
|
fi
|
2019-04-02 15:59:47 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
function update_apps_func_pff() {
|
|
|
|
local maps="$1" pffdir="${2:-$DEST}"
|
|
|
|
[ -f "$pffdir/$PFF_CONF" ] || return 0
|
|
|
|
|
|
|
|
source "$pffdir/$PFF_CONF"
|
|
|
|
pff_autofix "$pffdir"
|
|
|
|
|
|
|
|
local map src dest
|
|
|
|
array_split maps "$maps" ,
|
|
|
|
for map in "${maps[@]}"; do
|
|
|
|
if [ -z "$map" ]; then
|
|
|
|
continue
|
|
|
|
elif [[ "$map" == *:* ]]; then
|
|
|
|
# mapping de profil
|
|
|
|
splitpair "$map" dest src
|
|
|
|
if [ "$src" == "$PROFILE" ]; then
|
|
|
|
if array_contains PROFILES "$dest"; then
|
|
|
|
estep "Sélection du profil pff $dest"
|
|
|
|
pff_select_profile "$dest" "$pffdir"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
eerror "$dest: profil invalide, il a été ignoré"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# forcer le profil
|
|
|
|
dest="$map"
|
|
|
|
if array_contains PROFILES "$dest"; then
|
|
|
|
estep "Sélection du profil pff $dest"
|
|
|
|
pff_select_profile "$dest" "$pffdir"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
eerror "$dest: profil invalide, il a été ignoré"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# sélectionner le premier profil
|
|
|
|
setx dest=pff_get_first_profile "$pffdir"
|
|
|
|
if [ -n "$dest" ]; then
|
|
|
|
estep "Sélection du profil pff $dest"
|
|
|
|
pff_select_profile "$dest" "$pffdir"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-02 15:59:47 +04:00
|
|
|
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
|
2019-06-20 14:58:00 +04:00
|
|
|
DEFAULT_DEVEL_SRCDIR="$HOME/wop/php"
|
2019-08-26 16:12:53 +04:00
|
|
|
DEFAULT_COMPOSER_ACTION=install
|
2019-04-02 15:59:47 +04:00
|
|
|
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"
|
2019-09-18 10:57:12 +04:00
|
|
|
local app var URL DEVEL_SRCDIR DEST ORIGIN BRANCH TYPE after_update after_updates composer_action
|
2019-04-02 15:59:47 +04:00
|
|
|
for app in "${APPS[@]}"; do
|
|
|
|
etitle "$app"
|
2019-05-30 22:43:23 +04:00
|
|
|
|
|
|
|
var="${app//-/_}"
|
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
URL="${var}_URL"; URL="${!URL}"
|
|
|
|
[ -n "$URL" ] || {
|
2019-05-02 13:39:24 +04:00
|
|
|
ewarn "$app: vous devez définir l'url"
|
|
|
|
eend; return 1
|
|
|
|
}
|
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
DEVEL_SRCDIR="${var}_DEVEL_SRCDIR"; DEVEL_SRCDIR="${!DEVEL_SRCDIR}"
|
|
|
|
[ -n "$DEVEL_SRCDIR" ] || DEVEL_SRCDIR="$DEFAULT_DEVEL_SRCDIR/${URL##*/}"
|
2019-06-20 14:58:00 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
DEST="${var}_DEST"; DEST="${!DEST}"
|
|
|
|
[ -n "$DEST" ] || DEST="$app/b"
|
|
|
|
mkdir -p "$DEST" || { eend; return 1; }
|
2019-05-02 13:39:24 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
ORIGIN="${var}_${PROFILE}_ORIGIN"; ORIGIN="${!ORIGIN}"
|
|
|
|
[ -n "$ORIGIN" ] || { ORIGIN="${var}_ORIGIN"; ORIGIN="${!ORIGIN}"; }
|
|
|
|
[ -n "$ORIGIN" ] || ORIGIN="$DEFAULT_ORIGIN"
|
2019-05-02 13:39:24 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
BRANCH="${var}_${PROFILE}_BRANCH"; BRANCH="${!BRANCH}"
|
|
|
|
[ -n "$BRANCH" ] || { BRANCH="${var}_BRANCH"; BRANCH="${!BRANCH}"; }
|
|
|
|
[ -n "$BRANCH" ] || BRANCH="$DEFAULT_BRANCH"
|
2019-05-02 13:39:24 +04:00
|
|
|
|
2019-06-20 15:10:42 +04:00
|
|
|
# calculer le type maintenant, on en a besoin pour le mode devel
|
2019-09-18 10:57:12 +04:00
|
|
|
TYPE="${var}_TYPE"; TYPE="${!TYPE}"
|
2019-06-20 15:10:42 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
DEST="$DEST/$app"
|
2019-06-20 14:58:00 +04:00
|
|
|
if [ -n "$BUILD_UPDATE_DEVEL" ]; then
|
|
|
|
# synchronisation en mode devel
|
|
|
|
local -a rsync_opts; rsync_opts=(-a --delete --exclude .git/ --delete-excluded)
|
2019-09-18 10:57:12 +04:00
|
|
|
estep "Synchro $DEVEL_SRCDIR --> $DEST"
|
|
|
|
rsync "${rsync_opts[@]}" "$DEVEL_SRCDIR/" "$DEST" || { eend; return 1; }
|
2019-06-20 15:10:42 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ -z "$TYPE" ]; then
|
2019-06-20 15:10:42 +04:00
|
|
|
# possible de détecter le type quand on a le projet
|
|
|
|
# en cas de maj ici, mettre à jour aussi le code ci-dessous
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ -f "$DEST/composer.json" ]; then TYPE=composer
|
2019-10-03 15:58:07 +04:00
|
|
|
else TYPE=none
|
2019-06-20 15:10:42 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ "$TYPE" == composer ]; then
|
2019-06-20 15:10:42 +04:00
|
|
|
# Synchronisation des dépendances
|
|
|
|
local -a depdirs; local depdir pname
|
2019-09-18 10:57:12 +04:00
|
|
|
setx -a depdirs=ls -d "$DEST/vendor/"{lib,ur}/* 2>/dev/null
|
2019-06-20 15:10:42 +04:00
|
|
|
for depdir in "${depdirs[@]}"; do
|
|
|
|
[ -L "$depdir" ] && rm "$depdir"
|
2019-09-18 10:57:12 +04:00
|
|
|
pname="${depdir#$DEST/vendor/}"; pname="${pname/\//-}"
|
2019-06-20 15:10:42 +04:00
|
|
|
estep "Synchro $DEFAULT_DEVEL_SRCDIR/$pname --> $depdir"
|
|
|
|
rsync "${rsync_opts[@]}" --exclude /vendor/ "$DEFAULT_DEVEL_SRCDIR/$pname/" "$depdir"
|
|
|
|
done
|
|
|
|
fi
|
2019-05-10 16:29:30 +04:00
|
|
|
else
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ -d "$DEST" -a -d "$DEST/.git" ]; then
|
2019-06-20 14:58:00 +04:00
|
|
|
# mise à jour
|
2019-09-18 10:57:12 +04:00
|
|
|
estep "Maj dépôt $URL:$BRANCH --> $DEST"
|
2019-06-20 14:58:00 +04:00
|
|
|
setx cwd=pwd
|
2019-09-18 10:57:12 +04:00
|
|
|
cd "$DEST"
|
2019-06-20 14:58:00 +04:00
|
|
|
git fetch --all -p -f || { eend; return 1; }
|
2019-09-18 10:57:12 +04:00
|
|
|
git reset --hard "$ORIGIN/$BRANCH" || { eend; return 1; }
|
2019-06-20 14:58:00 +04:00
|
|
|
cd "$cwd"
|
|
|
|
else
|
|
|
|
# reliquat mode devel?
|
2019-09-18 10:57:12 +04:00
|
|
|
[ -d "$DEST" ] && rm -rf "$DEST"
|
2019-06-20 14:58:00 +04:00
|
|
|
# clonage initial
|
2019-09-18 10:57:12 +04:00
|
|
|
estep "Clonage $URL:$BRANCH --> $DEST"
|
|
|
|
git clone -o "$ORIGIN" -b "$BRANCH" "$URL" "$DEST" || { eend; return 1; }
|
2019-06-20 14:58:00 +04:00
|
|
|
fi
|
2019-05-10 16:29:30 +04:00
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ -z "$TYPE" ]; then
|
2019-06-20 15:10:42 +04:00
|
|
|
# possible de détecter le type quand on a le projet
|
|
|
|
# en cas de maj ici, mettre à jour aussi le code ci-dessus
|
2019-09-18 10:57:12 +04:00
|
|
|
if [ -f "$DEST/composer.json" ]; then TYPE=composer
|
2019-10-03 15:58:07 +04:00
|
|
|
else TYPE=none
|
2019-06-20 15:10:42 +04:00
|
|
|
fi
|
2019-05-02 13:39:24 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-30 22:43:23 +04:00
|
|
|
after_updates="${var}_AFTER_UPDATE"
|
2019-04-02 15:59:47 +04:00
|
|
|
if is_defined "$after_updates"; then
|
2019-05-30 22:43:23 +04:00
|
|
|
after_updates="$after_updates[@]"; after_updates=("${!after_updates}")
|
2019-09-18 10:57:12 +04:00
|
|
|
elif [ "$TYPE" == composer ]; then
|
2019-04-02 15:59:47 +04:00
|
|
|
after_updates=(sqlmig)
|
2019-05-02 13:39:24 +04:00
|
|
|
else
|
|
|
|
after_updates=()
|
2019-04-02 15:59:47 +04:00
|
|
|
fi
|
|
|
|
|
2019-09-18 10:57:12 +04:00
|
|
|
estep "Type de dépôt: $TYPE"
|
|
|
|
if [ "$TYPE" == composer ]; then
|
2019-08-26 16:12:53 +04:00
|
|
|
composer_action="${var}_${PROFILE}_COMPOSER_ACTION"; composer_action="${!composer_action}"
|
|
|
|
[ -n "$composer_action" ] || { composer_action="${var}_COMPOSER_ACTION"; composer_action="${!composer_action}"; }
|
|
|
|
[ -n "$composer_action" ] || composer_action="$DEFAULT_COMPOSER_ACTION"
|
|
|
|
|
2019-06-20 14:58:00 +04:00
|
|
|
if [ -z "$BUILD_UPDATE_DEVEL" ]; then
|
2019-08-26 16:12:53 +04:00
|
|
|
case "${composer_action:-install}" in
|
|
|
|
i|install) composer_action=install;;
|
|
|
|
u|update) composer_action=update;;
|
|
|
|
none|nop) composer_action=;;
|
|
|
|
*) ewarn "$composer_action: action invalide"; composer_action=;;
|
|
|
|
esac
|
|
|
|
if [ -n "$composer_action" ]; then
|
2019-10-03 15:58:07 +04:00
|
|
|
setx cwd=pwd
|
|
|
|
cd "$DEST"
|
2019-08-26 16:12:53 +04:00
|
|
|
estep "Installation des dépendances composer"
|
2019-10-03 15:58:07 +04:00
|
|
|
auto_composer "$composer_action" ${PRODUCTION:+--no-dev -o} || { eend; return 1; }
|
|
|
|
cd "$cwd"
|
2019-08-26 16:12:53 +04:00
|
|
|
fi
|
2019-06-20 14:58:00 +04:00
|
|
|
fi
|
2019-04-02 15:59:47 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
for after_update in "${after_updates[@]}"; do
|
|
|
|
if [ "${after_update#/}" != "$after_update" ]; then
|
|
|
|
# commande absolue, la lancer telle quelle
|
2019-09-18 10:57:12 +04:00
|
|
|
etitle "$after_update"
|
|
|
|
eval "$after_update" || { eend; eend; return 1; }
|
|
|
|
eend
|
2019-04-02 15:59:47 +04:00
|
|
|
elif [ "${after_update#./}" != "$after_update" ]; then
|
|
|
|
# commande relative, la lancer telle quelle
|
2019-09-18 10:57:12 +04:00
|
|
|
etitle "$after_update"
|
|
|
|
eval "$after_update" || { eend; eend; return 1; }
|
|
|
|
eend
|
2019-04-02 15:59:47 +04:00
|
|
|
else
|
|
|
|
# c'est une fonction update_apps_func_*
|
2019-09-18 10:57:12 +04:00
|
|
|
etitle "$after_update"
|
|
|
|
eval "update_apps_func_$after_update" || { eend; eend; return 1; }
|
|
|
|
eend
|
2019-04-02 15:59:47 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
eend
|
|
|
|
done
|
|
|
|
eend
|
|
|
|
}
|
|
|
|
|
2018-10-08 11:50:56 +04:00
|
|
|
function initialize_build_env() {
|
|
|
|
CTXDIR=.
|
|
|
|
NAME=
|
|
|
|
TAGS=(latest)
|
|
|
|
VERSION=
|
2019-07-18 20:57:53 +04:00
|
|
|
DIST=
|
2018-10-08 11:50:56 +04:00
|
|
|
}
|
2018-10-09 10:02:57 +04:00
|
|
|
function default_update_build_env() {
|
2019-07-18 20:57:53 +04:00
|
|
|
if [ -n "$DIST" ]; then
|
|
|
|
[ -n "$VERSION" ] && VERSION="$VERSION-"
|
|
|
|
VERSION="$VERSION$DIST"
|
2019-07-18 22:51:43 +04:00
|
|
|
TAGS+=("$DIST")
|
2019-07-18 20:57:53 +04:00
|
|
|
fi
|
2018-10-09 10:02:57 +04:00
|
|
|
[ -n "$VERSION" ] || docker_add_build_arg VERSION "$(get_version)"
|
|
|
|
[ -n "$VERSION" ] && TAGS+=("$VERSION")
|
|
|
|
}
|
2018-10-08 11:50:56 +04:00
|
|
|
function update_build_env() { default_update_build_env; }
|
|
|
|
|
2018-09-27 21:00:45 +04:00
|
|
|
function default_compose_build() {
|
2018-11-19 09:56:04 +04:00
|
|
|
${FAKE:+qvals} docker-compose \
|
2018-09-27 21:00:45 +04:00
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
2018-11-16 21:22:05 +04:00
|
|
|
build \
|
|
|
|
${NO_CACHE:+--no-cache} \
|
|
|
|
"${replace_build_args[@]}" "${build_args[@]}" \
|
2018-09-27 21:00:45 +04:00
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function default_docker_build() {
|
2018-10-08 11:50:56 +04:00
|
|
|
local tag
|
|
|
|
for tag in "${TAGS[@]}"; do
|
|
|
|
replace_build_args+=(-t "$NAME:$tag")
|
|
|
|
done
|
2018-11-19 09:56:04 +04:00
|
|
|
${FAKE:+qvals} docker build \
|
2018-11-16 20:48:51 +04:00
|
|
|
${NO_CACHE:+--no-cache} \
|
2018-09-27 21:00:45 +04:00
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
"${replace_build_args[@]}" "${build_args[@]}" \
|
|
|
|
"$@" "$CTXDIR"
|
|
|
|
}
|
2019-04-02 15:59:47 +04:00
|
|
|
function compose_build() {
|
|
|
|
[ -n "$BUILD_BUILD" ] || return 0
|
|
|
|
default_compose_build "$@"
|
|
|
|
}
|
|
|
|
function docker_build() {
|
|
|
|
[ -n "$BUILD_BUILD" ] || return 0
|
|
|
|
default_docker_build "$@"
|
|
|
|
}
|
2018-09-27 21:00:45 +04:00
|
|
|
function auto_build() {
|
|
|
|
local -a replace_env_args env_args
|
|
|
|
local -a replace_build_args build_args
|
2018-10-08 11:50:56 +04:00
|
|
|
initialize_build_env
|
2018-09-27 21:00:45 +04:00
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
2018-10-08 11:50:56 +04:00
|
|
|
update_build_env
|
2019-04-02 15:59:47 +04:00
|
|
|
build_update_apps || return 1
|
2019-05-30 23:25:34 +04:00
|
|
|
compose_build "$@"
|
2018-09-27 21:00:45 +04:00
|
|
|
else
|
|
|
|
docker_parse_env_args
|
|
|
|
docker_check_name
|
|
|
|
docker_add_build_arg build_date "$(date +%y%m%d)"
|
2018-10-08 11:50:56 +04:00
|
|
|
update_build_env
|
2019-04-02 15:59:47 +04:00
|
|
|
build_update_apps || return 1
|
2019-05-30 23:25:34 +04:00
|
|
|
docker_build "$@"
|
2018-09-27 21:00:45 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-05-31 17:14:59 +04:00
|
|
|
function default_compose_push() {
|
|
|
|
${FAKE:+qvals} docker-compose \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
2019-06-01 14:34:20 +04:00
|
|
|
push \
|
2019-05-31 17:14:59 +04:00
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function default_docker_push() {
|
|
|
|
${FAKE:+qvals} docker push \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function compose_push() {
|
|
|
|
default_compose_push "$@"
|
|
|
|
}
|
|
|
|
function docker_push() {
|
|
|
|
local tag
|
|
|
|
for tag in "${TAGS[@]}"; do
|
|
|
|
default_docker_push "$NAME:$tag" "$@"
|
|
|
|
done
|
|
|
|
}
|
2018-10-08 11:50:56 +04:00
|
|
|
function auto_push() {
|
2018-10-09 10:02:57 +04:00
|
|
|
local -a replace_env_args env_args
|
|
|
|
local -a replace_build_args build_args
|
2018-10-08 11:50:56 +04:00
|
|
|
initialize_build_env
|
2018-10-09 10:02:57 +04:00
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
|
|
|
update_build_env
|
2019-05-31 17:14:59 +04:00
|
|
|
compose_push "$@"
|
2018-10-09 10:02:57 +04:00
|
|
|
else
|
|
|
|
docker_parse_env_args
|
|
|
|
docker_check_name
|
|
|
|
update_build_env
|
2019-05-31 17:14:59 +04:00
|
|
|
docker_push "$@"
|
2018-10-09 10:02:57 +04:00
|
|
|
fi
|
2018-10-08 11:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-09-27 21:00:45 +04:00
|
|
|
function default_compose_up() {
|
2018-11-19 09:56:04 +04:00
|
|
|
${FAKE:+qvals} docker-compose \
|
2018-09-27 21:00:45 +04:00
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
up "${replace_run_args[@]}" "${run_args[@]}" \
|
|
|
|
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
|
|
|
}
|
|
|
|
function default_docker_up() {
|
2018-11-19 09:56:04 +04:00
|
|
|
${FAKE:+qvals} docker run \
|
2018-09-27 21:00:45 +04:00
|
|
|
"${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
|
2018-11-22 15:34:07 +04:00
|
|
|
local project_name container_name
|
2018-09-27 21:00:45 +04:00
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
|
|
|
replace_run_args=(-d)
|
|
|
|
compose_up "$@"
|
|
|
|
else
|
|
|
|
docker_set_env_args
|
2018-11-22 15:34:07 +04:00
|
|
|
docker_check_name set_container_name
|
|
|
|
replace_run_args=(-d --name "$container_name")
|
2018-09-27 21:00:45 +04:00
|
|
|
docker_up "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-28 10:53:50 +04:00
|
|
|
function default_compose_stop() {
|
|
|
|
${FAKE:+qvals} docker-compose \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
stop "${replace_stop_args[@]}" "${stop_args[@]}" \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function default_docker_stop() {
|
|
|
|
${FAKE:+qvals} docker container stop \
|
|
|
|
"${replace_stop_args[@]}" "${stop_args[@]}" \
|
|
|
|
"$container_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
|
|
|
|
local project_name container_name
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
|
|
|
compose_stop "$@"
|
|
|
|
else
|
|
|
|
docker_set_env_args
|
|
|
|
docker_check_name set_container_name
|
|
|
|
docker_stop "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function default_compose_logs() {
|
|
|
|
${FAKE:+qvals} docker-compose \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
logs "${replace_logs_args[@]}" "${logs_args[@]}" \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function default_docker_logs() {
|
|
|
|
${FAKE:+qvals} docker logs \
|
|
|
|
"${replace_logs_args[@]}" "${logs_args[@]}" \
|
|
|
|
"$container_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
|
|
|
|
local project_name container_name
|
|
|
|
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_container_name
|
|
|
|
replace_logs_args=(-f)
|
|
|
|
docker_logs "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function default_compose_down() {
|
|
|
|
${FAKE:+qvals} docker-compose \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
down "${replace_down_args[@]}" "${down_args[@]}" \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
function default_docker_down() {
|
|
|
|
estep "stop"
|
|
|
|
${FAKE:+qvals} docker container stop \
|
|
|
|
"${replace_down_args[@]}" "${down_args[@]}" \
|
|
|
|
"$container_name" "$@"
|
|
|
|
estep "rm"
|
|
|
|
${FAKE:+qvals} docker container rm \
|
|
|
|
"${replace_rm_args[@]}" "${rm_args[@]}" \
|
|
|
|
"$container_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
|
|
|
|
local project_name container_name
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
|
|
|
compose_down "$@"
|
|
|
|
else
|
|
|
|
docker_set_env_args
|
|
|
|
docker_check_name set_container_name
|
|
|
|
docker_down "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-24 23:57:02 +04:00
|
|
|
function default_compose_run() {
|
|
|
|
${FAKE:+qvals} docker-compose \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
run "${replace_run_args[@]}" "${run_args[@]}" \
|
|
|
|
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
|
|
|
}
|
|
|
|
function default_docker_run() {
|
|
|
|
${FAKE:+qvals} docker run \
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}" \
|
|
|
|
"${replace_run_args[@]}" "${run_args[@]}" \
|
|
|
|
"$NAME" \
|
|
|
|
"${replace_user_args[@]}" "${user_args[@]}" "$@"
|
|
|
|
}
|
|
|
|
function compose_run() { default_compose_run "$@"; }
|
|
|
|
function docker_run() { default_docker_run "$@"; }
|
|
|
|
function auto_run() {
|
2019-06-25 11:02:52 +04:00
|
|
|
eval "$(utools_local parse_opts)"
|
|
|
|
local detach no_deps rm=1 service_ports use_aliases volume
|
|
|
|
local -a envs labels
|
|
|
|
args=(
|
|
|
|
+
|
|
|
|
-d,--detach detach=1
|
|
|
|
-e: '$add@ envs -e; add@ envs'
|
|
|
|
-l:,--label: '$add@ labels -l; add@ labels'
|
|
|
|
--no-deps no_deps=1
|
|
|
|
--no-rm rm=
|
|
|
|
--rm rm=1
|
|
|
|
--service-ports service_ports=1
|
|
|
|
--use-aliases use_aliases=1
|
|
|
|
-v:,--volume: volume=
|
|
|
|
@ args -- "$@"
|
|
|
|
)
|
|
|
|
parse_opts "${args[@]}" && set -- "${args[@]}" || { eerror "$args"; return 1; }
|
|
|
|
|
2019-06-24 23:57:02 +04:00
|
|
|
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
|
2019-06-25 11:02:52 +04:00
|
|
|
replace_run_args=(
|
|
|
|
${detach:+-d}
|
|
|
|
"${envs[@]}" "${labels[@]}"
|
|
|
|
${no_deps:+--no-deps}
|
|
|
|
${rm:+--rm}
|
|
|
|
${service_ports:+--service-ports}
|
|
|
|
${use_aliases:+--use-aliases}
|
|
|
|
${volume:+-v "$volume"}
|
|
|
|
)
|
2019-06-24 23:57:02 +04:00
|
|
|
compose_run "$@"
|
|
|
|
else
|
|
|
|
docker_set_env_args
|
|
|
|
docker_check_name set_container_name
|
2019-06-25 11:02:52 +04:00
|
|
|
replace_run_args=(
|
|
|
|
--name "$container_name"
|
|
|
|
${rm:+--rm}
|
|
|
|
${volume:+-v "$volume"}
|
|
|
|
)
|
2019-06-24 23:57:02 +04:00
|
|
|
docker_run "$@"
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-06-05 10:13:20 +04:00
|
|
|
function default_docker_deploy() {
|
2019-06-01 14:34:20 +04:00
|
|
|
${FAKE:+qvals} docker \
|
|
|
|
stack deploy \
|
|
|
|
"${replace_deploy_args[@]}" "${deploy_args[@]}" \
|
|
|
|
"$container_name" "$@"
|
|
|
|
}
|
2019-06-05 10:13:20 +04:00
|
|
|
function docker_deploy() { default_docker_deploy "$@"; }
|
2019-06-01 14:34:20 +04:00
|
|
|
function auto_deploy() {
|
|
|
|
local -a replace_env_args env_args
|
|
|
|
local -a replace_deploy_args deploy_args
|
|
|
|
local project_name container_name
|
|
|
|
if [ -f docker-compose.yml -o -f docker-stack.yml ]; then
|
2019-06-05 10:13:20 +04:00
|
|
|
docker_set_deploy_args set_container_name
|
2019-06-01 14:34:20 +04:00
|
|
|
[ -n "$WITH_REGISTRY_AUTH" ] && replace_deploy_args+=(--with-registry-auth)
|
2019-06-05 10:13:20 +04:00
|
|
|
docker_deploy "$@"
|
|
|
|
else
|
|
|
|
die "Impossible de trouver ni docker-compose.yml ni docker-stack.yml"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function default_docker_service() {
|
|
|
|
${FAKE:+qvals} docker service "$@"
|
|
|
|
}
|
|
|
|
function docker_service() { default_docker_service "$@"; }
|
|
|
|
function auto_service() {
|
|
|
|
if [ -f docker-compose.yml -o -f docker-stack.yml ]; then
|
|
|
|
local command="$1"; shift
|
|
|
|
[ -n "$command" ] || {
|
|
|
|
eerror "Vous devez spécifier la commande"
|
|
|
|
return 1
|
|
|
|
}
|
2019-06-29 12:17:07 +04:00
|
|
|
local -a command_args
|
|
|
|
[ "$command" == update -a -n "$WITH_REGISTRY_AUTH" ] && command_args+=(--with-registry-auth)
|
2019-06-05 10:13:20 +04:00
|
|
|
case "$command" in
|
|
|
|
ls) # ces commandes n'ont pas besoin du nom de service
|
|
|
|
docker_service "$command" "$@"
|
|
|
|
;;
|
|
|
|
*) # ces commandes ont besoin du nom du service
|
|
|
|
local service="$1"; shift
|
|
|
|
[ -n "$service" ] || {
|
|
|
|
eerror "Vous devez spécifier le nom du service"
|
|
|
|
return 1
|
|
|
|
}
|
2019-06-29 12:17:07 +04:00
|
|
|
local -a replace_env_args env_args
|
|
|
|
local -a replace_deploy_args deploy_args
|
|
|
|
local project_name container_name
|
2019-06-05 10:13:20 +04:00
|
|
|
docker_set_deploy_args set_container_name
|
|
|
|
service="${container_name}_${service#${container_name}_}"
|
2019-06-29 12:17:07 +04:00
|
|
|
docker_service "$command" "${command_args[@]}" "$@" "$service"
|
2019-06-05 10:13:20 +04:00
|
|
|
;;
|
|
|
|
esac
|
2019-06-01 14:34:20 +04:00
|
|
|
else
|
|
|
|
die "Impossible de trouver ni docker-compose.yml ni docker-stack.yml"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-17 02:31:09 +04:00
|
|
|
function default_compose_show_ip() {
|
|
|
|
local -a cmd cids; local cid
|
|
|
|
cmd=(
|
|
|
|
docker-compose
|
|
|
|
"${replace_env_args[@]}" "${env_args[@]}"
|
|
|
|
ps -q "${replace_show_ip_args[@]}" "${show_ip_args[@]}"
|
|
|
|
"$@"
|
|
|
|
)
|
|
|
|
if [ -n "$FAKE" ]; then
|
|
|
|
echo "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \"\$($(qvals "${cmd[@]}"))\""
|
|
|
|
else
|
|
|
|
setx -a cids="${cmd[@]}" 2>/dev/null
|
|
|
|
for cid in "${cids[@]}"; do
|
|
|
|
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$cid"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function default_docker_show_ip() {
|
|
|
|
${FAKE:+qvals} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
|
|
|
|
"${replace_show_ip_args[@]}" "${show_ip_args[@]}" \
|
|
|
|
"$container_name" "$@"
|
|
|
|
}
|
|
|
|
function compose_show_ip() { default_compose_show_ip "$@"; }
|
|
|
|
function docker_show_ip() { default_docker_show_ip "$@"; }
|
|
|
|
function auto_show_ip() {
|
|
|
|
local -a replace_env_args env_args
|
|
|
|
local -a replace_show_ip_args show_ip_args
|
|
|
|
local project_name container_name
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args
|
|
|
|
compose_show_ip "$@"
|
|
|
|
else
|
|
|
|
docker_set_env_args
|
|
|
|
docker_check_name set_container_name
|
|
|
|
docker_show_ip "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-10 07:25:20 +04:00
|
|
|
function default_compose_systemd_unit() {
|
2019-01-14 16:09:03 +04:00
|
|
|
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
|
2018-12-07 16:04:18 +04:00
|
|
|
fi
|
2018-11-22 15:34:07 +04:00
|
|
|
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
|
|
|
|
}
|
2019-04-10 07:25:20 +04:00
|
|
|
function default_docker_systemd_unit() {
|
2019-01-14 16:09:03 +04:00
|
|
|
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
|
2018-12-07 16:04:18 +04:00
|
|
|
fi
|
2018-11-22 15:34:07 +04:00
|
|
|
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"
|
|
|
|
}
|
2019-04-10 07:25:20 +04:00
|
|
|
function compose_systemd_unit() { default_compose_systemd_unit "$@"; }
|
|
|
|
function docker_systemd_unit() { default_docker_systemd_unit "$@"; }
|
|
|
|
function auto_systemd_unit() {
|
2018-11-22 15:34:07 +04:00
|
|
|
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
|
|
|
|
|
2019-04-10 07:25:20 +04:00
|
|
|
estep "Génération de l'unité systemd"
|
2018-11-22 15:34:07 +04:00
|
|
|
export COMPOSE_PROJECT_NAME=
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_env_args set_container_name
|
|
|
|
replace_run_args=(-d --no-color)
|
2019-04-10 07:25:20 +04:00
|
|
|
compose_systemd_unit "$@"
|
2018-11-22 15:34:07 +04:00
|
|
|
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")
|
2019-04-10 07:25:20 +04:00
|
|
|
docker_systemd_unit "$@"
|
2018-11-22 15:34:07 +04:00
|
|
|
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)
|
2018-12-01 23:04:28 +04:00
|
|
|
Requires=docker.service
|
|
|
|
After=docker.service
|
2018-11-22 15:34:07 +04:00
|
|
|
|
|
|
|
[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
|
|
|
|
|
2019-04-10 07:25:20 +04:00
|
|
|
estep "Installation de l'unité systemd"
|
2018-11-22 15:34:07 +04:00
|
|
|
local_run "$HOST" "$tmpscript"
|
|
|
|
}
|
|
|
|
|
2019-10-03 19:20:32 +04:00
|
|
|
function default_local_composer() {
|
|
|
|
# lancement direct
|
|
|
|
case "$1" in
|
|
|
|
rootshell|shell|rootbash|bash)
|
|
|
|
# ewarn parce qu'on est pas root dans ce shell contrairement à ce qui est demandé
|
|
|
|
ewarn "Lancement d'un shell utilisateur"
|
|
|
|
bash "$@"
|
|
|
|
;;
|
|
|
|
usershell|ushell|userbash|ubash)
|
|
|
|
estep "Lancement d'un shell utilisateur"
|
|
|
|
bash "$@"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$COMPOSER_CMD" ]; then :
|
|
|
|
elif [ -x composer.phar ]; then COMPOSER_CMD=./composer.phar
|
|
|
|
elif [ -x /usr/bin/composer ]; then COMPOSER_CMD=/usr/bin/composer
|
|
|
|
else
|
|
|
|
eerror "Impossible de trouver composer"
|
|
|
|
return 1
|
2019-10-03 19:12:38 +04:00
|
|
|
fi
|
2019-10-03 19:20:32 +04:00
|
|
|
"$COMPOSER_CMD" "$@"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
function default_docker_composer() {
|
|
|
|
# lancement dans un container
|
2019-10-03 15:58:07 +04:00
|
|
|
local user group projdir actualcmd args
|
2019-10-02 22:04:10 +04:00
|
|
|
setx user=id -un; setx user=getent passwd "$user"
|
|
|
|
setx group=id -gn; setx group=getent group "$group"
|
|
|
|
setx projdir=pwd
|
2019-10-02 22:16:40 +04:00
|
|
|
case "$1" in
|
2019-10-02 22:20:48 +04:00
|
|
|
rootshell|shell|rootbash|bash)
|
|
|
|
actualcmd='eval "bash $args"'
|
2019-10-03 15:58:07 +04:00
|
|
|
shift
|
2019-10-02 22:20:48 +04:00
|
|
|
;;
|
|
|
|
usershell|ushell|userbash|ubash)
|
2019-10-02 22:16:40 +04:00
|
|
|
actualcmd='eval "su-exec \"$user\" bash $args"'
|
2019-10-03 15:58:07 +04:00
|
|
|
shift
|
2019-10-02 22:16:40 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
actualcmd='eval "su-exec \"$user\" \"$composer\" $args"'
|
|
|
|
;;
|
|
|
|
esac
|
2019-10-02 22:04:10 +04:00
|
|
|
setx args=qvals "$@"
|
|
|
|
|
2019-10-03 15:58:07 +04:00
|
|
|
local -a basecmd cmd setupscript runscript
|
|
|
|
basecmd=(
|
2019-10-02 22:04:10 +04:00
|
|
|
-e user="$user"
|
|
|
|
-e group="$group"
|
|
|
|
-e projdir="$projdir"
|
2019-10-03 15:58:07 +04:00
|
|
|
-e setup="$COMPOSER_SETUP"
|
|
|
|
-e composer="$COMPOSER_CMD"
|
2019-10-02 22:04:10 +04:00
|
|
|
-e args="$args"
|
|
|
|
-v "$HOME:$HOME"
|
|
|
|
)
|
|
|
|
if [ "${projdir#$HOME/}" == "$projdir" ]; then
|
|
|
|
# si le répertoire de projet ne se trouve pas dans $HOME, le monter aussi
|
|
|
|
cmd+=(-v "$projdir:$projdir")
|
|
|
|
fi
|
2019-10-03 15:58:07 +04:00
|
|
|
setupscript='eval "$setup"'
|
|
|
|
runscript='
|
2019-10-02 22:04:10 +04:00
|
|
|
echo "$user" >>/etc/passwd; user="${user%%:*}"
|
|
|
|
echo "$group" >>/etc/group; group="${group%%:*}"
|
|
|
|
|
|
|
|
cd "$projdir"
|
2019-10-03 15:58:07 +04:00
|
|
|
if [ -n "$composer" ]; then :
|
|
|
|
elif [ -x composer.phar ]; then composer=./composer.phar
|
2019-10-02 22:04:10 +04:00
|
|
|
elif [ -x /usr/bin/composer ]; then composer=/usr/bin/composer
|
|
|
|
else
|
2019-10-03 15:58:07 +04:00
|
|
|
echo "ERROR: Impossible de trouver composer"
|
2019-10-02 22:04:10 +04:00
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-02 22:16:40 +04:00
|
|
|
'"$actualcmd"
|
2019-10-03 15:58:07 +04:00
|
|
|
|
|
|
|
if [ -n "$COMPOSER_SETUP" ]; then
|
|
|
|
# lancement dans un container docker à préparer
|
|
|
|
local NAME project_name container_name dkid
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
|
|
compose_set_project_name set_container_name
|
|
|
|
else
|
|
|
|
NAME="$(basename -- "$(pwd)")"
|
|
|
|
docker_check_name set_container_name
|
|
|
|
fi
|
|
|
|
container_name="dk_composer_${container_name}"
|
|
|
|
|
|
|
|
# vérifier l'existence de l'image
|
|
|
|
setx dkid=docker image ls --format '{{.ID}}' "${container_name}_image"
|
|
|
|
|
|
|
|
# créer le container le cas échéant
|
|
|
|
if [ -z "$dkid" ]; then
|
|
|
|
estep "Création du container $container_name avec l'image $COMPOSER_IMAGE"
|
|
|
|
cmd=(
|
|
|
|
docker create -it --name "${container_name}_ct"
|
|
|
|
"${basecmd[@]}"
|
|
|
|
"$COMPOSER_IMAGE"
|
|
|
|
bash -c "$setupscript"
|
|
|
|
)
|
|
|
|
setx dkid="${cmd[@]}" || return 1
|
|
|
|
docker container start -ai "$dkid" || return 1
|
|
|
|
docker container commit "$dkid" "${container_name}_image" || return 1
|
|
|
|
docker container rm "$dkid" || return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# prendre comme image le container créé
|
|
|
|
COMPOSER_IMAGE="${container_name}_image"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cmd=(
|
|
|
|
docker run -it --rm
|
|
|
|
"${basecmd[@]}"
|
|
|
|
"$COMPOSER_IMAGE"
|
|
|
|
bash -c "$runscript"
|
2019-10-02 22:04:10 +04:00
|
|
|
)
|
|
|
|
"${cmd[@]}"
|
|
|
|
}
|
2019-10-03 19:20:32 +04:00
|
|
|
function local_composer() { default_local_composer "$@"; }
|
|
|
|
function docker_composer() { default_docker_composer "$@"; }
|
|
|
|
function auto_composer() {
|
|
|
|
local COMPOSER_IMAGE="$DEFAULT_COMPOSER_IMAGE"
|
|
|
|
local COMPOSER_MACHINE=-u
|
|
|
|
local COMPOSER_CMD=
|
|
|
|
local COMPOSER_SETUP=
|
|
|
|
[ -f .composer.conf ] && source ./.composer.conf
|
|
|
|
# les premiers arguments peuvent service à redéfinir les variables
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
COMPOSER_IMAGE=*) setv "$1"; shift;;
|
|
|
|
COMPOSER_MACHINE=*) setv "$1"; shift;;
|
|
|
|
COMPOSER_CMD=*) setv "$1"; shift;;
|
|
|
|
COMPOSER_SETUP=*) setv "$1"; shift;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$COMPOSER_IMAGE" == none ]; then
|
|
|
|
local_composer "$@"
|
|
|
|
|
|
|
|
else
|
|
|
|
local PREVIOUS_DOCKER_MACHINE_NAME="$DOCKER_MACHINE_NAME"
|
|
|
|
if [ -n "$COMPOSER_MACHINE" -a "$DOCKER_MACHINE_NAME" != "$COMPOSER_MACHINE" ]; then
|
|
|
|
local -x DOCKER_TLS_VERIFY= DOCKER_HOST= DOCKER_CERT_PATH= DOCKER_MACHINE_NAME=
|
|
|
|
if [ "$COMPOSER_MACHINE" != -u ]; then
|
|
|
|
local env
|
|
|
|
setx env=docker-machine env "$COMPOSER_MACHINE" 2>/dev/null || {
|
|
|
|
eerror "$COMPOSER_MACHINE: une erreur s'est produite lors de la sélection du noeud avec docker-machine"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
eval "$env"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker_composer "$@"
|
|
|
|
fi
|
|
|
|
}
|
2019-10-02 22:04:10 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2018-10-01 09:28:20 +04:00
|
|
|
DEFAULT_PROFILE=devel
|
2019-10-03 19:43:46 +04:00
|
|
|
# pour le moment ne pas lancer composer dans un container par défaut
|
|
|
|
DEFAULT_COMPOSER_IMAGE=none #docker.univ-reunion.fr/image/utils-icmycas-php-apache:d9
|
2018-10-01 20:49:00 +04:00
|
|
|
PROFILE=
|
2018-11-16 16:25:33 +04:00
|
|
|
DM_PROFILES=()
|
2018-10-01 09:28:20 +04:00
|
|
|
set_defaults dk
|
2018-11-16 14:16:16 +04:00
|
|
|
export PROFILE
|
2018-10-01 09:28:20 +04:00
|
|
|
|
2018-09-27 21:00:45 +04:00
|
|
|
chdir=
|
2019-06-11 08:06:29 +04:00
|
|
|
CONFIG=
|
2019-05-31 17:14:59 +04:00
|
|
|
DM_SET_MACHINE=
|
2019-06-01 14:34:20 +04:00
|
|
|
USE_STACK=
|
2018-11-19 09:56:04 +04:00
|
|
|
FAKE=
|
2019-11-07 12:09:39 +04:00
|
|
|
FORCE=
|
2018-11-22 15:34:07 +04:00
|
|
|
NO_CACHE=
|
|
|
|
HOST=
|
2019-06-01 14:34:20 +04:00
|
|
|
WITH_REGISTRY_AUTH=1
|
2019-04-02 15:59:47 +04:00
|
|
|
update_apps_mode=ub
|
2019-06-20 14:58:00 +04:00
|
|
|
update_apps_devel=
|
2019-04-02 15:59:47 +04:00
|
|
|
update_apps_origin=
|
|
|
|
update_apps_branch=
|
2018-10-08 11:50:56 +04:00
|
|
|
args=(
|
2018-09-27 21:00:45 +04:00
|
|
|
--help '$exit_with display_help'
|
|
|
|
-d:,--chdir: chdir=
|
2019-06-11 08:06:29 +04:00
|
|
|
-c:,--config: CONFIG=
|
2018-11-16 14:16:16 +04:00
|
|
|
-p:,--profile: PROFILE=
|
|
|
|
-P,--prod PROFILE=prod
|
|
|
|
-T,--test PROFILE=test
|
2019-05-31 17:14:59 +04:00
|
|
|
-m:,--set-machine: DM_SET_MACHINE=
|
2019-06-01 14:34:20 +04:00
|
|
|
--stack USE_STACK=1
|
2018-11-19 09:56:04 +04:00
|
|
|
-n,--fake FAKE=1
|
2019-11-07 12:09:39 +04:00
|
|
|
-f,--force FORCE=1
|
2018-11-22 15:34:07 +04:00
|
|
|
-j,--no-cache NO_CACHE=1
|
|
|
|
-h:,--host: HOST=
|
2019-04-02 15:59:47 +04:00
|
|
|
-g,--ug,--no-update-apps update_apps_mode=b
|
|
|
|
-u,--uu,--update-apps-only update_apps_mode=u
|
2019-06-20 14:58:00 +04:00
|
|
|
-w,--uw,--update-apps-devel update_apps_devel=1
|
2019-04-02 15:59:47 +04:00
|
|
|
--uo:,--update-apps-origin: update_apps_origin=
|
|
|
|
--ub:,--update-apps-branch: update_apps_branch=
|
2019-06-01 14:34:20 +04:00
|
|
|
-l,--without-registry-auth WITH_REGISTRY_AUTH=
|
2018-09-27 21:00:45 +04:00
|
|
|
)
|
|
|
|
parse_args "$@"; set -- "${args[@]}"
|
|
|
|
|
2019-06-01 19:34:37 +04:00
|
|
|
progexists docker-machine && DM_AVAILABLE=1 || DM_AVAILABLE=
|
2019-05-31 17:14:59 +04:00
|
|
|
if [ -n "$DM_SET_MACHINE" ]; then
|
|
|
|
[ -n "$DM_AVAILABLE" ] || die "docker-machine n'est pas disponible"
|
2019-10-02 22:04:10 +04:00
|
|
|
[ "$DM_SET_MACHINE" == - ] && DM_SET_MACHINE=-u
|
2019-05-31 17:14:59 +04:00
|
|
|
setx dm_env=docker-machine env "$DM_SET_MACHINE" || die
|
|
|
|
eval "$dm_env"
|
|
|
|
fi
|
2019-06-01 19:34:37 +04:00
|
|
|
if [ -n "$DM_AVAILABLE" ]; then
|
|
|
|
for dm_profile in "${DM_PROFILES[@]}"; do
|
|
|
|
splitpair "$dm_profile" dm profile
|
|
|
|
if [ "$dm" == "$DOCKER_MACHINE_NAME" ]; then
|
|
|
|
DEFAULT_PROFILE="$profile"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2019-05-31 17:14:59 +04:00
|
|
|
|
2018-09-27 21:51:33 +04:00
|
|
|
# construire par défaut
|
|
|
|
[ $# -eq 0 ] && set -- build
|
2018-11-16 14:16:16 +04:00
|
|
|
[ -n "$PROFILE" ] || PROFILE="$DEFAULT_PROFILE"
|
2018-10-01 09:28:20 +04:00
|
|
|
|
|
|
|
[ -n "$chdir" ] && { cd "$chdir" || die; }
|
2019-06-20 14:58:00 +04:00
|
|
|
update_apps_mode="${update_apps_mode}${update_apps_devel:+w}"
|
2018-09-27 21:51:33 +04:00
|
|
|
|
2019-08-14 17:29:30 +04:00
|
|
|
[ -f .dk.scripts.sh ] && source ./.dk.scripts.sh
|
|
|
|
[ -f dk.scripts.sh ] && source ./dk.scripts.sh
|
|
|
|
|
2018-09-27 21:00:45 +04:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
[ "$1" == -- ] && { shift; continue; }
|
|
|
|
cmd="$1"; shift
|
|
|
|
case "$cmd" in
|
2019-11-21 08:55:09 +04:00
|
|
|
get-profile|get_profile|profile)
|
|
|
|
echo "$PROFILE"
|
|
|
|
exit 0
|
|
|
|
;;
|
2018-09-27 21:46:24 +04:00
|
|
|
b|build)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2018-09-27 21:00:45 +04:00
|
|
|
[ -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
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2018-09-27 21:00:45 +04:00
|
|
|
auto_build "${args[@]}" || die
|
|
|
|
;;
|
2019-05-31 17:14:59 +04:00
|
|
|
p|push)
|
2018-10-08 11:50:56 +04:00
|
|
|
[ -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
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2018-10-08 11:50:56 +04:00
|
|
|
auto_push "${args[@]}" || die
|
|
|
|
;;
|
2019-06-24 23:57:02 +04:00
|
|
|
s|start)
|
2018-09-27 21:00:45 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2018-09-27 21:00:45 +04:00
|
|
|
auto_up "${args[@]}" || die
|
|
|
|
;;
|
2018-09-27 21:46:24 +04:00
|
|
|
k|stop)
|
2019-03-28 10:19:55 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2019-03-28 10:19:55 +04:00
|
|
|
auto_stop "${args[@]}" || die
|
2018-09-27 21:00:45 +04:00
|
|
|
;;
|
2018-09-27 21:46:24 +04:00
|
|
|
1|up)
|
2018-09-27 21:00:45 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2018-09-27 21:00:45 +04:00
|
|
|
auto_up "${args[@]}" && auto_logs || die
|
|
|
|
;;
|
2019-03-28 10:19:55 +04:00
|
|
|
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
|
|
|
|
;;
|
2019-06-24 23:57:02 +04:00
|
|
|
r|run)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_run "${args[@]}" || die
|
|
|
|
;;
|
|
|
|
x|exec)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_exec "${args[@]}" || die
|
|
|
|
;;
|
2018-09-27 21:46:24 +04:00
|
|
|
d|brd)
|
2018-09-27 21:00:45 +04:00
|
|
|
do_auto_down=1
|
|
|
|
function auto_down_trap() {
|
|
|
|
[ -n "$do_auto_down" ] && auto_down
|
|
|
|
}
|
|
|
|
trap auto_down_trap 1 3 15 EXIT
|
|
|
|
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2018-11-14 14:28:24 +04:00
|
|
|
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
|
|
|
|
[ -f build.scripts.sh ] && source ./build.scripts.sh
|
2018-09-27 21:00:45 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
2018-11-16 14:16:16 +04:00
|
|
|
enote "Profil $PROFILE"
|
2018-09-27 21:00:45 +04:00
|
|
|
if auto_build; then
|
|
|
|
auto_up "${args[@]}" && auto_logs || die
|
|
|
|
else
|
|
|
|
do_auto_down=
|
|
|
|
fi
|
|
|
|
;;
|
2018-12-09 22:33:07 +04:00
|
|
|
bs)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2018-12-09 22:33:07 +04:00
|
|
|
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
|
|
|
|
[ -f build.scripts.sh ] && source ./build.scripts.sh
|
2019-06-01 14:34:20 +04:00
|
|
|
USE_STACK=1
|
2018-12-09 22:33:07 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_build && auto_up "${args[@]}"
|
|
|
|
;;
|
2019-06-24 23:57:02 +04:00
|
|
|
br)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2019-06-24 23:57:02 +04:00
|
|
|
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
|
|
|
|
[ -f build.scripts.sh ] && source ./build.scripts.sh
|
|
|
|
USE_STACK=1
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_build && auto_run "${args[@]}"
|
|
|
|
;;
|
2019-06-01 14:34:20 +04:00
|
|
|
y|deploy)
|
|
|
|
USE_STACK=1
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_deploy "${args[@]}" || die
|
|
|
|
;;
|
|
|
|
by|bd)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2019-06-01 14:34:20 +04:00
|
|
|
[ -f .build.scripts.sh ] && source ./.build.scripts.sh
|
|
|
|
[ -f build.scripts.sh ] && source ./build.scripts.sh
|
|
|
|
USE_STACK=1
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_build && auto_deploy "${args[@]}"
|
|
|
|
;;
|
2019-06-05 10:13:20 +04:00
|
|
|
bp)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2019-06-05 10:13:20 +04:00
|
|
|
[ -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_push "${args[@]}"
|
|
|
|
;;
|
2019-06-01 14:34:20 +04:00
|
|
|
bpy|bpd)
|
2019-10-02 22:04:10 +04:00
|
|
|
build_set_options "$update_apps_mode" "$update_apps_origin" "$update_apps_branch"
|
2019-06-01 14:34:20 +04:00
|
|
|
[ -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_push && auto_deploy "${args[@]}"
|
|
|
|
;;
|
2019-06-05 10:13:20 +04:00
|
|
|
service)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_service "${args[@]}" || die
|
|
|
|
;;
|
|
|
|
u|update)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_service update "${args[@]}" || die
|
|
|
|
;;
|
|
|
|
scale)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_service scale "${args[@]}" || die
|
|
|
|
;;
|
2019-04-17 02:31:09 +04:00
|
|
|
ip|show-ip)
|
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
|
|
|
auto_show_ip "${args[@]}" || die
|
|
|
|
;;
|
2019-04-10 07:25:20 +04:00
|
|
|
systemd-unit|systemd)
|
2019-03-28 10:53:50 +04:00
|
|
|
args=()
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
enote "Profil $PROFILE"
|
2019-04-10 07:25:20 +04:00
|
|
|
auto_systemd_unit "${args[@]}" || die
|
2019-03-28 10:53:50 +04:00
|
|
|
;;
|
2019-09-18 00:13:22 +04:00
|
|
|
ps)
|
|
|
|
pscmd=(
|
|
|
|
docker container ps -a
|
2019-09-18 00:35:10 +04:00
|
|
|
--format "table {{.ID}}\t{{.Image}}\t{{.Names}}\t{{.Status}}\t{{.RunningFor}}\t{{.Ports}}"
|
2019-09-18 00:13:22 +04:00
|
|
|
)
|
|
|
|
filtercmd=(cat)
|
|
|
|
awkscript='
|
|
|
|
NR == 1 { print; next }
|
|
|
|
($2 ~ filter || $3 ~ filter) { print }
|
|
|
|
'
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# pas de filtre
|
|
|
|
:
|
|
|
|
elif [ "$1" == -- ]; then
|
|
|
|
# fin de la commande
|
|
|
|
shift
|
|
|
|
elif [[ "$1" == *=* ]]; then
|
|
|
|
# filtre docker
|
|
|
|
pscmd+=(--filter "$1")
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
# expression régulière
|
|
|
|
filtercmd=(awk -v filter="$1" "$awkscript")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
set -o pipefail
|
|
|
|
"${pscmd[@]}" | "${filtercmd[@]}" || die
|
|
|
|
;;
|
|
|
|
ls)
|
|
|
|
lscmd=(docker image ls)
|
|
|
|
filtercmd=(cat)
|
|
|
|
awkscript='
|
|
|
|
BEGIN {
|
|
|
|
if (split(filter, parts, /:/) > 1) {
|
|
|
|
filter = parts[1]
|
|
|
|
tag = parts[2]
|
|
|
|
} else {
|
|
|
|
tag = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NR == 1 { print; next }
|
|
|
|
(filter == "" || $1 ~ filter) && (tag == "" || $2 ~ tag) { print }
|
|
|
|
'
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
# pas de filtre
|
|
|
|
:
|
|
|
|
elif [ "$1" == -- ]; then
|
|
|
|
# fin de la commande
|
|
|
|
shift
|
|
|
|
elif [[ "$1" == *=* ]]; then
|
|
|
|
# filtre docker
|
|
|
|
lscmd+=(--filter "$1")
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
# expression régulière
|
|
|
|
filtercmd=(awk -v filter="$1" "$awkscript")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
set -o pipefail
|
|
|
|
"${lscmd[@]}" | "${filtercmd[@]}" || die
|
|
|
|
;;
|
|
|
|
pull)
|
|
|
|
lscmd=(docker image ls)
|
|
|
|
filtercmd=(awk 'NR == 1 { print; next } $2 !~ /</ { print }')
|
|
|
|
awkscript='
|
|
|
|
BEGIN {
|
|
|
|
if (split(filter, parts, /:/) > 1) {
|
|
|
|
filter = parts[1]
|
|
|
|
tag = parts[2]
|
|
|
|
} else {
|
|
|
|
tag = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NR == 1 { print; next }
|
|
|
|
(filter == "" || $1 ~ filter) && (tag == "" || $2 ~ tag) && $2 !~ /</ { print }
|
|
|
|
'
|
|
|
|
if [ $# -eq 0 -o "$1" == -- ]; then
|
|
|
|
# pas de filtre
|
|
|
|
ewarn "pull: Vous devez spécifier l'image à mettre à jour"
|
|
|
|
continue
|
|
|
|
elif [[ "$1" == *=* ]]; then
|
|
|
|
# filtre docker
|
|
|
|
lscmd+=(--filter "$1")
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
# expression régulière
|
|
|
|
filtercmd=(awk -v filter="$1" "$awkscript")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
all="$("${lscmd[@]}" | "${filtercmd[@]}")"
|
|
|
|
setx -a images awk 'NR == 1 { next } { print $1 ":" $2 }' <<<"$all"
|
|
|
|
if [ ${#images[*]} -gt 0 ]; then
|
|
|
|
echo "$all"
|
|
|
|
ask_yesno "Etes-vous sûr de vouloir mettre à jour ces images?" O || die
|
|
|
|
for image in "${images[@]}"; do
|
|
|
|
docker pull "$image" || die
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
2018-09-27 21:00:45 +04:00
|
|
|
rm)
|
2019-09-18 00:13:22 +04:00
|
|
|
lscmd=(docker image ls)
|
|
|
|
filtercmd=(cat)
|
|
|
|
awkscript='
|
|
|
|
BEGIN {
|
|
|
|
if (split(filter, parts, /:/) > 1) {
|
|
|
|
filter = parts[1]
|
|
|
|
tag = parts[2]
|
|
|
|
} else {
|
|
|
|
tag = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NR == 1 { print; next }
|
|
|
|
(filter == "" || $1 ~ filter) && (tag == "" || $2 ~ tag) { print }
|
|
|
|
'
|
|
|
|
if [ $# -eq 0 -o "$1" == -- ]; then
|
|
|
|
# pas de filtre
|
|
|
|
ewarn "rm: Vous devez spécifier l'image à supprimer"
|
|
|
|
continue
|
|
|
|
elif [[ "$1" == *=* ]]; then
|
|
|
|
# filtre docker
|
|
|
|
lscmd+=(--filter "$1")
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
# expression régulière
|
|
|
|
filtercmd=(awk -v filter="$1" "$awkscript")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
all="$("${lscmd[@]}" | "${filtercmd[@]}")"
|
|
|
|
setx -a images awk 'NR == 1 { next } { print $3 }' <<<"$all"
|
|
|
|
if [ ${#images[*]} -gt 0 ]; then
|
|
|
|
echo "$all"
|
|
|
|
ask_yesno "Etes-vous sûr de vouloir supprimer ces images?" || die
|
2019-11-07 12:09:39 +04:00
|
|
|
docker image rm ${FORCE:+--force} "${images[@]}" || die
|
2019-09-18 00:13:22 +04:00
|
|
|
fi
|
2018-09-27 21:00:45 +04:00
|
|
|
;;
|
2018-09-27 21:46:24 +04:00
|
|
|
X|prune)
|
2018-09-27 21:00:45 +04:00
|
|
|
docker container prune -f || die
|
|
|
|
docker image prune -f || die
|
|
|
|
;;
|
2019-10-02 22:16:40 +04:00
|
|
|
composer|c|ci|cu|cs)
|
2019-10-02 22:04:10 +04:00
|
|
|
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=()
|
|
|
|
if [ "$cmd" == ci ]; then args+=(install)
|
|
|
|
elif [ "$cmd" == cu ]; then args+=(update)
|
2019-10-02 22:16:40 +04:00
|
|
|
elif [ "$cmd" == cs ]; then args+=(shell)
|
2019-10-02 22:04:10 +04:00
|
|
|
fi
|
|
|
|
while [ $# -gt 0 -a "$1" != -- ]; do
|
|
|
|
args+=("$1"); shift
|
|
|
|
done
|
|
|
|
auto_composer "${args[@]}"
|
|
|
|
;;
|
2018-09-27 21:00:45 +04:00
|
|
|
*) die "$cmd: commande inconnue";;
|
|
|
|
esac
|
|
|
|
done
|