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