Exemple de fichier gitlab-ci.yml

.gitlab-ci.yml

stages : - predeploy - deploy - postdeploy - scheduled prod_backup_db: script: - ssh <a href="mailto:user@serveur">user@serveur</a> 'drush @kg cr' - ssh <a href="mailto:user@serveur">user@serveur</a> 'drush @kg sql-dump --gzip > "/home/site/db/`date +%Y-%m-%d_%H-%M-%S`-kgaut.net-$(hostname).sql.gz"' only: - master stage : predeploy environment: name: preprod prod_diff_git: script: - ssh <a href="mailto:user@serveur">user@serveur</a> 'bash -s' < scripts/deploy/2-diff.sh only: - master except: - schedules stage : predeploy environment: name: preprod prod_diff_config: script: - ssh <a href="mailto:user@serveur">user@serveur</a> 'bash -s' < scripts/deploy/3-diff-config.sh only: - master except: - schedules stage : predeploy environment: name: preprod prod_deploy: script: - ssh <a href="mailto:user@serveur">user@serveur</a> 'bash -s' < scripts/deploy/4-deploy.sh only: - master except: - schedules stage : deploy environment: name: preprod dump: only: - schedules stage : scheduled script: - ssh <a href="mailto:user@serveur">user@serveur</a> 'find "/home/kgaut_net/db" -type f -mtime +"3" -delete'

2-diff.sh

#!/bin/bash set -e cd website if [[ $(git diff) ]]; then FILENAME="$(date +"%Y-%m-%d_%H-%M-%S")-diff.patch" git diff > "/home/site/diffs/$FILENAME" echo "---------------------------------"; echo "modifications en prod detectées, patch créé : $FILENAME"; echo "Modifications de fichier en prod detectées, patch créé" | mail -s "Fichiers modifiés" -a "/home/site/diffs/$FILENAME" <a href="mailto:moi@email.com">moi@email.com</a> echo "Liste des fichiers modifiés : "; echo $(git diff --name-only) echo "---------------------------------"; git checkout ./ else if [[ $(git ls-files --others --exclude-standard) ]]; then echo "---------------------------------"; echo "Fichiers non versionnés : " echo $(git ls-files --others --exclude-standard) echo "---------------------------------"; FAIL; else echo "Pas de modification en prod à signaler" fi fi

3-diff-config.sh

#!/bin/bash set -e cd /home/site/website drush @kg cr drush @kg config-export sync -y if [[ $(git diff files/config/) ]]; then echo "---------------------------------"; FILENAME="$(date +"%Y-%m-%d_%H-%M-%S")-config.patch" git diff files/config/ > "/home/site/diffs/$FILENAME" echo "Modifications de configuration en prod detectées, patch créé : $FILENAME"; echo "Configuration modifiée, patch créé" | mail -s "Configuration modifiée" -a "/home/site/diffs/$FILENAME" <a href="mailto:contact+kgn@kgaut.net">contact+kgn@kgaut.net</a> git checkout ./ echo "---------------------------------"; #FAIL; fi cd /home/site/website/files/config if [[ $(git ls-files --others --exclude-standard) ]]; then echo "---------------------------------"; FILENAME="$(date +"%Y-%m-%d_%H-%M-%S")-config.tar" echo "Config en prod non versionnée : " echo $(git ls-files --others --exclude-standard) tar -zcvf "/home/site/diffs/$FILENAME" ./ echo "Archive crée : $FILENAME"; echo "Configuration modifiée, non versionnée, patch créé" | mail -s "Configuration non versionnée" -a "/home/site/diffs/$FILENAME" <a href="mailto:contact+kgn@kgaut.net">contact+kgn@kgaut.net</a> rm ./*/*.yml git checkout ./ echo "---------------------------------"; #FAIL; fi

4-deploy.sh

#!/bin/bash set -e cd /home/site/website git pull composer install --no-dev drush @kg updb -y drush @kg entup -y drush @kg updb -y drush @kg config-import sync -y gulp prod drush @kg cr

Ajouter un commentaire

Ne sera pas publié
CAPTCHA
Désolé, pour ça, mais c'est le seul moyen pour éviter le spam...