mirror of
https://github.com/lemonade-sdk/lemonade.git
synced 2026-11-22 19:49:40 -10:00
fix(containers): include the lemond port in container names
Two lemond instances on one container daemon loading the same model produced the same name, and start() removes that name unconditionally, so the second instance killed the first one's container. The name is now lemonade-<port>-<recipe>-<backend>-<model>, still stable per instance so a load clears that instance's own crash leftovers, and the container carries an ai.lemonade.instance label. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LdWSB6RM2hfmfgheR7KvsP
This commit is contained in:
6 files changed
+39
-24
No files matched your search
@@ -178,8 +178,8 @@ These options are the same for Podman and Docker:
|
||||
| `--rm`, `--init`, `--cap-drop=all`, `--security-opt=no-new-privileges` | Same for every container † | Fixed |
|
||||
| `--pull=never` | Same for every container | Fixed |
|
||||
| seccomp | The tool's default profile: the command passes no `seccomp` option † | Fixed |
|
||||
| `--name` | `lemonade-<recipe>-<backend>-<model>`, where each part keeps letters, digits, `.` and `-`, doubles `_`, and writes any other character as `_` plus its two hex digits (`user.foo/bar` becomes `user.foo_2fbar`) | The loaded model |
|
||||
| `--label` | `ai.lemonade`, `ai.lemonade.recipe`, `.backend`, `.model`, `.port` † | The loaded model |
|
||||
| `--name` | `lemonade-<instance>-<recipe>-<backend>-<model>`, where `<instance>` is the port `lemond` listens on, so two `lemond` instances that share a container daemon never remove each other's containers, and each other part keeps letters, digits, `.` and `-`, doubles `_`, and writes any other character as `_` plus its two hex digits (`user.foo/bar` becomes `user.foo_2fbar`) | The loaded model |
|
||||
| `--label` | `ai.lemonade`, `ai.lemonade.instance`, `ai.lemonade.recipe`, `.backend`, `.model`, `.port` † | The loaded model and the `lemond` port |
|
||||
| `--network` | A private `--internal` network named after the container | Fixed |
|
||||
| `-v` | `<host path>:/mnt/models/<name>:ro,z`, one per model file the command names †. A directory the command names, such as Halogen's tokenizer directory, gets one mount per file inside it at the same relative path, such as `/mnt/models/tokenizer/vocab.json` ‡. Each host path is resolved through symlinks first, so files in a Hugging Face cache, which link into the cache's `blobs/` folder, mount as the files themselves. `z` gives the files a shared SELinux label that every container can read, so the same model can be mounted by several containers, whether Lemonade started them or not. It does nothing on hosts without SELinux | The model's files |
|
||||
| `--device` | One per node, such as `/dev/dri` § | `ContainerPolicy.devices` (see [`containers` Descriptor Field](#containers-descriptor-field)) |
|
||||
@@ -216,18 +216,19 @@ The program is the server the container runs, with its arguments, such as `llama
|
||||
|
||||
### Complete Example
|
||||
|
||||
Suppose `lemond` runs under the user's own account on a native host with rootless Podman, and loads the model `Qwen3-4B-GGUF` on `llamacpp:nathanw` with `ctx_size` set to 8192. `ContainerProcess` runs two commands. The first creates the container's private network, and the second starts the server:
|
||||
Suppose `lemond` listens on port 13305 under the user's own account on a native host with rootless Podman, and loads the model `Qwen3-4B-GGUF` on `llamacpp:nathanw` with `ctx_size` set to 8192. `ContainerProcess` runs two commands. The first creates the container's private network, and the second starts the server:
|
||||
|
||||
```
|
||||
podman network create --internal \
|
||||
--label ai.lemonade \
|
||||
lemonade-llamacpp-nathanw-Qwen3-4B-GGUF
|
||||
lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF
|
||||
|
||||
podman run \
|
||||
--rm \
|
||||
--init \
|
||||
--name lemonade-llamacpp-nathanw-Qwen3-4B-GGUF \
|
||||
--name lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF \
|
||||
--label ai.lemonade \
|
||||
--label ai.lemonade.instance=13305 \
|
||||
--label ai.lemonade.recipe=llamacpp \
|
||||
--label ai.lemonade.backend=nathanw \
|
||||
--label ai.lemonade.model=Qwen3-4B-GGUF \
|
||||
@@ -235,7 +236,7 @@ podman run \
|
||||
--cap-drop=all \
|
||||
--security-opt=no-new-privileges \
|
||||
--pull=never \
|
||||
--network=lemonade-llamacpp-nathanw-Qwen3-4B-GGUF \
|
||||
--network=lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF \
|
||||
--device /dev/dri \
|
||||
--group-add keep-groups \
|
||||
-v /home/alice/.cache/huggingface/hub/models--unsloth--Qwen3-4B-GGUF/snapshots/a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4/Qwen3-4B-Q4_K_M.gguf:/mnt/models/Qwen3-4B-Q4_K_M.gguf:ro,z \
|
||||
@@ -380,7 +381,7 @@ Rootless Podman also needs the `lemonade` account to own a subordinate UID/GID r
|
||||
|
||||
- When `/etc/subuid` and `/etc/subgid` both already have a `lemonade` entry, the script leaves them as they are, so upgrades and reinstalls keep the existing range.
|
||||
- Otherwise it reads both files, takes the highest end (start plus count) of every range in them, with a minimum of 100000, and allocates the 65,536 IDs from there to whichever file lacks a `lemonade` entry, with `usermod --add-subuids <start>-<start+65535> lemonade` and `usermod --add-subgids <start>-<start+65535> lemonade`. The range sits past every account's existing block, and `useradd` allocates later accounts past it in turn.
|
||||
- When `/etc/nsswitch.conf` has a `subid:` line, the host gets subordinate IDs from a central directory such as FreeIPA or SSSD, and the script leaves the allocation to the host's administrator. The setup assistant's "Subordinate IDs allocated" check reports a missing range.
|
||||
- When `/etc/nsswitch.conf` has a `subid:` line naming a source other than `files`, the host gets subordinate IDs from a central directory such as FreeIPA or SSSD, and the script leaves the allocation to the host's administrator. The setup assistant's "Subordinate IDs allocated" check reports a missing range.
|
||||
|
||||
`lemond` starts and stops the containers as children in its own cgroup, so stopping `lemond.service` tears down its containers with it.
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ Install pulls the image, so loading a model starts from the image already on dis
|
||||
|
||||
## How Containers Run
|
||||
|
||||
Each loaded model gets its own container, named `lemonade-<recipe>-<backend>-<model>` and labeled `ai.lemonade`, so `podman ps --filter label=ai.lemonade` lists them. Every load logs its full `podman run` or `docker run` command. Each container:
|
||||
Each loaded model gets its own container, named `lemonade-<port>-<recipe>-<backend>-<model>`, where `<port>` is the port Lemonade listens on, and labeled `ai.lemonade`, so `podman ps --filter label=ai.lemonade` lists them. Every load logs its full `podman run` or `docker run` command. Each container:
|
||||
|
||||
- mounts only the model's files, read-only, under `/mnt/models`, with the shared SELinux label so other containers and programs can still read them
|
||||
- opens only the GPU device nodes its backend needs
|
||||
|
||||
@@ -29,6 +29,7 @@ struct ContainerRunSpec {
|
||||
std::string recipe;
|
||||
std::string backend;
|
||||
std::string model;
|
||||
int instance = 0;
|
||||
int port = 0;
|
||||
std::string network;
|
||||
std::vector<std::string> devices;
|
||||
@@ -130,10 +131,12 @@ public:
|
||||
// The container's address on its network, or "" while it has none.
|
||||
std::string address(const std::string& name) const;
|
||||
|
||||
// lemonade-<recipe>-<backend>-<model>, reduced to the characters a
|
||||
// container name accepts.
|
||||
static std::string container_name(const std::string& recipe, const std::string& backend,
|
||||
const std::string& model);
|
||||
// lemonade-<instance>-<recipe>-<backend>-<model>, reduced to the
|
||||
// characters a container name accepts. `instance` is the port the owning
|
||||
// lemond listens on, so two lemond instances sharing a container daemon
|
||||
// never claim each other's containers.
|
||||
static std::string container_name(int instance, const std::string& recipe,
|
||||
const std::string& backend, const std::string& model);
|
||||
// The command that installs Podman on the distribution `os_release`
|
||||
// describes, matched on ID, then each word of ID_LIKE.
|
||||
static std::string podman_install_command(const std::string& os_release);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "lemon/backends/backend_ops.h"
|
||||
#include "lemon/runtime_config.h"
|
||||
#include "lemon/utils/container_manager.h"
|
||||
|
||||
#include <lemon/utils/aixlog.hpp>
|
||||
@@ -114,11 +115,14 @@ std::string ContainerProcess::start(const ServerCommand& command) {
|
||||
throw std::runtime_error(recipe_ + ":" + backend_ + " names the image " + policy_.image +
|
||||
", which is not one Lemonade runs container backends from");
|
||||
}
|
||||
name_ = ContainerManager::container_name(recipe_, backend_, model_);
|
||||
const RuntimeConfig* config = RuntimeConfig::global();
|
||||
const int instance = config ? config->port() : 0;
|
||||
name_ = ContainerManager::container_name(instance, recipe_, backend_, model_);
|
||||
manager.remove_container(name_);
|
||||
|
||||
utils::ContainerRunSpec spec;
|
||||
spec.name = name_;
|
||||
spec.instance = instance;
|
||||
spec.recipe = recipe_;
|
||||
spec.backend = backend_;
|
||||
spec.model = model_;
|
||||
|
||||
@@ -363,6 +363,7 @@ std::vector<std::string> ContainerManager::run_command(const ContainerRunSpec& s
|
||||
std::vector<std::string> argv = {
|
||||
tool_name(*chosen), "run", "--rm", "--init", "--name", spec.name,
|
||||
"--label", kLabel,
|
||||
"--label", std::string(kLabel) + ".instance=" + std::to_string(spec.instance),
|
||||
"--label", std::string(kLabel) + ".recipe=" + spec.recipe,
|
||||
"--label", std::string(kLabel) + ".backend=" + spec.backend,
|
||||
"--label", std::string(kLabel) + ".model=" + spec.model,
|
||||
@@ -580,10 +581,11 @@ std::string ContainerManager::address(const std::string& name) const {
|
||||
return result.exit_code == 0 ? trim(result.output) : "";
|
||||
}
|
||||
|
||||
std::string ContainerManager::container_name(const std::string& recipe,
|
||||
std::string ContainerManager::container_name(int instance, const std::string& recipe,
|
||||
const std::string& backend,
|
||||
const std::string& model) {
|
||||
return "lemonade-" + name_token(recipe) + "-" + name_token(backend) + "-" + name_token(model);
|
||||
return "lemonade-" + std::to_string(instance) + "-" + name_token(recipe) + "-" +
|
||||
name_token(backend) + "-" + name_token(model);
|
||||
}
|
||||
|
||||
std::string ContainerManager::podman_install_command(const std::string& os_release) {
|
||||
|
||||
@@ -103,10 +103,11 @@ struct FakeHost {
|
||||
// The spec's Complete Example: Qwen3-4B-GGUF on llamacpp:nathanw.
|
||||
ContainerRunSpec example_spec() {
|
||||
ContainerRunSpec spec;
|
||||
spec.name = "lemonade-llamacpp-nathanw-Qwen3-4B-GGUF";
|
||||
spec.name = "lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF";
|
||||
spec.recipe = "llamacpp";
|
||||
spec.backend = "nathanw";
|
||||
spec.model = "Qwen3-4B-GGUF";
|
||||
spec.instance = 13305;
|
||||
spec.port = 8001;
|
||||
spec.network = spec.name;
|
||||
spec.devices = {"/dev/dri"};
|
||||
@@ -119,14 +120,15 @@ ContainerRunSpec example_spec() {
|
||||
|
||||
void test_run_command() {
|
||||
const std::string common =
|
||||
" run --rm --init --name lemonade-llamacpp-nathanw-Qwen3-4B-GGUF"
|
||||
" run --rm --init --name lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF"
|
||||
" --label ai.lemonade"
|
||||
" --label ai.lemonade.instance=13305"
|
||||
" --label ai.lemonade.recipe=llamacpp"
|
||||
" --label ai.lemonade.backend=nathanw"
|
||||
" --label ai.lemonade.model=Qwen3-4B-GGUF"
|
||||
" --label ai.lemonade.port=8001"
|
||||
" --cap-drop=all --security-opt=no-new-privileges"
|
||||
" --pull=never --network=lemonade-llamacpp-nathanw-Qwen3-4B-GGUF"
|
||||
" --pull=never --network=lemonade-13305-llamacpp-nathanw-Qwen3-4B-GGUF"
|
||||
" --device /dev/dri";
|
||||
const std::string mount_and_home =
|
||||
" -v /home/alice/model.gguf:/mnt/models/Qwen3-4B-Q4_K_M.gguf:ro,z"
|
||||
@@ -403,13 +405,16 @@ void test_install_commands() {
|
||||
|
||||
void test_helpers() {
|
||||
check("characters a container name rejects are escaped as _ plus hex",
|
||||
ContainerManager::container_name("llamacpp", "nathanw", "user.My Model:Q4/x") ==
|
||||
"lemonade-llamacpp-nathanw-user.My_20Model_3aQ4_2fx");
|
||||
ContainerManager::container_name(13305, "llamacpp", "nathanw", "user.My Model:Q4/x") ==
|
||||
"lemonade-13305-llamacpp-nathanw-user.My_20Model_3aQ4_2fx");
|
||||
check("names that differ only in rejected characters keep distinct containers",
|
||||
ContainerManager::container_name("llamacpp", "nathanw", "user.foo/bar") !=
|
||||
ContainerManager::container_name("llamacpp", "nathanw", "user.foo-bar") &&
|
||||
ContainerManager::container_name("llamacpp", "nathanw", "user.foo_2fbar") ==
|
||||
"lemonade-llamacpp-nathanw-user.foo__2fbar");
|
||||
ContainerManager::container_name(13305, "llamacpp", "nathanw", "user.foo/bar") !=
|
||||
ContainerManager::container_name(13305, "llamacpp", "nathanw", "user.foo-bar") &&
|
||||
ContainerManager::container_name(13305, "llamacpp", "nathanw", "user.foo_2fbar") ==
|
||||
"lemonade-13305-llamacpp-nathanw-user.foo__2fbar");
|
||||
check("two lemond instances loading the same model get distinct containers",
|
||||
ContainerManager::container_name(13305, "llamacpp", "nathanw", "Qwen3-4B-GGUF") !=
|
||||
ContainerManager::container_name(13306, "llamacpp", "nathanw", "Qwen3-4B-GGUF"));
|
||||
|
||||
check("other publishers are refused",
|
||||
!ContainerManager::allowed_image("docker.io/library/ubuntu") &&
|
||||
|
||||
Reference in new issue
Block a user