scripts/container
Source file repositories/reference/linux-study-clean/scripts/container
File Facts
- System
- Linux kernel
- Corpus path
scripts/container- Extension
[no extension]- Size
- 5996 bytes
- Lines
- 200
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) 2025 Guillaume Tucker
"""Containerized builds"""
import abc
import argparse
import logging
import os
import pathlib
import shutil
import subprocess
import sys
import uuid
class ContainerRuntime(abc.ABC):
"""Base class for a container runtime implementation"""
name = None # Property defined in each implementation class
def __init__(self, args, logger):
self._uid = args.uid or os.getuid()
self._gid = args.gid or args.uid or os.getgid()
self._env_file = args.env_file
self._shell = args.shell
self._logger = logger
@classmethod
def is_present(cls):
"""Determine whether the runtime is present on the system"""
return shutil.which(cls.name) is not None
@abc.abstractmethod
def _do_run(self, image, cmd, container_name):
"""Runtime-specific handler to run a command in a container"""
@abc.abstractmethod
def _do_abort(self, container_name):
"""Runtime-specific handler to abort a running container"""
def run(self, image, cmd):
"""Run a command in a runtime container"""
container_name = str(uuid.uuid4())
self._logger.debug("container: %s", container_name)
try:
return self._do_run(image, cmd, container_name)
except KeyboardInterrupt:
self._logger.error("user aborted")
self._do_abort(container_name)
return 1
class CommonRuntime(ContainerRuntime):
"""Common logic for Docker and Podman"""
def _do_run(self, image, cmd, container_name):
cmdline = [self.name, 'run']
cmdline += self._get_opts(container_name)
cmdline.append(image)
cmdline += cmd
self._logger.debug('command: %s', ' '.join(cmdline))
return subprocess.call(cmdline)
def _get_opts(self, container_name):
opts = [
'--name', container_name,
'--rm',
'--volume', f'{pathlib.Path.cwd()}:/src',
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.