Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  • Overview
  • Transcript

3.3 Using the Heroku CLI

Heroku really shines with its full-fledged command-line toolbelt. In this lesson, you’ll learn a couple of the most important commands that can be used to support your deployed applications.

Related Links

3.3 Using the Heroku CLI

So far we've been using a couple of commands available in the entire Heroku toolbelt. The whole set of features is quite numerous, but I want to focus on a couple more because I think they deserve an honorable mention. And I think they're very important in the overall process of handling your app and production. The first thing that she should do is type in the Roku command with no arguments whatsoever. There's a bunch of functions. They're related. Either to your app or to your account. For example the off command. Allows you to authenticate into the Iraq a server. And this will give you access to your applications, to your settings, and stuff like that. Now, the first command that I want to share with you is the Heroku status method. This command will show you if the Heroku servers are running okay or not, if there any issues at one point in time or not. You most likely want to use this for example periodically. Every single day, or when you know there's some issues, and you want to keep tabs with it's status. This might come in handy in one way or another. Now, another command that I want to show you is the heroku run command. This run command will basically run something in the shell that lives in your application. It is hosted in a Linux environment on its own, and because of that, you can run commands on it. If you type bash, for example, it is going to run a Linux shell on top of it. So, just wait a little bit until the problem comes up, there you go. I can type ls for example, and I will get the list of all the files and folders inside the application folder. It can pass in multiple options as well. So if I type in ls-la I will get every single thing available in the rails application folder. This is definitely not emulated or anything, it's the real thing. You're actually running a bash shell inside your project folder. The same way you can type in standard Linux commands, you can type in for example, the rails console. If you type in rails console inside the bash terminal, you will get the production environment being loaded, in which you can perform some operations. For example, if I want to, I can list all of the projects. As you can see, I only have one. But that's okay. This is just to make sure that you know you can resort to the actual data in your application, via this command. Now, I've shown you how you can run the console command under a bash terminal. But there's actually a way to run the console without calling the bash terminal right away. You can just type in heroku run console, and this will load the same thing as we did seconds ago. Again, just with a little bit until the prompt is loaded and you can type in the same kind of information in Ruby. There's your data. Aside from the console and bash commands, as I mentioned you can run anything. Let's say you have migrations you need to run. So, just type in run rake db:migrate the same way as you would do in development. So type in that. And you will see. Information on that specific note. There you go. We have information on the schema migration and everything. So regardless of what command you want to introduce you want to make sure it plans. Just type in Heroku run and the command. Rembemer that you can always reach out for help using the Heroku help command. With the definition of the sub command you want to get help from. For example, Heroku help run will give us a list of options for that specific run command. Another particular feature that I find interesting is the one called Heroku releases. This command will provide you different versions of the application. As you can see, I have six different versions and five of them were deployed at the moment of the first one. So I have the initial release with locking capabilities set up. Then with all the variables inside, the databases attached to the application. The deploy is performed by the commit that I specified in the branch. And finally I have this specific version that was deployed when I set the config variable with SMTP user. Remember that for each specific variable, a new deploy is processed. If I were to set all three variables around the SMTP settings, I would get three specific deploys. The remaining commands in the tool belt are available by typing Heroku with no arguments. There's a bunch of different commands you can use in order to retrieve, or manage different aspects of your app. For example, the stack command allows you to manage your application stack. Let's type that in right away, heroku stack. You will see that the stack that I'm in is called cedar-14. But you can choose to manipulate the stacks in any way you like. This is just one of the commands. There are many others around for example, managing collaborators on an app, to invite additional people to handle the production environment. Checkin the list of applications and your account for to reparse atry, for example if you want to test it out in the fall of man authentication keys. Enable maintenance mode this is actually quite useful sometimes when you want to have a large stand of time to perform some operations. You might want to have to enable maintenance mode in order for your users to know that you're under some serious operation. More information on the Heroku toolbelt can be read in the link that I've provided in the description below. The toolbelt has loads of options, and little configuration tweaks for each different command that you should know about.

Back to the top