Deploy static assets only to a web server with separate app server
Using Rails 3.0.7 and git, deploying with capistrano. I'm using different machines as web and app servers. I cannot deploy the application code to the web server, only the static assets--basically the public/ folder.
This would 开发者_StackOverflow社区seem common but no luck searching for a best practice.
Is anything build around capistrano to handle this case? Otherwise I'm thinking that adding tasks to create the structure, but scp
the public directory from the app server would be the solution.
So I assume there's a business reason you can't deploy the app to the other server?
If there isn't then just deploy the whole code and configure your web server to just serve the public folder.
(in Apache/Passenger the configs would be exactly the same, you just wouldn't enable passenger on the static server)
That is the only simple way to do it.. otherwise you're going to cause yourself a load of headaches..
Nevertheless I'm going to make up a way to solve this.
If you do need to deploy just the static code then I suggest you create two repositories
- the app (eg. git@myserver:app.git
- the static files (eg. git@myserver:static.git)
Now in your app include git@myserver:static.git as a submodule mounted at public/
Having done this, you should search standard capistrano recipes for deploying with git submodules (in particular I guess you'll want to store a local cache of the submodules, update it, then git submodule init
somehow with that)
You can then have two capistrano recipes
I suggest you check out capistrano multi-stage... defining app and static as two stages
You can therefore just specify git@myserver:app.git as the repository for "app" and git@myserver:static.git as the repository for "static"
then a simple cap app deploy:migrations && cap static deploy
should do it.
but remember these will not be simultaneous
I too wish there were more established practices published. We've done ours based on the Django book which recommends making your public app directory a networked directory.
This is much better as scp only works if your public directory is static. Many apps will write things to the public directory, e.g. image generation on-the-fly. These files also need to be copied to the web server immediately.
I recommend using a NFS, Samba Share or similar, so that your public directory is actually just a networked folder, so when you write to it, it's like writing to the remote folder.
To integrate it into capistrano we do the following: create this networked folder in shared/public
After deploy:update_code: move content from current/public to shared/public (overriding files as needed) remove or rename current/public then symlink current/public to shared/public
Downsides: * doesn't remove old files (like someone earlier said) * no real rollback option (apart from redeploying older version)
Best approach I've come up with is to in fact scp files over to the web server.
精彩评论