Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to best update a website from subversion

Tags:

svn

I have a PHP website backed by a MySQL database and a small team of programmers submitting code to subversion. Typically we write code, test it locally, commit to subversion and then copy changed files to a hidden area for online testing.

However mistakes can be made. Occasionally I want to refresh the site so that I know, without a doubt, that the site code and database really represents what's in subversion. I'd like to get as close to a one click solution as possible so that it's foolproof.

What's the best way to do that?

BTW, if it matters, we develop on windows machines.

like image 751
dl__ Avatar asked Oct 16 '08 13:10

dl__


People also ask

How does SVN update work?

svn update brings changes from the repository into your working copy. If no revision is given, it brings your working copy up-to-date with the HEAD revision. Otherwise, it synchronizes the working copy to the revision given by the --revision option.

How do I pull latest changes in SVN?

Simply type svn update [name-of-directory] , or cd to that directory and type svn update there.

Does GitHub work with SVN?

GitHub repositories can be accessed from both Git and Subversion (SVN) clients.

What is the purpose of an SVN Subversion repository?

SVN stands for Subversion. So, SVN and Subversion are the same. SVN is used to manage and track changes to code and assets across projects.


7 Answers

The export can be automatically done after every commit with a post-commit hook:

http://svnbook.red-bean.com/en/1.5/svn.ref.reposhooks.post-commit.html

You can setup the hook to automatically export the project inside the hidden area for the online testing.

like image 186
Davide Gualano Avatar answered Oct 15 '22 18:10

Davide Gualano


I wouldn't recommend checking out your code to your production server. This can potentially expose svn control files (.svn) on the server.

I would recommend using a script (python, ruby, etc.) combined with the command line svn and FTP client to export the files from svn and ftp the files to the server. The svn export command can be used to check out a set of files from the svn server without all the .svn directories. Also, don't forget to tag the svn repository when doing this so you have a checkpoint of what you have deployed.

like image 23
Ken Liu Avatar answered Oct 15 '22 18:10

Ken Liu


We deploy via Subversion and use database migration tools (with schema versioning) to do this.

(http://blog.lavablast.com/post/2008/02/I2c-for-one2c-welcome-our-new-revision-control-overlords!.aspx)

(We develop in .NET)

like image 33
Jason Kealey Avatar answered Oct 15 '22 19:10

Jason Kealey


What about checking out the code to place where you want to run it from?

like image 23
sebagomez Avatar answered Oct 15 '22 18:10

sebagomez


Code version management and database version management are two very different problems. The solution that I prefer is done in three stages (Test, Deployment Test, Live) rather than two.

  • Update the code and apply database changes via scripts in the development environment
  • Download the live database to a deployment test environment, restore it and apply the change scripts
  • Test the code against the 'synchronised' live database
  • Update the live environment via svn from the relevant branch on the repository (we do it via ssh tunneling since it's a linux environment) and apply the change scripts to the live db

Edit: The update for the live environment is best done using export rather than checkout/update. This doesn't leave svn's control file hanging around. This may or may not have security implications, it does force you to specify which branch you're checking out each time though.

Your 'one click' could probably be scripted for the last step.

like image 35
Bell Avatar answered Oct 15 '22 20:10

Bell


If you install the Subversion command line client, it's quite easy to make a batch file/shell script that will do a checkout export of the latest revision from the repository to a folder on the server. This requires that you have the same file structure in Subversion as you do on the server though (unless you want to add the logic to change the structure in the script, of course).

like image 33
Anders Sandvig Avatar answered Oct 15 '22 18:10

Anders Sandvig


I recommend that you write some sort of script that does this for you. Whether you do this with PHP or something else is up to you. Just keep security in mind when you do this.

Doing an export of your project won't export any svn:externals you might have set which means you need to do multiple exports. When you script this it shouldn't of course being much of an issue. Another thing with exports, if you project is large (if you use lots of video, PDF's etc.) then an export can be quite cumbersome, especially when your version control is hosted off-site and only available through HTTP.

I recommend you do a checkout and make sure that your server can't serve any files located in the hidden .svn folders.

like image 43
Luke Avatar answered Oct 15 '22 18:10

Luke