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
-
Web applications can be published for free (with restrictions *)
-
You can use DB (PostgreSQL) for free
-
Free frame is 550 hours / month
Automatically sleeps if there is no operation for 30 minutes (no access, etc.)
(If there is access, it will take the first time, but it will start automatically)
See below for details
Free Dyno Hours
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
- Java, Maven
- Heroku, git beginner
Advance preparation
- Free Heroku account (only email address required. Credit card registration is not required and the threshold is relatively low)
- Java 8
- Maven 3
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) ...
- Introduction
- Preparation contents dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/2c163f96-e7fc-641c-7a5f-d90d06dbd9bc.png)
- Set up
- Heroku command line installation (git is installed with it) dd>
- After installation, log in with the Heroku command dd>
$ heroku login
Enter your Heroku credentials.
Email: [email protected]
Password:
- Prepare the app
- git clone the prepared sample program and prepare it locally dd>
$ git clone https://github.com/heroku/java-getting-started.git
$ cd java-getting-started
- Deploy the app
- Deploy and launch sample program on Heroku dd>
$ heroku create
$ git push heroku master
$ heroku ps:scale web=1
$ heroku open
- View logs
- Explanation of log confirmation method dd>
$ heroku logs --tail
- Define a Procfile
- Procfile description dd>
- Heroku seems to specify the type of application in this Procfile dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/61e94532-bb9d-2821-6d22-435c5ff5eb2d.png)
- Scale the app
- Explanation of the concept of Dyno that runs the application and explanation of the above free frame dd>
- Dyno seems to be lightweight, secure, virtualized Unix container dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/c28250ce-69e8-7b3b-2416-0e20fb4c71a2.png)
- Declare app dependencies
- Explanation of pom.xml, system.properties and preparation for operation in local environment dd>
- Specify the operation version in system.properties dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/7d82246a-5eab-409b-890a-3fe1a1721d3e.png)
- dd>
- Because the environment variables JAVA_HOME and MAVEN_HOME were added and the setting to PATH was omitted when installing Java and Maven dd>
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? Occurrence dd>
- Environment variables MAVEN_HOME, JAVA_HOME added, both variables added to PATH solves dd>
- Run the app locally
- Start in local environment and check screen dd>
- Local environment access URL: http: // localhost: 5000 dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/3b2fe452-ffc4-d4ea-f724-6f48b134fb9b.png)
- Push local changes
- Explanation of sample program modification procedure and deployment of modification to Heroku dd>
$ mvn clean install
$ heroku local web
$ git add .
$ git commit -m "Demo"
$ git push heroku master
$ heroku open hello
- dd>
- git commit -m "Demo" says *** Please tell me who you are. dd>
- I was in the state of heroku login, so I thought that it would be linked without permission and tried various things again ... dd>
- As a result, heroku login was completely irrelevant, so quietly execute the following command displayed after Please tell me who you are. dd>
- git config --global user.email {email address} dd>
- git config --global user.name {name} dd>
- Provision add-ons
- add-ons seems to be convenient, but I realized that credit card authentication is required and skipped dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/0b26b17b-33b8-6a7a-b0cf-a622862e2397.png)
- Start a one-off dyno
- You can execute commands on Dyno dd>
$ heroku run bash
- Define config vars
- Explanation that config settings can be used considering the environmental differences between the local environment and Heroku environment dd>
- In the local environment, set the .env file and Heroku environment with the command dd>
$ heroku config:set ENERGY="20 GeV"
$ heroku config
- Use a database
- Explanation of DB (PostgreSQL) dd>
- On Heroku, the sample already has a DB access part, so the operation check is completed smoothly dd>
- The DB connection settings for the Heroku environment are in config dd>
- There seems to be another procedure in the local environment (not implemented) dd>
![image.png](https://qiita-image-store.s3.amazonaws.com/0/188544/9a2d4528-6e04-3099-2dc8-895e4cd18a1a.png)
- Next steps
- Why don't you study this area next time? Explanation dd>
![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 dt>
- 2. mvn clean install
- 3. heroku local web
- 4. Local operation check dt>
- 5. git add .
- 6. git commit -m "Comment"
- 7. git push heroku master
- 8. heroku open