Created
August 2, 2014 11:24
-
-
Save vpratfr/4b4f401ef981d76291e1 to your computer and use it in GitHub Desktop.
Bash script to automatically deploy a web project
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
## 1. Create git repo in user's home | |
cd /home/myuser | |
mkdir git | |
mkdir web.git | |
cd /home/myuser/git/web.git | |
git init --bare | |
## 2. Put the post-receive script in there | |
cd /home/myuser/git/web.git/hooks | |
# copy the file here | |
# edit it to replace "/web" in DEPLOYTO by your own www root path | |
## 3. Add the repository remote (we'll name it "prod") to your source repository | |
git remote add prod ssh://myuser@yourserver.com:/home/myuser/git/web.git | |
## 4. Push master to that remote when you're ready | |
git push prod master |
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
#!/bin/bash | |
# post-receive | |
# 1. Read STDIN (Format: "from_commit to_commit branch_name") | |
DEPLOYTO=/web | |
read FROM TO REFNAME | |
BRANCH=${REFNAME#refs/heads/} | |
# 2. Only deploy if master branch was pushed | |
if [[ "$BRANCH" != "master" ]]; then | |
echo $FROM $TO $BRANCH | |
echo "Not deploying because I received branch: " $BRANCH | |
exit | |
else | |
echo "Deploying to: " $DEPLOYTO | |
fi | |
# 3. Copy files to deploy directory | |
GIT_WORK_TREE="$DEPLOYTO" git checkout -f master | |
# 4.TODO: Deployment Tasks | |
# i.e.: Run Puppet Apply, Restart Daemons, etc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment