I've been meaning to get myself set up with Git deployment for a while now. What better time than right after a website refresh?
I wrote a pretty straightforward Grunt task to change the Sass output style from expanded
to compressed
for building prior to deployment. There’s probably some Jekyll plugin, or an even more clever way of doing it, but this is what I’m doing, so I need to make it work.
So, the requirements for my Git hook are:
- Checkout into a working directory
- Run one or more Grunt tasks
- Build with Jekyll
- Don't shit all over itself
Dreamhost already has Git and Ruby installed, but that didn’t stop me from jumping into a rabbit hole...
Note: This worked for me, but it may not work for you. Proceed with caution; don’t come blaming me for any trouble you get into.
Also, most of this is unsupported by Dreamhost and could break at any time.
Node and NPM
I originally installed Node on my server a while back by cloning the source and compiling myself. And while that worked fine, when it came time to install Grunt and some tasks, I ran into a few problems getting the latest versions of everything. After a bit of Googling, I found NVM.
NVM : Node :: RVM : Ruby
NVM makes it almost too easy to install and update Node. I chose the manual install to avoid having my bash_profile
automatically written to.
Manually installing NVM is as simple as cloning the repo and checking out the latest version:
Once that’s finished, source the ~/.nvm/nvm.sh
file in your shell and you can easily manage Node versions. See their usage docs for more, but what I did was update my dotfiles, test on my laptop and then pull the changes to the server. From there I re-installed my dotfiles and everything was ready to go.
RVM and Ruby
Installing gems like Jekyll and Rouge was no problem. However, Dreamhost has an older version of Ruby (1.8.7), which meant I was stuck on older versions of the gems. The Dreamhost RVM docs helped, but it still wasn’t quite working. This Stack Exchange answer cleared everything up:
Even with that bit of magic, updating Ruby was unnecessarily difficult. I ended up going with this suggestion from another Stack Exchange answer.
Great. But...
I spent about an hour or so working through my Ruby and Node installation issues and getting everything set up, and basically the rest of my life troubleshooting why my Git hook was telling me Grunt and Jekyll weren’t installed.
This was my first experience with Git hooks, so I think I let that cloud what was actually a pretty simple problem to fix.
The non-login environment
I haven’t researched this a whole lot, so forgive me if I don't have this 100% correct, but, as far as I could figure out, my Git hook is running in a non-login shell, meaning all my fancy bash_profile
settings and $PATH
weren't set as they should have been.
So, essentially, what I needed to do was re-create my login environment for the Git hook.
That did the trick. Everything ran as expected. I was very happy to have gotten to the bottom of that.
I hope this helped you (or future me) get past the hurdle of automated deployment with Git, Grunt and Jekyll.