Deploying Rails to Elastic Beanstalk, nodejs? - ruby-on-rails

I want to host my app on a VPC EC2 instance with AWS, and this line in the documentation has me somewhat confused:
Install nodejs to allow the Rails server to run locally:
$ sudo apt-get install nodejs
I was just wondering why I need nodejs at all, let alone to allow the rails server to run locally since i thought that this was already handled by WEBrick.
Heres a link to the documentation in question:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby_rails.html

Rails uses a Javascript runtime for certain tasks (generating scaffolds and compiling templates among others). You do not need to use nodejs, you can add other runtimes as gems in your Gemfile, e.g. therubyracer, therubyrhino. (YMMV on EC2, if it suggests using nodejs, I would install it unless you have a good reason not to)

The title of the question is unclear. Elasticbeanstalk uses EC2 instances but you should never ssh directly into an EC2 server to make changes.
Elasticbeanstalk will destroy and create EC2 instances to scale with the web traffic coming to the application. Making changes to one particular instance will not guarantee it will make the changes for all of the EC2 instances belonging to one Elasticbeanstalk application.
Also that particular instance can be destroyed when deploying, or rebuilding or when the app scales back down.
If you're using the Ruby platform on Elasticbeanstalk you'll need to use their builtin in EB extensions to either run a command to install node or use the yum package manager to install it.
Here's documentation that describes the yum method:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-packages

Related

Dokku error /var/lib/dokku/plugins/available/pg-plugin/plugin.toml: no such file or directory

