How to Deploy a Rails Application7:22 with Jim Hoskins
In this video, we deploy our application on to Heroku, and look at what other steps must be done to get the app up and running.
[?music?] 0:00 [Master Class: Designer and Developer Workflow] 0:02 [Fourth Sprint: Deploying the Application] 0:04 [Jim Hoskins] So now we've updated our application, 0:07 hopefully, in order to support Heroku and Postgre, 0:09 and we've updated our repository, 0:12 so now we should be able to create our Heroku application. 0:15 So the way we do this is pretty simple. 0:19 We'll be using the Heroku Gem that we installed and the Heroku command 0:21 that was installed along with that. 0:25 You can see if the Heroku command is installed properly by just typing in $heroku 0:27 and this will give you some usage. 0:32 So in order to actually our application, we're going to be inside of our Easy Jobs! directory 0:35 where our Git repository is. 0:40 We're going to use the $heroku create command 0:43 and we're going to use the stack flag by using --stack 0:47 and this is because Heroku offers different environments in which to deploy our application. 0:52 You can learn more about stacks in the Dev Center 0:57 and there are 3 different stacks available right now: 1:01 Aspen, which runs the MRI Ruby interpreter, version 1.8.6; 1:05 there's the Bamboo stack, which runs the Ruby Enterprise edition 1.8.7 1:11 as well as the Ruby 1.9 Interpreter; 1:16 and then there's the newest one, Cedar, 1:20 which only runs Ruby 1.9.2 as well as supports other platforms like Node, Closure, and others. 1:23 Cedar is the newest one and it's the one that we'll be using. 1:33 But this means that our application needs to be able to run on 1.9.2. 1:36 Since we're using Rails3, this should not be a problem 1:41 because Rails runs fine on 1.9.2, 1:43 but depending on the code you have installed, you need to make sure 1:47 that your entire application will run on 1.9.2 if you decide to use Cedar. 1:50 So we'll specify that in our command by doing - - stack cedar. 1:56 Now, since this is the first time we've used Heroku on the computer, 2:02 we need to add our credentials by just typing in our email address 2:05 and password that we used for Heroku. 2:10 I will do mine. 2:13 So it's done a few things. 2:21 It took my email and password, 2:23 and then it needed to upload my ssh key. 2:27 Now, you'll remember when we set up for GitHub, 2:30 we had to give GitHub our ssh public key in order to allow us to push 2:33 to the repository and authenticate. 2:37 Heroku did this automatically by searching for our public key 2:40 and uploading it automatically, so we didn't have to do anything. 2:43 The final 3 lines are actually creating the application. 2:47 By default, it will give our application a name and a number; 2:50 in this case, deep-meadow-7939. 2:54 We can change this fairly easily, but right now it's going to be hosted 2:57 at deep-meadow-7939.herokuapp.com. 3:01 Finally, it added the remote repository for Heroku to our git project, 3:05 so if we take a look at $git remote, we now have two remote repositories: 3:11 heroku and origin. 3:17 Origin is our GitHub repository and is the main repository we'll be usinig for development 3:19 and when we want to launch our application, 3:25 we will push to the Heroku repository, which should launch our application. 3:27 So let's clear all this out 3:33 and let's try to deploy our application to Heroku. 3:35 This is as easy as doing $git push 3:38 and then the name of the remote that we want to push to, which is heroku 3:41 and the branch being master. 3:44 So since this is the first time we're connecting to heroku, 3:50 we need to establish that this is the proper server to connect to, 3:52 so let's just type in yes. 3:57 And now it begins receiving our application 4:02 and building it and hopefully deploying it. 4:05 This is where we'll see any build-time errors that we will need to fix, 4:08 and it looks like it launched without any problems. 4:20 Let's take a look at the output here to see exactly what Heroku is doing. 4:23 So the first chunk of information here is just the $git pushing of our data, 4:28 so this is all the data that was pushed to the remote repository. 4:32 All of this is what Heroku did after it received that data, 4:37 so it saw the push, did a little bit of cleaning to remove ds store files 4:40 that OS X puts in the repository. 4:44 It noticed that we're using Ruby on Rails 4:47 and it begins installing dependencies. 4:51 You can see it ran bundle install without development and test. 4:53 These are the groups that we used to specify SQLite, 4:57 so it did not install SQLite into the environment here, 5:01 so we can see the output that we would normally see from bundle install. 5:08 So here's where it ended our bundle install. 5:14 You can see it overwrote our database.yml to use the database that Heroku provides. 5:16 It added some plugins that will allow us to manage our application through Heroku 5:23 so we don't have to worry about it. 5:27 The next thing we did is it says discovering process types. 5:30 Now, normally, when installing an application on the Cedar stack, 5:36 we would have to define exactly how to start up the application, 5:39 but since we're using a Rails project and Heroku recognized that, 5:42 it will create a Procfile which defines how to start up our application automatically. 5:46 And now we can see it compelled a slug of 13.9MB. 5:52 This represents our app. 5:56 Right now, it's going to be running on a single dyno or a single instance. 5:59 However, one of those features of Heroku is we can increase that easily 6:03 by just changing the settings. 6:07 This will launch more instances or more dynos of our application 6:09 and it does that by just taking a slug 6:12 and applying that to its server resource and that brings up 2 or 3 or 4 dynos 6:15 or instances of our application, 6:20 which is then able to route more efficiently. 6:23 So our entire application, when compiled together, takes 13.9MB. 6:25 Finally, it takes that slug and it launches it. 6:31 As you can see, it's launched at deep-meadow-7939.herokuapp.com. 6:34 So if we go to this URL, we should see our application. 6:41 Now, right now, our database is empty, 6:44 so if we open this URL, we should be able to see our application. 6:47 However, since it's a new deployment, our database will be empty, 6:50 so we'll see exactly what that looks like. 6:53 So we could either manually type in this URL, copy or paste it, 6:56 or we can use the Heroku open command, 6:59 which uses the application that you're currently in, figures out its URL, 7:02 and opens it in a browser. 7:06 So $heroku open 7:10 and we get an error. 7:14 This isn't unexpected. 7:17 Oftentimes, this happens our first time, so we'll debug this in the next part. 7:19
You need to sign up for Treehouse in order to download course files.Sign up