Automation can liberate the human hands, and more importantly, because the prescribed process to walk, but also reduce the production of many misoperation. Do not know how you usually update their own production environment code, FTP overwrite old files, server scheduled task to build the latest source, or there is more advanced practice?
I'm currently using a Git Hook to deploy my project. A git hook is a hook provided by git that can be invoked after a specific event is triggered. In fact, more generally speaking, when you set up a git hook, as long as your remote warehouse received a push, Git hook can help you execute a bash script.
Here are my simple automated deployments using Git hooks, and there may be more advanced practices that you can dig for yourself.
Initializing a remote Git repository on the server
git init
and git --bare init
The original warehouse is completely different, specific I Google, English is understood, but to translate the Chinese but do not know what adjectives to call these 2 kinds of warehouses.
Here we're going to git --bare init
initialize a remote repository by initializing
1 2 3 4
|
CD ~ Testrepo Testrepo $ git--bare init
|
Initializing a local Git repository on the server
This repository is initialized by the git init
most common local repository, its role is to pull the remote repository (in fact, next to it) the latest source code, and then compile in this warehouse, the code compiled to the WWW directory (the root directory of the Web site).
1 2 3 4 5 6 7 8 9 10 11 |
CD ~ Testdeploy Testdeploy Clone ~/#从远程仓库 clone source
# # # Set hooks for remote warehouses
"' Bash CD ~/Testrepo/hooks $ vim Post-receive
|
post-receive
The execution script inside
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/bin/sh unset git_dir deploypath=/home/user/ Testdeploy wwwpath=/home/wwwroot/testdeploy CD $DeployPath git Add. -A && git stash git pull Origin master < span class= "comment" ># the following 2 steps are the actual bash scripts you add yourself fis release-dompd $ Wwwpath # I use the FIS, the front-end code is compiled qrsync/home/user/qiniutools/config.json span class= "comment" ># sync with seven kn sync tool |
Finally, to post-receive
add executable permissions
Add a remote source to a local warehouse
This time the local warehouse is really your development machine above the local. Add a new remote source to your existing Git project, and the push code in the remote source will automatically trigger the bash script above.
1 2
|
$ git remote add deploy [email protected]:/home/user/Testrepo $ git push Deploy Master
|
Turn Https://dearb.me/archive/2015-03-30/automate-deploy-your-websites-with-git-hook/?utm_source=tuicool
Automate site deployment with Git hooks