📜 ⬆️ ⬇️

Integration of shared hosting and SVN

This script is more research than intended for serious groups of developers. Created by me to learn python better. Nevertheless, I successfully use it for more than six months.

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

deployment scheme

The layout of my deployment is very simple - I just update the files on the remote server. This is what is implemented using the script.

The developer secures the code in the repository. After that, a script is started (automatically or manually) on a python that uploads updated files to the server and deletes old ones. My script runs automatically, due to the fact that I use the BuildServer CruiseControl (java), which monitors the repository and allows me to execute some events when I see that a newer version of the code has appeared in the repository.
Requirements for the environment
  1. Server in local network
    • SVN repository, svn.exe has been added to PATH
    • installed python 2.5, python.exe has been added to PATH
    • SSH access. I have a stripped down version of cygwin, which actually has only ftp + ssh, so I’ll expect you to have it.

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

  3. The C: \ Program Files \ CruiseControl \ projects \ project1 server folder contains 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 is the same.
  4. The script is located at the path C: \ svn \ apply_svn_changes \ publish_web_site.py
  5. The user from which you run the script has rights 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 like this:
> 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 into the folder “C: \ Program Files \ CruiseControl \ projects \ project1 \ source” , where it finds out 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 svn diff . After that, he draws up a plan for completing 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 is on pastebin , the entire script is on depositfiles.

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

Source: https://habr.com/ru/post/103258/

All Articles