Heroku is a cloud platform that helps you build, serve, monitor, and scale your apps, allowing you to expedite the process of getting an idea and getting it up and running. It also frees you from infrastructure management issues.
-Excerpt from Official Form Page
Supplementally, Heroku is a PaaS (Platform as a Service), which means that developers can distribute and operate applications if they concentrate only on application development. Since it is linked with GitHub, it can be deployed to git just by pushing, so it is a suitable platform for CI / CD. Currently, it supports languages such as Node.js
, Java
, PHP
, Go
.
Heroku-CLI is a tool that makes it easier to work with Heroku apps on your terminal. You can download it here [https://devcenter.heroku.com/articles/heroku-cli). (** Please install git in advance. **) Please install according to your OS.
heroku login -i
The -i
option means "log in inside the command". Without this option, your browser will open and you will be logged in with your browser.
After logging in, move to the directory you want to create with the Heroku app and launch git with git init
.
If you don't have an existing source, you can clone the Heroku tutorial code at the link below.
Node.jsJavaPHPThe app is automatically generated on Heroku with heroku start
. In this case, the app name will be randomly generated so you can change it later or create the app first and clone it with heroku git: clone -a [app name]
.
Let's raise the code that outputs "hello world" in PHP and Java.
PHP
index.php
<?php
echo 'hello world';
Java
DemoApplication.java
package com.example.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@SpringBootApplication
public class DemoApplication {
@RequestMapping("/")
@ResponseBody
String home() {
return "hello world";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Heroku is a web application, so you can't just look at it with System.out.println ()
.
I think it's better to use a web framework such as Spring.
git add . git commit -am "commit message" git push heroku master
You can push the source to Heroku with the above command.
The heroku open -a [app name]
command will open your app in your browser.
You can also check it with the "Open app" button on the Heroku form page.
We've introduced how to easily deploy to Heroku. I think that serverless and cordless are steadily coming, so I think that wearing cloud services such as Heroku and AWS Elastic Beanstalk will be a great strength in the future. Thank you for visiting
Recommended Posts