Since yesterday, this blog deploys automatically when I push changes to its git repository. Before that, my workflow was something like:
- ssh into the server
- write something
- git add, git commit, git push (or forget about this step altogether)
- bundle exec jekyll build
Now, I do:
- Write something (from any machine where I have a copy of my blog's git repository)
- git add, git commit, git push
The best part for me is that I should now have a proper git history of my blog's modifications instead of a few giant commits spaced far apart in time due to skipping step 3 by mistake or laziness.
This isn't unique, has been done before, and a few automated deployment techniques are documented on the Jekyll site, but I wanted to jot down my configuration for a few reasons:
- As a "note to self" so I can recall how it works if I need to set this up again
- I'm due for my yearly blog post (yes, I should write more)
- It might be helpful to other people using a similar list of tools
One of those git projects is the source files for the blog.
Gogs lets you edit git hooks via its web interface under the git repository's "Settings > Git Hooks" section. The one we're interested in is "post-receive", which runs on the server-side after git is done receiving the changes you pushed to it via "git push" from the client-side.
Since both Gogs and the Jekyll blog are on the same server, the only thing I have to do is tell git to run the "jekyll build" command (along with some house-keeping details) after it got the new data:
And that's pretty much it. Make sure the user running your Gogs instance has access to the blog's files/directories and you should be good to go.