Heroku Spring Boot deploy not creating database tables - spring

I'm trying to deploy a Spring Boot REST API to Heroku.
It successfully uploads the files to Heroku's Git repository.
But it is not creating the database tables and so the app doesn't work.
This is how I'm doing on the CLI.
git add .
git commit -m "message"
heroku login
heroku create myappname
heroku addons:create heroku-postgresql:hobby-dev
git push heroku main
Tried with several different application.properties (as below) and none of them was successful.
(user/passwords below are fake. Just for explanation purpose)
application.properties test1
spring.jpa.hibernate.ddl-auto=create
application.properties test2
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.jpa.hibernate.ddl-auto=create
application.properties test3
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=postgres://aooswjxdniusmd:f99447ede191d139d32f1e3d539dc8ty4535c65350a51960d887km44d6we7c4#ec2-21-567-987-345.compute-1.amazonaws.com:5432/q5kl3s76jh08yt
application.properties test4
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=postgres://aooswjxdniusmd:f99447ede191d139d32f1e3d539dc8ty4535c65350a51960d887km44d6we7c4#ec2-21-567-987-345.compute-1.amazonaws.com:5432/q5kl3s76jh08yt
application.properties test5
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=info
application.properties test6
spring.datasource.url=${JDBC_DATABASE_URL}
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
application.properties test7
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=info
UPDATE:
I ran heroku logs --tail to take a look at the logs.
Two entries called my attention:
heroku[router]: at=error code=H14 desc="No web processes running"
Error: Unable to access jarfile target/myapp-0.0.1-SNAPSHOT.jar
Then I tried the following:
java -jar myapp-0.0.1-SNAPSHOT.jar
Also got the same error message:
Error: Unable to access jarfile myapp-0.0.1-SNAPSHOT.jar
So that seems to be the cause of the issue.
Not sure why it is happening though.

Related

How does Spring Config Server Fetch Values from Git using Queues

I am doing a course from Udemy, and implemented Spring Cloud Config Server, with Git as Backend. Every thing seems to be working fine.
I have following Spring Cloud Config Server: ConfigServer-RI
In ConfigServer-RI I have following entry in application.properties file, for configuring rabbit mq.
spring.cloud.config.server.git.uri=https://github.com/Naresh-Chaurasia/ConfigServer-RI
spring.cloud.config.server.git.default-label=main
spring.cloud.config.server.git.clone-on-start=true
management.endpoints.web.exposure.include=bus-refresh
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
I also have User Microservice: User-RI
In User-RI, I have following entry in application.properties
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
Now if i make change in applicaiton.properties in Git file, https://github.com/Naresh-Chaurasia/ConfigServer-RI, and then call, the Spring Config Server, with following URL http://localhost:8012/actuator/bus-refresh, the changes that are done in the Git properties file are reflected in User-RI Microservice i.e. the changes from Git repository properties file are accessible to User-RI Microservice without restarting it.
Question: I am not able to understand, how the data is flowing from Git Repository to Microservices, when I configure the queue details in application.properties file.
Thanks.

Spring Boot Logging Config External File with Password

I have config server and I store my logbook.xml here. My config server integrated with my git repo and it has username-password.
I want to get related logback file from config server but it return 401.
I should add my user informations. How should I solve it
My YML file:
logging:
config: ${myRepo}

Where is H2 database when using Spring Boot and Heroku?

I am using H2 database with Java Spring Boot and Heroku. Here is my application.properties:
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.url=jdbc:h2:./database
When I run app locally, files database.mv.db and database.trace.db are created in root of project. However when I deploy this project to Heroku, and run:
heroku login
heroku run bash --app myappname
ls
I don't see any database files in project root. But the app still works and stores the data in the database. However, after the server restarts, the database is empty. Does this mean that Heroku only runs the H2 database in-memory? Or is there any way to set H2 on Heroku as persistent storage?

Dockerized Spring Boot app can't get JDBC connection string on Heroku

