Simple Deployment Workflow

May 18th 16

Yes GIT is not meant for deployment and something more robust like Capistrano is optimal. However, while working on a basic project it will suffice.

Being able to steer clear of FTP is the bare minimum. Version control additionally is just too useful not to use even for small apps.

Steps

With that said this will get you started with a semi-decent workflow:

  • Enable SSH

You will need to request this from your service provider. I have found that it is best to do this from the account billing page rather than cPanel. I would imagine that the provider doesn’t want you on this page for very long while requesting a change.

  • Create SSH

Generate your key using ssh-keygen if you haven’t already.

Generate your key

cd ~/.ssh
ssh-keygen -t rsa -C "email@domain.com"
pbcopy < ~/.ssh/id_rsa.pub
  • Copy the key onto your Server

Enable passwordless communication

rsync -av -e "ssh -p 2222" ~/.ssh/id_dsa.pub root@ip.add.ress.here:.ssh/authorized_keys

If you run into any problems here check with your host provider.

  • Local Repository

Example basic GIT

mkdir site && cd $_
git init
cat > index.html
....
git add .
git commit -a
  • Add Local Push Deployment

Configure the server

git remote add prod ssh://username@ipaddress:port/~/apps/blog/.git
  • Server Repository

Exporting requires an empty working directory

mkdir .git && cd $_
git init --bare
  • Server Hook

GIT wont automatically checkout your changes when you push. You need to setup a hook so that your content will be updated:

Setup automatic checkout

cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=~/apps/blog/public git checkout -f
chmod +x hooks/post-receive

Note that GIT_WORK_TREE points to where the .git is located which includes ‘~’.

  • Push to Live
Update your deployment
git push prod +master:refs/heads/master
Subsequent pushes
git push prod

Knowing when to change

Next