Image Templates — Code-Driven Approach¶
Problem¶
The itzg/minecraft-server image requires MAX_MEMORY and INIT_MEMORY env vars to respect the order's provisioned memory. Without them, the JVM defaults to 1 GB regardless of how much memory was allocated. The flow had no access to order.resources, so there was no place to inject these.
Solution¶
Move all deployment-level concerns out of the flow and into the blueprint, which already receives order: &Order.
Flow's responsibility: capture user choices only — loader, difficulty, online_mode, use_optimization_flags.
Blueprint's responsibility: turn those choices + order resources into the full deployment spec — image tag, entrypoint, all env vars (including resource-derived ones).
This keeps the system consistent: blueprints, flows, and service kinds are all code. There is no separate "template" entity or DB table.
What Changed¶
-
MinecraftConfigurationnow stores only user choices. Theimageandenvfields are kept asOptionwith#[serde(default)]for backwards-compatible deserialization of orders already in the DB. -
MinecraftSetupFlow::into_output()is now trivial — it just copies the relevant state fields intoMinecraftConfiguration. -
MinecraftBlueprintnow owns all image/env logic: resolve_image(): derives the itzg image tag fromjava_for_minecraft_version(). Falls back to the storedmc.imagefor legacy orders.build_env_from_config(): builds the full env map from user choices.build_env(): callsbuild_env_from_config()(or uses the legacy stored env), then always overwritesMAX_MEMORYandINIT_MEMORYfrom currentorder.resources.memory(with a 128 MB headroom for JVM overhead).
Legacy Backwards-Compatibility¶
Orders already provisioned have MinecraftConfiguration.image and .env populated in their stored JSONB. The blueprint uses them as a base and then overwrites the resource-derived vars on top, so existing orders get the fix automatically on their next reprovisioning without requiring a data migration.
Once all active orders have been reprovisioned under the new system, the image and env fields can be removed from MinecraftConfiguration.
Adding a New Game Type¶
The pattern to follow:
- Define
TerrariaConfigurationwith user-facing choices only. - Add
Terraria(TerrariaConfiguration)toOrderServiceConfigandCatalogServiceKind. - Implement
TerrariaSetupFlow— gathers user choices,into_output()just captures them. - Implement
TerrariaBlueprint— resolves image, builds env, returnsVec<ProvisionSpec>.
No DB tables, no migrations, no separate template entity.