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.
- Install
easy_install
- Check your python version at the Terminal by running
python
(quit the python prompt by runningexit()
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
- Check your python version at the Terminal by running
- Install GitPython using
easy_install
- Just run
sudo easy_install GitPython
in Terminal and it’ll installGitPython
along with all its dependencies for you
- Just run
- Install
git-ftp.py
- Download
git-ftp.py
from https://github.com/ezyang/git-ftp - Place
git-ftp.py
in any folder you like (I’ve placed mine in~/Library
)
- Download
~
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!
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!
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.
Thank you for the tips, this is just what I need! Awesome post!
Thanks for the tip! I had a hard time configuring git-ftp.py using install notes in their github repo. You did a great job explaining the process, thanks!