Integration of shared hosting and SVN

    This script is more research than intended for serious development teams. I created to learn better python. Nevertheless, I have been successfully using it for more than six months.

    This article is for those developers who lead some project in SVN, having a remote server, access to which is via ftp and ssh, but you cannot install anything on it.

    deployment pattern


    The deployment scheme for me is very simple - I just update the files on the remote server. This is exactly what is implemented using the script.

    The developer pins the code into the repository. After that, a python script is launched (automatically or manually), which uploads the updated files to the server and deletes the old ones. My script starts automatically, due to the fact that I use BuildServer CruiseControl (java), which monitors the repository and allows me to perform some events when I see that a newer version of the code has appeared in the repository.
    Environmental requirements
    1. Server on the LAN
      • SVN repository, svn.exe added to PATH
      • installed python 2.5, python.exe is added to PATH
      • access to ssh . I have a stripped down version of cygwin, on which there is actually only ftp + ssh, so I’ll count on you to have one too.

    2. Remote server
      • ssh, ftp raised
      • there is no way to install third-party software

    3. The server folder C: \ Program Files \ CruiseControl \ projects \ project1 stores a working copy of the code synchronized with the one on the production server. That is, in fact, the code on the production server and in this folder coincide.
    4. The script is located on the path C: \ svn \ apply_svn_changes \ publish_web_site.py
    5. The user from which you run the script has the right to access the Internet via ftp and ssh, as well as run files on this server.
    6. The site on the production server is located in the web / project folder relative to the ftp home folder.

    The script is launched from the console as follows:
    > python C:\svn\apply_svn_changes\publish_web_site.py -c "C:\Program Files\CruiseControl\projects\project1\source" --host ftp_user@production.com -p ftp_password -d sites/ms

    The script looks in the folder “C: \ Program Files \ CruiseControl \ projects \ project1 \ source” , where it finds the current version of the code, the version of the code in the repository. He compares them, finding out which files and folders should be deleted and which ones should be downloaded again or created. This is done using the command svn diff . After that, he draws up a plan of tasks, saving the plan in a temporary folder.
    The script opens the plan, connects via ftp to the specified server and starts the plan to execute.
    Then it turns off. All changes are written to the log.

    The main code on pastebin , the whole script on depositfiles.

    Try also to run the script with the --help 1 switch
    python "C:\svn\apply_svn_changes\publish_web_site.py" --help
    .ssh is needed only to delete folders from the server using rm -rf ./[...](this is a stupid outgrowth on the overall smoothness of the system, hack, but I had to go for it).

    Also popular now: