A collection of commands that were frequently used on heroku

heroku is a tool that allows you to deploy your app to production for free. It's fairly easy to deploy, so it may be out of place after you've experienced deploying on AWS.

On the other hand, there is a caveat because it can be used for free, and the application deployed on heroku will stop after a certain period of time. In that case, if you use the app again, it will start, but be aware that it will take some time to start.

For example, if you deploy LINE BOT on heroku, there will be a short time lag between sending the text and receiving the first reply from Line. It took about 20 to 30 seconds to experience it.

Although the introduction has become long, there are many commands that I frequently used for such heroku and deployment, so I will describe them below as a memorandum.

① Log in to heroku

$ heroku login

It's literally a command to log in to the heroku site. After entering in the terminal, execute with the enter key. When you enter the command, the following will be displayed, so press the enter key again.

heroku: Press any key to open up the browser to login or q to exit:

Then you will be connected to the net and the screen will be displayed automatically. heroku1.png Pressing the word Log in will complete the login to the heroku site, which will also be noted in the terminal.

https://id.heroku.com/login Alternatively, you can log in directly from the above URL.

② Deploy to heroku

First, execute the following command to create an application on heroku.

$ heroku create <app name>

You can create an app like heroku just by typing the above command. Let's decide the application name enclosed in <> arbitrarily.

After that, you can manage the app on the heroku site as well.

After creating the app, it's time to deploy. Deployment is completed by entering the following three commands in order. Please be patient as the deployment will take some time.

$ git add .
$ git commit -m "initial commit"
$ git push heroku master

The deployment is now complete.

③ Log list display

This is the command that I personally find most convenient.

You can search for the cause of the error and list how heroku behaves in the terminal. The time is also displayed so you can see when and what happened.

$ heroku logs

Use it when you are in trouble.

④ When setting environment variables

Environment variables are set to strictly manage unpleasant tokens when leaked to the outside. The following is an assumption when the LINE BOT environment variable is set.

I mistyped the wording and input command in the controller file and got addicted to the error that the token could not be obtained.

So be careful about spelling mistakes and writing mistakes. If you get stuck in an error, look for the cause in the above heroku logs.

$ heroku config:set LINE_BOT_CHANNEL_SECRET="[LINE channel secret]"
$ heroku config:set LINE_BOT_CHANNEL_TOKEN="[LINE access token]"

I think that environment variables are necessary or unnecessary depending on what you create, so please set them appropriately.

⑤ Stop & restart the app

This command is used when something goes wrong, such as the behavior of the created application is strange.

Stop the app

$ heroku ps:scale web=1 

Restart the app

$ heroku ps

⑥ Delete the app

Unnecessary apps can be deleted from the heroku site. However, that alone remains in the remote of git, so it is not enough for deletion work. Therefore, it is certain to enter a dedicated command from the terminal and delete all at once.

$ heroku apps:destroy --app <app name>

After entering the command, you will be asked to enter the app name again for confirmation, so enter the app name again and continue the process to complete the deletion of the app. With this command, you can delete both apps on Heroku and remote repositories at once.

Of course, there are other commands, but this time the contents were the commands that were frequently used in the process from login to application creation to deployment to deletion.

Recommended Posts

A collection of commands that were frequently used on heroku
A collection of RSpecs that I used frequently
It's just now, but a collection of commands that frequently appear in Rails
Summary of frequently used Docker commands
Frequently used functions and commands of Xcode
Docker Frequently used commands
Generate a unique collection of values from a collection that contains duplicate values
A collection of Eclipse shortcuts that new graduates find useful
A concise summary of Java 8 date / time APIs that are likely to be used frequently
Frequently used Maven command collection
git flow Frequently used commands Memo
Deploy a war file on Heroku
Introduction to Docker (1) Frequently used commands
A collection of phrases that impresses the "different feeling" of Java and JavaScript
[Rails] A collection of tips that are immediately useful for improving performance
A memo that enabled VS Code + JUnit 5 to be used on Windows 10
A collection of methods often used when manipulating time with TimeWithZone of Rails
How to redo a deployment on Heroku
[Rails Struggle/Rails Tutorial] Summary of Heroku commands
Deploy a Java web app on Heroku
Deploy a Tomcat-based Eclipse project on Heroku
[Note] A list of commands that I checked many times after trying Ruby.
A memorandum of making a bot that automatically RTs and automatically tweets on Twitter 4J
[Ruby on Rails] Implement a pie chart that specifies the percentage of colors
java stream A memorandum of intermediate / termination operations that are really often used 1