Skip to content

Commit e669f52

Browse files
committed
container: T7185: Allow tmpfs mounts within containers
1 parent 4d9d45a commit e669f52

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

interface-definitions/container.xml.in

+25
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,31 @@
412412
</constraint>
413413
</properties>
414414
</leafNode>
415+
<tagNode name="tmpfs">
416+
<properties>
417+
<help>Mount a tmpfs filesystem into the container</help>
418+
</properties>
419+
<children>
420+
<leafNode name="destination">
421+
<properties>
422+
<help>Destination container directory</help>
423+
<valueHelp>
424+
<format>txt</format>
425+
<description>Destination container directory</description>
426+
</valueHelp>
427+
</properties>
428+
</leafNode>
429+
<leafNode name="size">
430+
<properties>
431+
<help>Filesystem size in MB</help>
432+
<valueHelp>
433+
<format>u32</format>
434+
<description>Filesystem size in MB</description>
435+
</valueHelp>
436+
</properties>
437+
</leafNode>
438+
</children>
439+
</tagNode>
415440
<tagNode name="volume">
416441
<properties>
417442
<help>Mount a volume into the container</help>

src/conf_mode/container.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ def verify(container):
223223
if not os.path.exists(source):
224224
raise ConfigError(f'Volume "{volume}" source path "{source}" does not exist!')
225225

226+
if 'tmpfs' in container_config:
227+
for tmpfs, tmpfs_config in container_config['tmpfs'].items():
228+
if 'destination' not in tmpfs_config:
229+
raise ConfigError(f'tmpfs "{tmpfs}" has no destination path configured!')
230+
if 'size' not in tmpfs_config:
231+
raise ConfigError(f'tmpfs "{tmpfs}" has no size configured!')
232+
226233
if 'port' in container_config:
227234
for tmp in container_config['port']:
228235
if not {'source', 'destination'} <= set(container_config['port'][tmp]):
@@ -362,6 +369,14 @@ def generate_run_arguments(name, container_config):
362369
prop = vol_config['propagation']
363370
volume += f' --volume {svol}:{dvol}:{mode},{prop}'
364371

372+
# Mount tmpfs
373+
tmpfs = ''
374+
if 'tmpfs' in container_config:
375+
for tmpfs_config in container_config['tmpfs'].values():
376+
dest = tmpfs_config['destination']
377+
size = tmpfs_config['size']
378+
tmpfs += f' --mount=type=tmpfs,tmpfs-size={size}M,destination={dest}'
379+
365380
host_pid = ''
366381
if 'allow_host_pid' in container_config:
367382
host_pid = '--pid host'
@@ -373,7 +388,7 @@ def generate_run_arguments(name, container_config):
373388

374389
container_base_cmd = f'--detach --interactive --tty --replace {capabilities} --cpus {cpu_quota} {sysctl_opt} ' \
375390
f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \
376-
f'--name {name} {hostname} {device} {port} {name_server} {volume} {env_opt} {label} {uid} {host_pid}'
391+
f'--name {name} {hostname} {device} {port} {name_server} {volume} {tmpfs} {env_opt} {label} {uid} {host_pid}'
377392

378393
entrypoint = ''
379394
if 'entrypoint' in container_config:

0 commit comments

Comments
 (0)