====== Git Deployement ======
===== Sur le serveur en ligne =====
==== créer un depos git "bare" ====
cd /home/username/
mkdir -p gitBareRepos/project-name.git
cd gitBareRepos/project-name.git
git init --bare
==== créer le hook post-update ====
en ajoutant fichier post-receive suivant dans /home/username/gitBareRepos/project-name.git/hooks/
#!/bin/bash
#hook/post-receive
PRODDIR="/var/www/project-name"
read oldrev newrev refname
if [ $refname = "refs/heads/prod" ]; then
echo "===== DEPLOYING APP ====="
unset GIT_DIR
cd ~
cd $PRODDIR
. deploy.sh
echo $?
echo "====== OK ====="
else
echo "Warning Commit not deployed, please use prod branch"
fi
rendre le hook executable
chmod +x post-receive.sh
==== Créer le dépos git du site de production ====
cd /var/www/
mkdir -p project-name/public_html
cd project-name/public_html
git init
git remote add origin /home/username/gitBareRepos/project-name.git
==== ajouter le script de deployment ====
ajouter le script suivant dans /var/www/project-name
=== script generic ===
#!/bin/sh
echo ""
echo "Switching to project docroot."
cd /var/www/project-name/public_html
echo ""
echo "Pulling down latest code."
git pull --ff-only origin prod
echo "Deployment complete."
=== pour drupal 7 ===
#!/bin/sh
echo ""
echo "Switching to project docroot."
cd /var/www/project-name/public_html
echo ""
echo "Pulling down latest code."
git pull --ff-only origin prod
echo ""
echo "Clearing drush cache"
drush cc drush
echo ""
echo "Run database updates."
drush updb -y
echo ""
echo "Reverting features modules."
drush fra -y
echo ""
echo "Clearing caches."
echo ""
drush cc all
echo ""
echo "Deployment complete."
=== pour drupal 8 ===
si le site n'est pas géré avec composer, commenter les lignes correspondantes
#!/bin/bash
# https://chromatichq.com/blog/drupal-8-deployments-jenkins-github-slack
echo "updating drupal 8"
echo "Switching to project docroot."
cd /var/www/project-name/public_html
echo ""
echo "Pulling down latest code."
git pull --ff-only origin prod
git submodule update --init --recursive
echo ""
echo "Clearing drush caches."
drush cache-clear drush
echo ""
echo "Composer install."
composer install --no-dev
echo ""
echo "Running database updates."
drush updb -y
echo ""
echo "Importing configuration."
drush config-import -y
echo ""
echo "Clearing caches."
drush cr
echo ""
echo "Deployment complete."
===== En locale =====
==== ajouter le remote du serveur dans votre depos git existant ====
Il est possible de remplacer serveur.com par l'ip du serveur
git remote add project-name username@serveur.com:gitBareRepos/project-name.git
==== créer une branche prod ====
git branch prod
==== travailler sur la branch master (ou autre) et synchroniser la branch prod ====
git fetch . master:prod
==== pousser la prod en ligne ====
git push project-name prod
et voila !