Where is H2 database when using Spring Boot and Heroku? - spring-boot

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?

Related

Heroku - environment variable for Srping Boot DB connect

I have an app on Spring Boot that running in two environments, local and heroku:
Local - connect to DB is configured by app.properties.
Heroku - app is working w\o app.properties, using one environment variable:
heroku config -a zed-social-network
=== zed-social-network Config Vars
CLEARDB_DATABASE_URL: mysql://{login}:{pass}#host.com/heroku?reconnect=true&useUnicode=true&characterEncoding=UTF-8
Question: how I can configure DB connect in Spring on local machine in same style, with one env variable?
I would use a command line argument:
mvn spring-boot:run -Drun.arguments=--customArgument=custom
so in your case
mvn spring-boot:run -Drun.arguments=--CLEARDB_DATABASE_URL=your_url
--
Alternatively, you could add the url to system variables and then reference it in application.properties like so:
spring.datasource.url=${NAME_OF_THE_SYSTEM_VARIABLE}

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.

spring boot logging.file not getting created in openshift

I want to export the logs of a spring boot application into a file in order to preserve it in a persistent volume.
In application.properties i added logging.file=myapplication.log
When i build and run the docker image locally, the myapplication.log file gets created in the container. But when i push the image to the Openshift internal registry and do
`oc new-app --name=<app> <image-name>`
the container gets created and works fine but the log file does not exist. I also tried inserting -Dlogging.file=myapplication.log in the dockerfile which also works locally but not in openshift.
What i am doing wrong! I am going insane!

Heroku addons:create --fork doesn't migrate redis data

I have an app hosted on Heroku and I am trying to migrate from Heroku Redis to Redis Cloud.
According to this documentation, I can easily migrate the data from my current Heroku Redis to a new Redis Cloud by using --fork flag.
https://devcenter.heroku.com/articles/rediscloud#migrating-from-an-existing-redis-server-to-redis-cloud
However, when I ran the command, it did create a new Redis Cloud instance but the instance doesn't have the data from my Heroku Redis instance.
This is the command that I used to create the instance
heroku addons:create rediscloud:100 --fork=`heroku config:get REDIS_URL -a app-name` -a app-name
Is the --fork flag only works for databases ?
Correct, fork will make a copy of the application, it's addons and data contained in Heroku Postgres.

How to deploy meanjs to heroku

I have tried deploying my meanjs on heroku.
I forked this https://github.com/meanjs/mean
1.) Login to heroku
2.) Deploy and connect github repositor
enabled automatic deploy CI
Click on Manual Deploy
On the build log it says "Bulid succeded"
My question is.
Why am I getting this application error?
When all I did was forked the repository and deployed it on heroku?
https://serkolgame.herokuapp.com/
Did you add a mongoDB to your app? Without it, the startup process is likely to fail.
Here are some options:
If you are using the default dev environment - then just add the mongodb connection string in development.js and restart the server
If you are using the prod environment - then you can use environment variables uri: process.env.MONGOHQ_URL or process.env.MONGOLAB_URI
This is assuming you have a mongoDB sandbox setup somewhere, if you don't, you'll first need a mongodb sandbox (get one from Heroku, Compose.io, or MongoLab).

Resources