I have a simple Micronaut server I am trying to launch on Heroku by building it with a heroku.yml but for some reason when I check the logs the process exits as soon as it starts. The docker image runs just fine locally and nothing else prints out in the logs so I can't find out why.
Here is my Dockerfile
FROM node as build-frontend
WORKDIR /app
COPY frontend/myfrontend/package.json .
COPY frontend/myfrontend/public ./public
COPY frontend/myfrontend/src ./src
RUN npm install .
RUN npm run build
FROM gradle:6.8.2-jre11 AS build-env
# Set the working directory to /home
WORKDIR /home
COPY --chown=gradle:gradle backend ./
COPY --from=build-frontend /app/build /home/src/main/resources/public
# Compile the application.
RUN ./gradlew assemble
FROM openjdk:11.0.10-jre-slim-buster
# Set the working directory to /home
WORKDIR /home
# Copy the compiled files over.
COPY --from=build-env /home/build/libs/myjar-0.1-all.jar /home/myjar.jar
# Starts the java app
# Using EntryPoing to pass env. variables as describe in this article
ENTRYPOINT exec java -XX: UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX: AlwaysPreTouch -jar myjar.jar
Here is my heroku.yml
setup:
addons:
- plan: heroku-postgresql
as: DATABASE
build:
docker:
web: Dockerfile
run:
web: "exec java -XX: UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX: AlwaysPreTouch -jar myjar.jar"
and finally my Micronaut application.yml which just sets some configs
micronaut:
application:
name: mypackage
router:
static-resources:
default:
enabled: true
paths:
- classpath:public
mapping: /**
server:
port: ${PORT:8080}
cors:
enabled: true
datasources:
default:
driverClassName: org.postgresql.Driver
dbUrl: jdbc:postgresql://mydbhost.com:port/dbname?sslmode=require
dbUsername: dbuser
dbPassword: dbpasswd
scan:
packages: mypackage
netty:
default:
allocator:
max-order: 3
When I just do docker build -t test-image:latest .
and docker run -p 80:8080 test-image:latest
I can connect just fine on localhost and the docker container runs the micronaut server. If it fails for some reason I see an output in the container logs detailing why. When I upload this to heroku (through a github deployment) All i see in the logs are
2023-01-09T22:25:50.145942 00:00 heroku[web.1]: Starting process with command `/bin/sh -c exec\ java\ -XX:\ UseContainerSupport\ -XX:MaxRAMPercentage\=80.0\ -noverify\ -XX:\ AlwaysPreTouch\ -jar\ myjar.jar`
2023-01-09T22:25:51.381760 00:00 heroku[web.1]: Process exited with status 0
2023-01-09T22:25:51.439962 00:00 heroku[web.1]: State changed from starting to crashed
I have tried: To run it locally connected to the heroku addon postgres database, works just fine Simplifying the build as much as possible Removing the default on the port (to ensure it picks up $PORT), and running it locally with export PORT=8080 set (works just fine, docker container picks up the env port like we expect in heroku)
And I cannot figure out why it just quits immediately on Heroku. editted: originally thought it had to do with the port value but but I figured out how to give micronaut a port through the command line and it still doesn't work on Heroku (works locally)
edit: I tried changing my application.yml to this with the DB hardcoded and still nothing. Just does not seem to work. App still crashes and there is nothing to indicate why in the logs
setup:
config:
PORT: $PORT
MICRONAUT_SERVER_PORT: $PORT
build:
docker:
web: Dockerfile
run:
web: "exec java -Dmicronaut.server.port=$PORT -XX: UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX: AlwaysPreTouch -jar myjar.jar"
I still have no extra output from Heroku. No stacktrace or stderr or stdout at all.
CodePudding user response:
Well, it isn't much of an answer. And nothing in the Heroku docs points me to why this works but removing ENTRYPOINT exec java -XX: UseContainerSupport -XX:MaxRAMPercentage=80.0 -noverify -XX: AlwaysPreTouch -jar myjar.jar
from my Dockerfile works. With entrypoint removed I see logs again and can see my micronaut server starting. With ENTRYPOINT
defined in my Dockerfile I just get what I posted about above "Process starting" followed immediately by process crashed