We recently automated our release process for a new project we are working on, to be debuted shortly. We use Git as a version control system, but found keeping the website up to date to be too cumbersome. So, we scripted the whole release process on our server. Here is how we did it.
- We installed the Git client on the web server. Our incredible hosting company handled that for us with no issues.
- Next we generated some SSH keys for Git to use when we SSH to our Git server. These keys automate passwords, especially when we use ssh-agent to handle the key’s password.
ssh-keygen -t rsa
- After transferring the public key to the Git server, we added that key, id_rsa, to ssh-agent
This will prompt you for the key’s passphrase, not your SSH password.
- Copy the public key to the Git Server, obviously using scp or sftp. Add it to the ~/.ssh/authorized_keys file.
- Clone the Git repository
git clone ssh://git.server.url:port/absolute/path/to/repository.git
- Script minutely|hourly|nightly|weekly resets and pulls from the Git server. I hard reset to restore the server to the pristine Git condition, then pull all updates from the Git server to make sure I’m as up to date as possible.
git reset --hard git pull
Step 6 is completely scripted and I run as a cron job every night. A side note regarding paths. My repository structure does not match the web server’s directory structures well. So, I added symbolic links to the necessary directories and I updated the permissions to allow the web server to run as intended.
How do you use Git to ensure proper release states of your website?