📜 ⬆️ ⬇️

Use Git as a tool for web application deployment.

Hi, Habrosoobschestvo!

Continuing the topic of using git hooks, I want to tell you about post-merge and post-checkout

What we have


We have a web application that we are developing. We need to quickly and easily add changes to production.
')

What does git offer us


post-merge - This hook is called 'git-merge', after we have executed 'git-pull' or 'git-merge' on the local repository. The hook will fail if we have conflicts with merge.
Post-checkout - This hook is called 'git-checkout' after we execute 'git-clone' or 'git-checkout'.

What we do


The deployment mechanism will be something like this:
1. Raise the git server. We translate all development to git. The tested code is uploaded to the repository.
2. We write hooks that will do what we need to do after deployment. In this case, the post-merge hook.
3. If we want to deploy a working configuration on a clean server, then we write a post-checkout hook

For example, after the deployment we need to clean up some folder and restart the Apache.
#!/bin/bash /etc/init.d/apache2 stop find /path/to/folder -type f -delete /etc/init.d/apache2 start 


Put this script in .git / hooks / post-merge.
We execute git pull and we run this script.

Similarly for post-checkout hook

Pros:




Minuses:




UPD: The goal is not to show the only and kosher kind of deployment, but how you can still use git hooks. And yes, I know about Capistrano, Vlad the Deployer, Chef (solo), Puppet and others.

Source: https://habr.com/ru/post/140103/


All Articles