Pushing from subversion to web server

2020-05-17 08:37发布

问题:

Long ago I tried to sort out my system between local, web server and subversion. I got some good explanation on this question.

Unfortunately I hit a road block on the whole pushing from SVN to a web server part and never revisited. All of my projects are solo, so I'm the only one developing them and often I'm the only user. So I've been able to get away with writing directly to the live server most of the time.

For 2009 I want to break that bad habit and actually do things the right way. I have SSH access to my web server (I can login and browse the files) but don't really know what to do in order to get the newest files out of SVN, into the server.

I've googled my fingers to the bone but everything I find requires some set of knowledge that I don't yet have.

I'd really, really appreciate step by step directions of how to automatically push the newest version of my code from an SVN repo to a live web server. FYI I'm currently using Beanstalk for Subversion hosting, but am totally willing to change that if someone has a better suggestion.

Thanks

回答1:

If you have SSH access you could do:

svn export [url to repo] [web directory]

Export will mean you don't get the .svn baggage that comes with a working copy.



回答2:

simply - login to your server machine and checkout the repository contents. This should be done just once.

$ svn checkout [http|svn|whatever_you_got_there]://{your_svn_repo} {checkout_directory}

Everytime you need to update your working copy with the newest one, perform update:

$ cd {checkout_directory}
$ svn update


回答3:

Release Management

you can create an job/batch which exports the svn to a local folder. after the export you can upload it with rsync.

the job can automatically execute by the svn hooks.

you can also use mtod ways but keep in mind: using a checkout on the server is a security risk, if someone can access the .svn folders! they can access the php code and see passwords or bugs.



回答4:

Unless your hosting company has given you access to either cron(1) or a shell, it will be difficult as svn, a centralised VCS, does not have a way to push things to a working directory, you are supposed to svn update.

Several ways to do what you want, depending on the above mentioned resources available:

  1. define a crontab(5) entry that does cd $WEBSITE && svn update
  2. use ssh to connect to your website and do the same command. The ssh can be automated by a crontab entry on your side.
  3. have a special cgi on your website, hopefully protected by password, that could be run periodically (from cron on your side) that does the same command.

Best way to me will still be moving to a decentralized VCS (like Mercurial or git) but that is a much bigger project.



回答5:

I had a somewhat similar question some time ago, however I didn't have SSH access into my server so I was quite limited in my options.

Depending on the size of your project you might consider not doing an export. In my case the project was over a gig of data! Not practical because with an export you need to export all the files over and over again. If you only have a hand full of files it might be different. Also, doing an export on your local machine means that the export needs to download the file first and then upload it to your hosting which is like a waste of bandwidth.

Also keep in mind that doing an SVN export doesn't do any database updates. E.g., while you're developing your site your database will probably change may times. With just an SVN export you still need to manually re-import the database on the server.

What I suggest is that you write a script that you place on the server. You can make this script as elaborate as you want of course but the bare bone script would do an 'update' on a checked out version of your site, does an export of your database in a temp folder (your database is of course also placed under version control) and re-imports the database (or merges it, whatever it needs to do). With one single command you can then deploy your site. Over and over and over again.

There are tools that can help you with this sort of automation, like CruiseControl and Capistrano.



回答6:

have you tried using our FTP deploy on Beanstalk? We also have web-hooks available, which means you can ping a URL on each commit to code your own stuff.

http://help.beanstalkapp.com/articles/17-deployment-and-releases



回答7:

You say 'automatically push'. This can be accomplished with a post-commit hook. I've been a one-man dev crew and use a set up like so for PHP dev:

VPS LAMP stack with Apache's mod_dav_svn handling SVN duties hosting a 'staging' version of the site. The 'staging' version of the site was actually a working copy, just checked out locally, to a directory that Apache could serve from

local VMware machine running NetBeans and LAMP stack, with xdebug installed for debugging PHP

My workflow went like this:

Check out a working copy from my VPS to my VMware virtual machine Get a database dump via PhpMyAdmin from VPS and import into MySQL on virtual machine dev my ass off, all locally at the end or day, export my database and upload it to MySQL on the VPS commit my changes to the VPS

The crux was the post commit hook - all it is, is a text file in SVN that is parsed after every commit event. You have it call a shell script, and that shell script does a 'svn update' to update the working copy that is your staging site that Apache is serving.

I suppose you could as easily have the shell script do an SVN export to your staging directory, but that might take awhile to run, whereas an update to a working copy just puts changes.

These notes are pretty jacked up, but they're my personal cheat sheet I use when setting something like this up:

http://random.siliconrockstar.com/dev_ShellScriptingAndNixAdmin/SVN.txt

If you want, I also have a copy of the VM with NetBeans all configured that I use for development, I used to hand them out to junior devs. If you want a copy just PM me.