Automatic Website Publishing with git-ftp.py on Mac OS X

On a recent project I collaborated on, deployment happened via git-ftp.py, a Python script which automatically publishes your git repository to an FTP server.

The script itself works with with an git-rev.txt file on the FTP server which keeps track of the last published commit. When deploying via git-ftp.py, the script only uploads the changes made since the last published commit.

~

Installing git-ftp

git-ftp.py relies on GitPython which itself can easily be installed using easy_install if you don’t want to worry about dependencies and the like.

  1. Install easy_install
    • Check your python version at the Terminal by running python (quit the python prompt by running exit() or hitting CTRL+D)
    • Download the correct .egg from http://pypi.python.org/pypi/setuptools/ (in my case: the one with 2.7 in its filename as my python version is 2.7.1)
    • Install it at the Terminal with sudo sh setuptools-0.6c11-py2.7.egg
  2. Install GitPython using easy_install
    • Just run sudo easy_install GitPython in Terminal and it’ll install GitPython along with all its dependencies for you
  3. Install git-ftp.py

~

Deploying with git-ftp.py

Before being able to deploy with git-ftp.py, you’ll have to provide it some FTP credentials. To do so, create a file ftpdata inside the (hidden) .git folder of your project (so the file is /path/to/project/.git/ftpdata). Set the contents of it to something like this:

[master]
username=projectname
password=projectpass
hostname=ftp.myproject.be
remotepath=/public_html
ssl=no

Note: you can add per-branch credentials if you want. Just duplicate the block and change [master] to the name of the branch you’re targetting.

Once configured, you can start deploying using this command:

python ~/Library/git-ftp.py

The script will output a list of all files that were uploaded.

Note: If you run git-ftp.py for the very first time on an FTP server containing an already published version of the project you should first place a git-rev.txt file on the server. Set the contents of the file to the SHA1 of the last commit which is already present on the server. Otherwise git-ftp.py will upload the whole repository which is not necessary.

~

Pro tip #1: set up an alias and save some time

In order to not having to type the entire publishing command all the time, set up an alias in .bash_profile. Run these commands at the Terminal:

echo "alias git-ftp='python ~/Library/git-ftp.py'" >> ~/.bash_profile
source ~/.bash_profile

That way you can deploying using this command:

git-ftp

~

Pro tip #2: Use a bare repository as a proxy

With git-ftp.py, it’s also possible to have a repository automatically publish when it’s being pushed upon. The git-ftp.py project has full instructions on how to set this up (haven’t used it myself).

~

Happy Deploying!

Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

Note: Whilst researching this I’ve stumbled upon git-ftp (not the same as git-ftp.py!), a shell script which – if I understand correctly – does about the same.

Alternatively – if you have Transmit – you could use Dock Send along with git-transmit.

If you’re more fond of the GitHub way of publishing (using a gh-pages branch), you’ll want to check out my own guide on Automatic website publishing with Git, GitHub-Style.

Finally, if you’re running all-Linux machines with SSH enabled, you’ll be better of with Capistrano.

Join the Conversation

3 Comments

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.