Created
July 18, 2016 09:11
-
-
Save lengerfulluse/458ba31849f041b0dbff7ac41eb9dd54 to your computer and use it in GitHub Desktop.
Deploy to DigitalOcean with git bare repo hooks
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
REFER LINK: https://www.digitalocean.com/community/tutorials/how-to-deploy-jekyll-blogs-with-git. | |
apt-get install git-core | |
Second, change to your home directory and create a new "bare repository" to deploy to. | |
cd ~/ | |
mkdir repos && cd repos | |
mkdir awesomeblog.git && cd awesomeblog.git | |
git init --bare | |
Following that, we need to set up a post-receive hook. This is a shell script that Git runs when files are pushed to a repository. Create it like so: | |
cd hooks | |
touch post-receive | |
nano post-receive | |
Now paste in the following script, adjusting the variables accordingly. GIT_REPO is the path to the bare repository created in the previous step, TMP_GIT_CLONE is a location where the script will check out the files to and build the blog before copying them to /var/www. PUBLIC_WWW is the path where the final site will reside. In this example (assuming your web root is /var/www) the site would appear at http://example.org/awesomeblog, whereas it would appear at http://example.org if PUBLIC_WWW read /var/www instead. | |
#!/bin/bash -l | |
GIT_REPO=$HOME/repos/awesomeblog.git | |
TMP_GIT_CLONE=$HOME/tmp/git/awesomeblog | |
PUBLIC_WWW=/var/www/awesomeblog | |
git clone $GIT_REPO $TMP_GIT_CLONE | |
jekyll build --source $TMP_GIT_CLONE --destination $PUBLIC_WWW | |
rm -Rf $TMP_GIT_CLONE | |
exit | |
Save the file by pressing control+O and hitting the enter key. Then give the file executable permissions. | |
chmod +x post-receive | |
Add a Git Remote | |
Back on your local machine, add a remote to your blog's Git repository. | |
git remote add droplet user@example.org:repos/awesomeblog.git | |
Now you should be able to push your latest commits to the server with the following command: | |
git push droplet master | |
Any time you make a new blog post in Jekyll, commit the changes to the Git repository and push to your VPS. The cloud server will build the site and the changes will go live within seconds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, is really helpful