Skip to main content
You will deploy an existing Spring Boot app, with a Dockerfile, to Reliant hosting with a managed Postgres. Forge reads the Dockerfile and writes its declarations beside it. Spring needs more hand edits than other stacks, because the detector reads the port from the Dockerfile but does not read pom.xml or build.gradle: you add the database yourself. The detector output here is from Forge v1.10.1-0.20261123064811-54313eead62f.

Before you begin

  • Docker, and the app in a git repository with a root Dockerfile that builds on its own.
  • Forge: reliant forge inside Reliant, or npx -y @reliantlabs/forge@latest anywhere else.
  • A Reliant account with app hosting billing. A JVM doesn’t fit the anonymous plan (below).

What the Dockerfile must do

A deploy runs docker build on the Dockerfile alone, so build the jar inside it. A Dockerfile that only does COPY target/app.jar fails, because target/ exists only on your machine:
Dockerfile
The detector takes the port from EXPOSE and sets PORT=8080 in the container. Spring Boot ignores PORT unless you map it: put server.port=${PORT:8080} in application.properties. Spring binds all interfaces by default. MaxRAMPercentage sizes the heap from the container’s memory limit instead of the JVM’s default quarter, which leaves room for metaspace and threads without being killed.

Postgres: a JDBC URL

Hosting hands each environment’s managed Postgres to the app as a URL in DATABASE_URL (postgres://user:pass@host/db form). Spring’s datasource wants jdbc:postgresql://host/db with the user and password separate, and doesn’t parse the URL form. The least code is a small DataSource bean that reads DATABASE_URL:
DatabaseConfig.java
Then declare the database in each hosted env, as the detector does for other stacks:
deploy/kcl/prod/main.k (excerpt)
The database’s name may not be a workload’s name (api).

Migrations: on startup

Flyway (spring-boot-starter-flyway or flyway-core) and Liquibase run on application startup, against the same DataSource, before Spring starts serving, so you don’t need a separate migrate job. With one replica that is safe; with more, both tools take a database lock, so the second replica waits. Keep migrations backward-compatible, because the old release serves while the new one migrates. If you’d rather migrate before the rollout, add a migrate job running java -jar app.jar --spring.main.web-application-type=none with a profile that exits after Flyway.
1

Preview and adopt

terminal
Output (trimmed)
No Postgres is detected for a Maven or Gradle app. Adopt, then add the database as above to staging/main.k and prod/main.k. For dev, set the command in deploy/kcl/dev/main.k to ./mvnw spring-boot:run and add a local Postgres (forge.HostInfra {name = "postgres", ...}; reliant forge skill load adopt/deploy shows the dev file).
terminal
2

Size the workload

The default hosted size is 250m CPU and 1 GiB of memory. A Spring Boot app with JPA usually wants 512 MiB to 1 GiB and starts slowly at 250m. Declare it in workloads.k, on the fixed shape of 4 GiB per vCPU in 125m steps:
deploy/kcl/workloads.k (excerpt)
3

Secrets, build, deploy

terminal
Deliver each secret as env.JWT_SECRET = forge.ManagedSecret {name = "JWT_SECRET"} on the workload. Check application.properties for ${JWT_SECRET:changeme}: the default after the colon is what prod runs with if the secret is missing. Without billing, the deploy is queued and exits 7 with the billing link.The anonymous plan (--claimable) caps the service at 125m CPU and 128 MiB. Spring Boot’s heap, metaspace and code cache alone exceed that, and at 125m it may not finish starting before its probe gives up. Sign in instead.
4

Verify

terminal
With Actuator, {"status":"UP"} includes the database check; switch the probe to tiers.Probes {readinessPath = "/actuator/health/readiness"}. obs check exits 0 proven good, 1 regressed, 2 not proven, 8 the wait ran out. The OpenTelemetry Java agent (-javaagent:opentelemetry-javaagent.jar in JAVA_TOOL_OPTIONS) reads the endpoint hosting sets and turns exit 2 (no_request_telemetry) into real verdicts.

Spring gotchas

  • OOMKilled at startup: raise memoryRequestBytes, or lower MaxRAMPercentage. Never set -Xmx above the limit.
  • Probe failures during a slow start: the TCP probe passes only once Tomcat listens. Give a large app more CPU rather than a longer timeout.
  • Failed to determine a suitable driver class: the datasource never got a JDBC URL. See the bean above.
See also: Bring an existing app, Managed Postgres, Secrets, Hosting limits.