This site no longer uses 11ty or post-receive hooks, at the moment, I simply git push to the server after building the files.
Setting up Post-Receive Hooks
I've been using git for years, but somehow never got into using hooks. In order to make updating this website smoother, I'm trying out a very simple hook script which executes on the server after I commit to it. After getting my local ssh configuration updated so that I didn't have to manually log in each time, the next step was figuring out how to commit directly into the server. This was done by adding a "remote" which is an SSH user@address with full path to the repo on the server.
With this additional remote, I now push into the main repo for storage and then to this new remote when I want to update the site.
On the server, the .git/hooks/post-receive script is waiting and will run:
Because I'm using 11ty, this triggers a rebuild of the static files. But this script could do whatever you need to build your site.
Although this is a very simple solution, it took me a lot of false starts and wrong ideas before I finally landed here.
Notes for future reference:
On the server
- When you setup your web server, install git
- Clone your repo onto the server
- Configure nginx or whatever server to point your site from the repo (where ever it builds final files to)
- Add Lets Encrypt or other SSL
- Add a bash script to do whatever build command you need in the git folder of your repo at
git config --global receive.denyCurrentBranch updateInsteadso you don't get an error committing into a non-bare repo.
On your local
- Avoid the login prompt by adding your SSH key to the SSH Agent
- Add a remote to the server
git remote add deploy ssh://<your-name>@<your-ip>/path/to/your/repo
git push deploy branchNamewhen you want to update the site