Skip to content

Commit 7ddc890

Browse files
authored
feat: support the service tmpfs key (#16)
* docs: plan tmpfs support * feat: accept and emit the service tmpfs key Compose's tmpfs short syntax (string or list of <path>[:<options>], e.g. /tmp:mode=1777) maps directly onto podman's own --tmpfs CONTAINER-DIR[:OPTIONS] flag (confirmed against podman-run docs), so it's a pure pass-through: no translation, no format validation.
1 parent 744a484 commit 7ddc890

6 files changed

Lines changed: 79 additions & 4 deletions

File tree

‎architecture/supported-subset.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ warns (ignored, behavior-neutral inside a single pod) or raises
2121

2222
- **Supported:** `image`, `build`, `command`, `environment`, `env_file`,
2323
`volumes`, `healthcheck`, `depends_on`, `networks`, `hostname`,
24-
`container_name`. compose2pod never builds: a `build` section is accepted
25-
but its contents (context, dockerfile, args) are not read — `image_for`
26-
(`compose2pod/emit.py`) runs the CI image supplied via `--image` for any
27-
service that has one.
24+
`container_name`, `tmpfs`. compose2pod never builds: a `build` section is
25+
accepted but its contents (context, dockerfile, args) are not read —
26+
`image_for` (`compose2pod/emit.py`) runs the CI image supplied via `--image`
27+
for any service that has one.
28+
- **`tmpfs`:** a string or list of strings, each `<path>` or
29+
`<path>:<options>` (e.g. `/tmp:mode=1777`), passed through verbatim as
30+
`podman run --tmpfs <value>` — Compose's short syntax maps directly onto
31+
podman's own `--tmpfs CONTAINER-DIR[:OPTIONS]` flag, so no translation is
32+
needed. No format validation; a malformed option string surfaces as a
33+
podman error at run time.
2834
- **`hostname` and `container_name`:** both are made resolvable to
2935
`127.0.0.1` like a network alias (added to the shared `--add-host` set), so
3036
other services can reach the service by either name. The pod shares the UTS

‎compose2pod/emit.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def run_flags(name: str, svc: dict[str, Any], pod: str, hosts: list[str], projec
6868
# Absolute bind mount (starts with "/") and named volume (bare
6969
# identifier) are both kept as-is — neither is a path to translate.
7070
flags += ["-v", f"{source}:{destination}"]
71+
tmpfs = svc.get("tmpfs") or []
72+
if isinstance(tmpfs, str):
73+
tmpfs = [tmpfs]
74+
for mount in tmpfs:
75+
flags += ["--tmpfs", mount]
7176
healthcheck = svc.get("healthcheck") or {}
7277
_add_health_flags(flags, healthcheck)
7378
return flags

‎compose2pod/parsing.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"networks",
2020
"hostname",
2121
"container_name",
22+
"tmpfs",
2223
}
2324
IGNORED_SERVICE_KEYS = {"ports", "restart", "stdin_open", "tty"}
2425
SUPPORTED_HEALTHCHECK_KEYS = {"test", "interval", "timeout", "retries", "start_period"}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
summary: Accept the service `tmpfs` key, emitted as podman `--tmpfs <path>[:<options>]`.
3+
---
4+
5+
# Change: Support the service `tmpfs` key
6+
7+
**Lane:** lightweight — two files (`parsing.py`, `emit.py`), no new file, no
8+
public-API change, single straightforward pass-through (verified against
9+
podman's own flag docs, no design ambiguity).
10+
11+
## Goal
12+
13+
`validate()` rejects the service `tmpfs` key
14+
(`service 'agent-worker': unsupported key 'tmpfs'`). Compose's `tmpfs:` short
15+
syntax (a string or list of strings, each `<path>` or `<path>:<options>`, e.g.
16+
`/tmp:mode=1777`) maps directly onto podman's own `--tmpfs
17+
CONTAINER-DIR[:OPTIONS]` flag — confirmed against podman's `podman-run` docs:
18+
"The general format is: `--tmpfs CONTAINER-DIR[:OPTIONS]`" with the same
19+
`mode=`/`size=` option vocabulary Compose uses. This is a pure pass-through,
20+
unlike volumes: no host-path translation, no bind-vs-named disambiguation.
21+
22+
## Approach
23+
24+
- `parsing.py`: add `"tmpfs"` to `SUPPORTED_SERVICE_KEYS`. No dedicated
25+
validation — `tmpfs` is a string or list of strings; malformed option
26+
strings surface as a podman error at run time, consistent with how other
27+
pass-through values (image names, volume names) are handled.
28+
- `emit.py` (`run_flags`): normalize `svc.get("tmpfs")` to a list the same way
29+
`env_file` already is (`str` → single-element list), then append
30+
`["--tmpfs", value]` for each entry, verbatim.
31+
- Promote into `architecture/supported-subset.md`.
32+
33+
## Files
34+
35+
- `compose2pod/parsing.py` — add `tmpfs` to `SUPPORTED_SERVICE_KEYS`.
36+
- `compose2pod/emit.py` — `run_flags`: emit `--tmpfs <value>` per entry.
37+
- `tests/test_parsing.py` — `tmpfs` (string and list forms) validates.
38+
- `tests/test_emit.py` — `run_flags` emits `--tmpfs` for both forms.
39+
- `architecture/supported-subset.md` — Service keys promotion.
40+
41+
## Verification
42+
43+
- [ ] Failing test first: `run_flags` with `tmpfs: ["/tmp:mode=1777"]` — no
44+
`--tmpfs` flag present (RED).
45+
- [ ] Apply the `parsing.py` + `emit.py` changes.
46+
- [ ] Test passes: `["--tmpfs", "/tmp:mode=1777"]` present in flags.
47+
- [ ] `just test-ci` — full suite green at 100% line coverage.
48+
- [ ] `just lint-ci` — clean.

‎tests/test_emit.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def test_env_file_list_form(self) -> None:
4545
flags = run_flags("app", svc, "p", [], "/builds/x")
4646
assert flags[4:8] == ["--env-file", "/builds/x/a.env", "--env-file", "/builds/x/b.env"]
4747

48+
def test_tmpfs_string_form(self) -> None:
49+
# S108 flags "/tmp" as an insecure hardcoded temp path; this is a
50+
# pass-through string being tested, not a file write.
51+
flags = run_flags("app", {"image": "x", "tmpfs": "/tmp:mode=1777"}, "p", [], "/builds/x") # noqa: S108
52+
assert flags[4:6] == ["--tmpfs", "/tmp:mode=1777"] # noqa: S108
53+
54+
def test_tmpfs_list_form(self) -> None:
55+
svc = {"image": "x", "tmpfs": ["/tmp:mode=1777", "/run"]} # noqa: S108
56+
flags = run_flags("app", svc, "p", [], "/builds/x")
57+
assert flags[4:8] == ["--tmpfs", "/tmp:mode=1777", "--tmpfs", "/run"] # noqa: S108
58+
4859
def test_absolute_volume_source_is_kept_as_is(self) -> None:
4960
flags = run_flags("app", {"image": "x", "volumes": ["/data/app:/srv/www/"]}, "p", [], "/builds/x")
5061
assert flags[4:6] == ["-v", "/data/app:/srv/www/"]

‎tests/test_parsing.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ def test_service_hostname_is_accepted(self) -> None:
127127
def test_service_container_name_is_accepted(self) -> None:
128128
compose = {"services": {"application": {"image": "x", "container_name": "calutron-ronline"}}}
129129
assert validate(compose) == []
130+
131+
def test_service_tmpfs_is_accepted(self) -> None:
132+
compose = {"services": {"app": {"image": "x", "tmpfs": ["/tmp:mode=1777"]}}} # noqa: S108
133+
assert validate(compose) == []

0 commit comments

Comments
 (0)