So here what I did and the following output:
root#ubuntu-512mb-sfo1-01:/var/lib/dokku/plugins# dokku postgres:link DATABASE ubuntu-512mb-sfo1-01
2016/02/18 05:24:38 open /var/lib/dokku/plugins/available/pg-plugin/plugin.toml: no such file or directory
2016/02/18 05:24:38 open /var/lib/dokku/plugins/available/pg-plugin/plugin.toml: no such file or directory
no config vars for ubuntu-512mb-sfo1-01
Can someone help me? I try to deploy rails to digital ocean.
I use http://blog.flatironschool.com/using-digital-ocean-and-dokku-for-easier-rails-app-deploys/ - this tutorial but it seems to be horribly outdated. I ran into so many errors so I am thinking of giving this up and staying with heroku hosting.
It means that you don't have a Postgres docker container active. Take a look at the dokku-pg-pluging to know how to configure and instantiate a postgres docker container.
By the way, since your objective is to change from Heroku to DigitalOcean, and you're having trouble using dokku, may I suggest you using deploy bot instead? I did managed to successfully deploy an rails 4 app to DigitalOcean using deploy bot. Follow this tutorial. And you can easily follow this guide with deploy bot, adapting the unicorn and nginx stop/start services with the hooks that deploy bot provides.
Edit:
Since you wanted a more specific answer for the deploy bot solution, here goes my approach (this was +/- 3/4 months ago):
Create the droplet and follow the guide to create a droplet, install ruby, rails, unicorn and nginx and the script to control unicorn (it's in the tutorial).
Configure the deploy bot and make sure you run bundle install and another rails' specific commands (changing environments and so on) after the upload (this is a predefined hook).
The last command should be service nginx restart to restart the server (using the script from step 1).
Profit!

Ruby on Rails app : from Heroku to a local server : what are the main steps?

My Ruby on Rails app (basically a commenting and voting system) has been deployed and currently runs on Heroku. I need to deploy it on a local server to ensure an optimal performance for a customer-organized event in a location where the internet bandwidth is too low and unpredictable to support the 100+ simultaneous users.
Just as Ruby, Rails, Javascript, JQuery, AJAX and CSSs were new to me a few months ago, going local is something new I need and am eager to learn (which should also allow me to deploy onto a dedicated or virtual private server if needed).
The following elements are obviously on the way : choosing an operating system, installing Ruby on Rails, a web server, a database engine and deploying my app code and data of course but I need help to make sure I do not forget anything and really understand how all of these elements must be tied together to get my app running.
At a reasonably high level, starting with my app code, could you please share your experience and tell me the steps I need to take from scratch to have it run on a local server ?
If you have a Mac, then you're already most of the way there. I do all of my Rails development on OS X. The steps from there are pretty easy.
Install Homebrew. This will help you quickly install any dependencies on the Mac that your Rails app needs (such as a database). Since you're on Heroku, you're likely using Postgres. So with Homebrew, you can install Postgres via brew install postgresql.
Copy your app code somewhere that makes sense. I have all my apps inside my ~/Projects directory.
Recommended: Install RVM. This will help keep gemsets unique to projects and keep your global gemset clean.
If you're using bundler, do bundle install within your app's directory.
Within the app directory, do: rake db:setup (Note: This may require prepending bundle exec)
Start your server. I tend to use Unicorn (see Heroku's deployment with Unicorn for even more details), so this would just be unicorn. Else, rails s works as well.
Those are the high level steps to get a local server running.

What, where and how to upload Ruby on Rails application files to the VPS?

I am using Ruby on Rails 3.0.9 and I would like to publish my web site. I already set my VPS running Ubuntu 10.04 LTS and the capistrano gem (this one I think as well as possible). Now, what I need to do is to upload all files to the www/project_name directory (I am on Mac OS)...
What I have to do to accomplish that?
You don't need your deployment machine to have Capistrano. Capistrano automates a bunch of tasks that I suggest you do at least one manually so you know what's going on. Sooner or later, you'll be debugging some Capistrano task, so you may as well figure out the guts sooner or later.
Coarsely, what you need to do is to basically duplicate your development environment on your production machine. If you have it on version control, you can git clone or svn whateveritis on your production machine. If not, you can scp it over with scp /local/rails/dir remoteuser#remotehost:www/projectname.
At this point, you should actually do the remainder of the work on the server. Since you've managed to install Capistrano, I assume you're familiar with the basics of making your way around SSH.
Once the code's over, you have to install the prerequisites. If you're using 3.0.9 you should be able to run bundle install --deployment, where the deployment flag basically tells bundler to use the identical gem set as on your development machine.
When that's done, actually getting the server online will vary based on your setup. If you're using non-standalone passenger, just follow any of the many guides at this point. If you're running standalone passenger or thin or unicorn or any other standalone rails server, go ahead and start that in daemon mode (so it won't quit on you when you end your SSH session) and make sure you se the production flag. You can either start it in sudo and have it listen on port 80 (e.g., sudo thin start -d -p 80) or have it listen on a higher-number port and use a reverse proxy on your WWW-facing server. The instructions for how to reverse proxy are all over the internet.
Let me know if you have any questions.
You have half of a deployment solution with Capistrano. Commonly Passenger is used as the other half, which sits on the server and loads your app. To accomplish this, usually, SSH keys are used. There are numerous tutorials on how to set this up. One of my favorites written by Dan Benjamin can be found on his blog Hivelogic.
Edited to provide more begginer info:
Capistrano begginer's guide from the Capistrano wiki.
Passenger Stand Alone Guide from the Passenger website.
Be sure to check out the other guides for the webserver of your choice when you're ready.
These guides will give you the background you need to get a local Passenger & Capistrano deployment going. These guides provide the knowledge you need to get achieve what you want.
Simple and short sample of deployment via SSH http://alexeypetrushin.github.com/vfs/ssh_deployment.html

Is there a linode version of EC2 on Rails?

We really like the idea of hosting with Amazon EC2 and the excellent EC2 on Rails, but our cashflow isn't enough to justify a move to EC2. So we've decided to host with linode. Now we're trying to put together the best Rails server build.
For those that don't know, EC2 on Rails is an opinionated Ubuntu Linux Server image for Amazon's EC2 hosting service. Out of the box, it runs a standard Ruby on Rails application with little to no customization.
So, is there something like EC2 on Rails for linode?
We'd need at least the following:
Ruby 1.8.7
Ruby on Rails 2.3.8
MySQL 5
memcached
Automatically runs hourly, daily, weekly and monthly scripts if they exist in Rails application’s script directory
Local Postfix SMTP mail server
SSL support
Passenger + Ngnix or Mongrel + Apache
32 bit image Ubuntu
With a railsy setup, meaning fast and simple. So, anyone run across anything like EC2 on Rails, but for linode?
I have been using linode for my personal use for a while and I think no matter what, you are probably going to have to get your hands dirty. I kind of like it for exactly that reason, but that is just my taste. They do have stack scripts with some predefined setups. The closest I can find to what you are looking for is a ruby/apache/mysql script that is fairly customizable.
From the script:
Installs a fully functioning, ready to
go stack that's optimized specifically
for your Linode's resources. By
default, it creates a VirtualHost
using the reverse DNS of your Linode's
primary IP.
This installs a stack based on Ruby,
Apache, and MySQL. This also gives you
the options to install gems so that
you can be up and running Ruby on
Rails in no time.
Optionally creates a MySQL database
and user, and assigns that user grants
to the database.
You may use this as an example for
creating more VirtualHosts. Set up
VirtualHosts, install your sites,
point your domains to your Linode, and
you're set!
This script downloads and compiles the
source from Ruby's ftp. Along with
Ruby, the latest version of ruby gems
is installed and you have a choice of
initial gems to install. Rails and
passenger can be used to have a ready
to go Rails server. Once this script
has finished be sure to run
'passenger-install-apache2-module' to
complete the passenger install.
Note that this script may take 1.5 - 2
hrs depending on the gems that are
specified.
All details of this stack script are
logged to /root/log.txt and the stack
script is finish when the line
"StackScript Finished!" is written to
the log file.
You might have good luck talking to their support though, they might have some more secret sauce that I haven't found yet.
Nothing in that setup sounds EC2-specific beyond the name. It appears it is just convenient to use with EC2, because they let you grab a disk image from another account.
You are welcome to create your own StackScript to do this and contribute it to the community. Once a StackScript is written, it can be marked public and used by others. EC2 on Rails has a public GitHub repository from which you can get started, and honestly, I'd love to see things like this ported to the StackScript system.

Deployment on EC2 using poolparty and Chef server

Does anyone have done the rails application deployment on EC2 using poolpary gems and Chef server(not Chef solo). Please share your experiences if you know some blogs or code links(except poolpartyrb.com and related to it).
The poolparty script must be able to launch an selected AMI instance with two EBS blocks(data and DB) use one elastic ip,fetch code repo and install Chef server on selected instance. Or if you have used Chef server for rails deployment please share your exp.
Thanks,
Pravin
How far did you get with your pool party script?
launching EC2 instances is explained in this detailed example
the EBS part is explained in this github issue
to deploy an application from git, use chef's deploy resource
installing chef is done using gem install chef
Maybe you can share what you have and where exactly you're currently stuck.

Resources