By hook or by crook

(♣)

By hook or by crook

Homemade continuous deployment i use github as my main git repo, and i use Netlify as my stage development service. i love netlify. for one reason of another i wanted to have the convinience of git push > trigger netlify build execpt i wanted that on my own cheap fastcomet server. how difficult could it be right? well ... not at all difficult. the most annoying thing was getting the file system permissions right on my server. and that is it.

here is how i did it:

For the indepth step by step article will go over everything, and is available on medium or as an essay

This is the holy trinity, the code equivalent of the love triangle. you push the code changes to Github, which triggers a webhook, that in turn executes a CURL and delivers a POST payload to your server. On the server you check they payload and if it is secure it then fires an event to run a bash command. That shell script will pull the updates from the repo, and rebuild the static site, with an NPM run command.

That is all well and good, here is the snag that trapped me. Execute permissions, and PHPs silent failure to execute npm commands. After almost two hours on stackoverflow and google at large i discovered that the PHP command shell_exec() was not getting my shell variables, so it did not have a PATH to the binaries.

To solve this you SSH onto your machine and systematically run which for git, npm and node. That will tell you where the binies are when the shell is complete. When you ssh into a machine it creates your shell by running the bashrc and other server specific session stuff. So for example:

which npm
/usr/local/bin/npm

With the output value you add it to the shell script as a viarble called PATH so that when PHP runs the script the path to the binary is defined, and it is done without the overhead of source to your profile.