I am working on an Opensourced project I want to create, deploying to a VPS.
I'm working with Rails 4 and Capistrano 3 on Ubuntu, both on the local machine and the server.
I have a configuration file named "application.yml" that includes basic information about the application, as a Google Analytics script, the application name, Mailer configurations and such.
I want to create a task that would rename "application.example.yml" to "application.yml" before Capistrano runs deploy:migrate.
I wrote the task below and put it in config/deploy.rb:
before "deploy:migrate", "configure:application"
namespace :configure do
task :application do
run "#{try_sudo} cp #{current_path}/config/application.example.yml #{current_path}/config/application.yml"
end
end
(I know cp copies the file but it also renames so it is fine.)
It does not seem to work. How can I rename "application.example.yml" before deploy:migrate runs?
GitHub Repository and deploy.rb
Also as I am moving forward with my App I seem to find more and more stuff I know little or nothing about, and would love it if someone experienced with Rails would be willing to become my "Mentor" by sharing with me his Skype (or any other communication service) so I could occasionally ask him my questions.
Related
To give you some context, I'm trying to use Figaro to safely add in environment variables without having to worry about security risks. The problem is is that I can't seem to get Engine Yard to play nice with production.
I went and did a touch application.yml and then vim application.yml, i, and then command+v to insert that api keys and what not. I know the ENV['VARIABLES'] work because of development and all my rspec and cucumber tests (which utilize the APIs), passed.
When I've got everything ready, I add within the .gitignore:
# Ignore application configuration
/config/application.yml
Afterwards, I deploy the site. I open it up and data isn't going to the APIs anymore. OK...
cd into config and discover application.yml isn't there anymore. Paste it back in... Redeploy the site since now it understands it has to ignore that file and I'm not seeing changes on production. Check back... and its gone again!
Stumped on what's going on.
Simply putting a file into your deployed application's filesystem will not work because you get a clean environment each time you deploy. EngineYard cannot know that you want that particular file copied to that particular location without a little bit of extra work.
Their official recommendation is to put your YAML configuration files in /data/<app>/shared/config and symlink them to /data/<app>/current/config each time you deploy using deploy hooks.
In rails 3.1 I was able to put a symbolic link to a directory of html pages in my public folder and it worked. Now in rails 3.2 it gives me a 404 not found page when I try to open any of those html files. What changed in rails 3.2 that now blocks symbolic links and how can I get around it?
To clarify, I have a friend who wants to save money by having his site hosted off mine. So when I deploy his site should be accessible at http://mysite.org/hissite/. He has an account on the same server as me so I just create a symbolic link to the directory hissite which is located in his account. I put this symbolic link in my public folder. Prior to upgrading to rails 3.2 this worked like a charm. I can use a hard directory but this would be on my account requiring him to send me updates which I would then have to post. This is a big hassle. It is important for me to allow him to host his content with my site as it is related content and helps bring more visitors to my site.
More details:
The problem is with my production site which is using passenger. In development, I tested it with a symlinked directory on my development machine and it worked fine. Hard links seem to work in production but then I have to update the directory whenever he adds new files which is a hassle.
Well I figured out a hack to get it to work but it is not what I would like. I wrote a capistrano task to link the files whenever I do a deployment. So my capistrano task looks like this.
namespace :accounts do
desc "Relink friend's site on each release"
task :relink_friends_site, :roles => :app do
run "mkdir -p #{release_path}/public/hissite"
run "cd #{release_path}/public/hissite && ln /home/hisaccount/hissite/index.html"
run "cd #{release_path}/public/hissite && ln /home/hisaccount/hissite/page2.html"
...
end
end
If anyone knows a better way to fix this please let me know. At least this way I don't have to relink the files myself foreach deployment.
I have started developing a new Rails app on my server using RVM, Rails 3, & Ruby v1.9.2. I am using Git as my code repository. It's a simple app and I don't want to use an extra server. I just want to deploy my app directly from the same server I am developing on.
I've installed Phusion Passenger w/ Apache to serve my app, but have realized that I can't do that pointing to my development directory as my RAILS_ENV is set to "development". (I found I got file permission errors on the asset pipeline and other issues when I attempted to set RAILS_ENV to "production" and serve the app)
What's the simplest/easiest way to deploy the app? Can I simply:
1) Create a separate user to run rails production (Rails in dev currently runs as me on my Ubuntu server)
2) Clone my repo into a separate dir and configure Apache accordingly
3) Seed my database with the data needed for production (not much data needed here)
4) What else?
I've looked briefly at Capistrano, but it seems like overkill for this simple app. I only need to be able to provide a simple web interface for some data entry. Seems like git push should be sufficient, but I haven't done this before so maybe I'm wrong? Also, if I git push how do I ensure file permissions in the "production" directories are all set properly, particularly for any new files that get created in the originating app directory structure?
Thanks for any ideas.
No- you do not need Capistrano for the above; at this stage I feel it will only serve to confuse you further.
I'd suggest you first save your repo to a private Github or free BitBucket account. What you should do is keep one folder for 'development'.
Remember that Passenger is 'just' a module working with Apache. So what you need to do is setup a virtual host under apache and direct that to another folder on your system. For this example, consider:
~/rails/myapp_development/ and ~/rails/myapp_production/
Passenger always runs the app in production, so that should not be an issue. You can do bundle --without=production in your development setup to ignore any gems listed in the Gemfile under the production namespace, i.e. say you've got the mysql adaptor specified, you can ignore this and have Rails only rely on the SQlite gem.
You can now simply develop in the development folder, commit, push to BitBucket. Deploying will be as simply going into the production folder and doing a git pull and touch tmp/restart.txt.
I have a deployed Rails application that I'd like to use with Hoptoad (an online exception notification service). It comes packaged in a gem that I installed on my deployment server, but I need to run the script/generate hoptoad every time I deploy to configure it because the Hoptoad config files/changes exist only on my production application (and not on my development, so when I deploy, they all get erased).
Is there an easy way to run that script/generate on the production server every time I deploy? I feel like you could do this with Capistrano tasks, but I don't know how to do that.
What do people usually do for this? Sorry if this post is a little hard to understand, I'm not quite sure how to explain the issue.
Thanks!
You can add the Hoptoad configuration file to your source code repository so that it gets deployed as part of the Rails application.
Alternatively, if you don't want that information within your repository, then upload the config file to your production server (outside of Capistrano's normal releases directory structure) and have Capistrano create a symbolic link to it as part of the deployment process. I provided an answer to a similar question here which should give you the idea.
I'm looking at ways to deploy a Ruby on Rails app (running on JRuby) to a Tomcat instance for testing.
The tomcat instance is running on a Solaris server that I can SSH to. I've looked at using Capistrano, but there doesn't seem to be a lot out there about using it to deploy to Tomcat, or even about running it under JRuby, and I keep hitting bugs in Capistrano due to the Windows/JRuby environment my PC is running (yeah, it's corporate - not my choice, but I've got to live with it).
I'm using warble to build the .war file, and the app deploys and runs fine once I manually copy it up and deploy it. I'm wanting something easier and more automated to actually get it there.
Anyone done this before? Documentation on the web seems pretty thin.
I am running a Rails project using JRuby and deploying to a Tomcat server. I have chosen to deploy with Capistrano because it automates just about everything. I had to make a few minor modifications to Capistrano's deployment lifecycle in order to get it to run on Tomcat:
Step 1: I created a warble task to be run on the server after Capistrano updates the code:
desc "Run the warble command to deploy the site"
namespace(:deploy) do
task :warble do
run ". ~/.profile;cd #{release_path};warble"
end
end
And hooked it into Capistrano lifecycle using:
after 'deploy:update_code', 'deploy:warble'
My Tomcat server has a symlink pointing to the #{release_path}/tmp/war directory created by warble. If you don't like this, you can easily modify the warble task to move the war file into the Tomcat directory instead.
Step 2: I overrode the deploy:start and deploy:stop tasks so that they kick off the Tomcat server instead of a Mongrel server:
desc "Starts the Tomcat Server"
namespace(:deploy) do
task :start do
sudo "#{tomcat_home}/bin/startup.sh"
end
end
desc "Shutdown the Tomcat Server"
namespace(:deploy) do
task :stop do
sudo "#{tomcat_home}/bin/shutdown.sh"
end
end
I run Capistrano tasks using MRI rather than the JRuby interpreter.
I don't have much experience on this, so I don't know if I can give you the BEST way, but if Capistrano doesn't work, and you can't have a separate MRI install just to run it, you have just a few alternatives left:
Try running plain Rake and write your own deployment target:
http://www.gra2.com/article.php/deploy-ruby-on-rails-applications-rake
Or use Ant or Maven.
Or if it just ONE server you have to deploy to, you could just hack together two Ruby scripts - one that listens on the server for shutdown/startup requests, and one local that you run to: Send shutdown, scp over the file, send startup.
By the way, have you submitted any integration bugs you find with Capistrano to the JRuby team? I'm sure they'd be happy to have any contribution.
:)
Might be worth looking at 'Vlad the deployer' it adds remote_task to Rake allowing you to run tasks on a remote server. Personally however I prefer to have a standard Rake task on the server, ssh in and run that task - which would then do an svn checkout, make the WAR file, whatever...
I would probably use Ant for this. After all, it's just another WAR file, right? I don't know which version of Tomcat you're using but version 4.1x comes with an Ant task for deploying to Tomcat.
There's a few Capistrano recipes for deploying to Tomcat -- I built one into a gem called capistrano-tomcat. It takes a WAR you've built (probably with Warbler) and deploys and starts a Tomcat instance on a remote server.
The source is up on Github: http://github.com/rhunter/capistrano-tomcat