cd /home/username/ mkdir -p gitBareRepos/project-name.git cd gitBareRepos/project-name.git git init --bare
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
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 suivant dans /var/www/project-name
#!/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."
#!/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."
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."
Il est possible de remplacer serveur.com par l'ip du serveur
git remote add project-name username@serveur.com:gitBareRepos/project-name.git
git branch prod
git fetch . master:prod
git push project-name prod
et voila !