I'm trying to run the Dockerized Spring Boot application on Heroku. I use dockerfile-maven and plugin to create the app I use this commands
heroku apps:create my-app-name --buildpack heroku/java
heroku addons:create heroku-postgresql:hobby-dev --app my-app-name
Notice that I'm using buildpack here.
In application.properties I have such lines
spring.datasource.url=${JDBC_DATABASE_URL:some default jdbc connection string}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
How I understand if I set the heroku/java buildpack for the app the environment variables JDBC_DATABASE_URL should be created but in my case, I see the default connection string in logs. That's mean that JDBC_DATABASE_URL is not set or not available. Why that's could happen?
Worth to mention that DATABASE_URL environment variable is available in the application.

Heroku: deploy jhipster project with `gitlab-ci` get crashed because of `Procfile` command

I had ask this issue on jhipster-generator Github issue before.
But still don't get solutions yet.
(See more at Example Repository on my Gitlab and Github issue#9426)
I think it related to the final commands in the Procfile that I got from the generator which defined like these:
web: java $JAVA_OPTS -Xmx256m -jar target/*.war --spring.profiles.active=prod,heroku,no-liquibase --server.port=$PORT
release: cp -R src/main/resources/config config && ./mvnw liquibase:update -Pheroku
on release: the command cp -R ... can't be executed because from the last job of gitlab-ci which work fine and get green response. But when I see log in Heroku deploy instance, I got the src/main/resource/config not found. Then I try to investigate more with added ls * -ltr to release: and found that even src directory is not found. Only target directory is over there.
So I tried remove the release: row from Procfile the try again, then I got crashed messages from Heroku server running the application.
Some part from Log
2019-03-26T03:18:10.547189+00:00 app[web.1]: 03:18:10.536 [localhost-startStop-1] ERROR org.springframework.boot.SpringApplication - Application run failed
2019-03-26T03:18:10.547217+00:00 app[web.1]: java.util.ServiceConfigurationError: javax.cache.spi.CachingProvider: Provider org.redisson.jcache.JCachingProvider not a subtype
...
2019-03-26T03:18:10.567009+00:00 app[web.1]: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
But if I run with the command jhipster heroku it will deploy with different method from the command defined in .gitlab-ci.yml file. And can be run successfully.
So due to the Heroku deployment documentation which I think it is the most related to the issue I found right now, what should I fix on the Procfile to get the final deployment on Heroku can work as it should be?
Any help will be appreciate and thank you in advance.
TLDR;
I do these things and then the CI-CD with Gitlab -> Heroku can do CI-CD properly.
at Procfile, remove the release: line, because what the .gitlab-ci.yml file do when deploy-to-production state was performed is deploy the JAR file, not include the whole project directories, so, it's not important to copy files from project's directories anymore.
Now you can run CI-CD with all green on Gitlab pipeline and Deployed succeed on Heroku
But there are some issues will block your app from running properly. And here what I found.
# ===================================================================
# Spring Boot configuration for the "heroku" profile.
#
# This configuration overrides the application.yml file.
# ===================================================================
# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================
eureka:
instance:
hostname: jhip-cicd-bug.herokuapp.com
non-secure-port: 80
prefer-ip-address: false
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}
hikari:
maximumPoolSize: 8
data:
jest:
uri: ${BONSAI_URL}
The application-heroku.yml file, the reference to environment variables ${JDBC_DATABASE_URL}, ${JDBC_DATABASE_USERNAME}, ${JDBC_DATABASE_PASSWORD}, is not created, only thing be created is DATABASE_URL that contains with postgres://[generated-user]:[generated-secret]#[generated-url]:5432/[generated-dbname]
It's wrong on
Not started with jdbc:
Environment variable name is different as defined above DATABASE_URL (created) not equals to JDBC_DATABASE_URL, and the ${JDBC_DATABASE_USERNAME}, ${JDBC_DATABASE_PASSWORD} were not created. Then my workaround is create those environment variables on Heroku settings -> Config vars and edit their value properly, like...
key JDBC_DATABASE_URL value jdbc:postgres://[url]:5432/[dbname]
key JDBC_DATABASE_USERNAME value [username]
key JDBC_DATABASE_PASSWORD value [password]
Or you might change this url: ${JDBC_DATABASE_URL} to url: jdbc:${DATABASE_URL} (never try before, not confident for the result).

Resources