Last active
December 17, 2015 05:09
-
-
Save kingkool68/5555927 to your computer and use it in GitHub Desktop.
To push code changes to text servers I do this.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have a private Git running on a server somewhere which we consider our central repository. Inside the .git/hooks/post-recieve is the following: | |
#!/bin/bash | |
while read oldrev newrev ref | |
do | |
branch=`echo $ref | cut -d/ -f3` | |
if [ "master" == "$branch" ]; then | |
echo "MASTER can't deploy anywhere yet" | |
fi | |
if [ "beta" == "$branch" ]; then | |
echo "Deploying BETA branch to example1.com" | |
unset GIT_DIR | |
git push betaserver beta | |
echo "Done deploying BETA branch" | |
fi | |
if [ "alpha" == "$branch" ]; then | |
echo "Deploying ALPHA branch to example2.com" | |
unset GIT_DIR | |
git push alphaserver alpha | |
echo "Done deploying ALPHA branch" | |
fi | |
done | |
So it basically does a git push to a different origin based on which branch was committed. This also assumes your central Git repository server has the SSH keys for the other servers it is pushing to. | |
On each of the servers where code is pushed to we have this in .git/hooks/post-recieve: | |
#!/bin/sh | |
cd /path/to/the/root-folder/of-the-website || exit | |
unset GIT_DIR | |
git fetch --all | |
git reset --hard origin/beta | |
echo "example1.com deployed!" | |
php -q /path/to/some/other/script/that/should/run/index.php ''; | |
So what we end up with is seamless deployments to our development servers. When code is committed to a branch and pushed, the server for that branch updates itself. That script that is fired off at the end is for minifying CSS and other weird tasks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment