[JAVA] I tried Heroku, which can publish web applications for free

Overview

I felt that I was a long way behind the times, so I tried to get back even a little, so I tried Heroku, which can publish web applications for free, and summarized when I tried Getting Started on Heroku with Java on the official website & memorandum

[Official website (English)]  Getting Started on Heroku with Java

What you can do when Getting Started is complete

Getting Started Approximate working time to complete

2 hours (I did it while putting it together, so if I just did it, it would be much less impressive)

Reference book

If the English documentation is painful, the only thing about Heroku? The following of Japanese books may be helpful It has the same contents as Getting Started, DB, files, response time at startup, and is full of useful information for beginners. Introduction to Heroku for Professionals Application Development and Operation Using Platform Cloud

My skills

Advance preparation

Below, there is an installation procedure in the procedure

What I did and what I did

Follow the steps on the official website above to complete the following 15 steps You can do it without difficulty if you follow the procedure I'm rather embarrassed to fail twice (described later) ...

  1. Introduction
Preparation contents
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/2c163f96-e7fc-641c-7a5f-d90d06dbd9bc.png)
  1. Set up
Heroku command line installation (git is installed with it)
After installation, log in with the Heroku command
$ heroku login
Enter your Heroku credentials.
Email: [email protected]
Password:

image.png

  1. Prepare the app
git clone the prepared sample program and prepare it locally
$ git clone https://github.com/heroku/java-getting-started.git
$ cd java-getting-started

image.png

  1. Deploy the app
Deploy and launch sample program on Heroku
$ heroku create
$ git push heroku master
$ heroku ps:scale web=1
$ heroku open

image.png

  1. View logs
Explanation of log confirmation method
$ heroku logs --tail

image.png

  1. Define a Procfile
Procfile description
Heroku seems to specify the type of application in this Procfile
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/61e94532-bb9d-2821-6d22-435c5ff5eb2d.png)
  1. Scale the app
Explanation of the concept of Dyno that runs the application and explanation of the above free frame
Dyno seems to be lightweight, secure, virtualized Unix container
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/c28250ce-69e8-7b3b-2416-0e20fb4c71a2.png)
  1. Declare app dependencies
Explanation of pom.xml, system.properties and preparation for operation in local environment
Specify the operation version in system.properties
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/7d82246a-5eab-409b-890a-3fe1a1721d3e.png)
Because the environment variables JAVA_HOME and MAVEN_HOME were added and the setting to PATH was omitted when installing Java and Maven
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Occurrence
Environment variables MAVEN_HOME, JAVA_HOME added, both variables added to PATH solves
  1. Run the app locally
Start in local environment and check screen
Local environment access URL: http: // localhost: 5000
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/3b2fe452-ffc4-d4ea-f724-6f48b134fb9b.png)
  1. Push local changes
Explanation of sample program modification procedure and deployment of modification to Heroku
$ mvn clean install
$ heroku local web
$ git add .
$ git commit -m "Demo"
$ git push heroku master
$ heroku open hello

image.png

git commit -m "Demo" says *** Please tell me who you are.
I was in the state of heroku login, so I thought that it would be linked without permission and tried various things again ...
As a result, heroku login was completely irrelevant, so quietly execute the following command displayed after Please tell me who you are.
git config --global user.email {email address}
git config --global user.name {name}
  1. Provision add-ons
add-ons seems to be convenient, but I realized that credit card authentication is required and skipped
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/0b26b17b-33b8-6a7a-b0cf-a622862e2397.png)
  1. Start a one-off dyno
You can execute commands on Dyno
$ heroku run bash

image.png

  1. Define config vars
Explanation that config settings can be used considering the environmental differences between the local environment and Heroku environment
In the local environment, set the .env file and Heroku environment with the command
$ heroku config:set ENERGY="20 GeV"
$ heroku config

image.png

  1. Use a database
Explanation of DB (PostgreSQL)
On Heroku, the sample already has a DB access part, so the operation check is completed smoothly
The DB connection settings for the Heroku environment are in config
There seems to be another procedure in the local environment (not implemented)
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/9a2d4528-6e04-3099-2dc8-895e4cd18a1a.png)
  1. Next steps
Why don't you study this area next time? Explanation
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/105b309f-8c1a-8003-3027-f228b63a025b.png)

Summary

It is convenient that if you modify the program in about 2 hours in the future, you can easily publish it with just the following procedure I'm happy to be able to use DB

1. Program modification
2. mvn clean install
3. heroku local web
4. Local operation check
5. git add .
6. git commit -m "Comment"
7. git push heroku master
8. heroku open

Recommended Posts

I tried Heroku, which can publish web applications for free
I tried "Visual Studio Code Installer for Java" which can create Java development environment immediately
I tried AWS Copilot CLI which can build ECS at high speed
I tried Cassandra's Object Mapper for Java