stuffer.files module¶
Actions that change contents of files.
-
class
stuffer.files.
Chmod
(permissions: int, path: Union[str, stuffer.content.DeferStr])[source]¶ Bases:
stuffer.core.Action
Set permissions for a file.
- permissions
- Read/write/execute permissions, expressed as a number. For readability, use Python octal numbers,
e.g.
0o755
. - path
- The path to the directory or file to change permissions on.
-
class
stuffer.files.
Chown
(owner: Union[str, stuffer.content.DeferStr], path: Union[str, stuffer.content.DeferStr], group: Optional[str] = None, recursive: bool = False)[source]¶ Bases:
stuffer.core.Action
Set ownership for file(s).
- owner
- Username that should own the file(s).
- path
- Path to directory or file to change ownership on.
- group
- Name of group to set on files.
- recursive
- If true, change files in all subdirectories.
-
class
stuffer.files.
Content
(path, contents, make_dirs=False)[source]¶ Bases:
stuffer.core.Action
Set the contents of a file.
- path
- Path to file
- contents
- Supplier or contents, or fixed value string. In order to dynamically supply content at image build time, use content.OutputOf.
- make_dirs
- If True, create parent directories if necessary.
-
class
stuffer.files.
DownloadFile
(url: Union[str, stuffer.content.DeferStr], path: Union[pathlib.Path, str, stuffer.content.DeferStr])[source]¶ Bases:
stuffer.core.Action
Download and install a single file from a URL.
- url
- URL to retrieve.
- path
- Path of destination file.
-
class
stuffer.files.
Mkdir
(path: Union[pathlib.Path, str, stuffer.content.DeferStr])[source]¶ Bases:
stuffer.core.Action
Create a directory, unless it exists.
- path
- Path of directory to create.
-
class
stuffer.files.
SysctlConf
(name: str, key: str, value: Union[int, str])[source]¶ Bases:
stuffer.files.Content
Set sysctl parameter in /etc/sysctl.d.
- name
- Name of file, without .conf suffix
- key
- Sysctl key to set
- value
- Value of key
-
class
stuffer.files.
Transform
(path: Union[pathlib.Path, str, stuffer.content.DeferStr], transform: Callable[str, str])[source]¶ Bases:
stuffer.core.Action
Transform the contents of a file by applying a function on the contents.
- path
- Path to file whose contents should be transformed.
- transform
- Function that manipulate file contents and return the new content.
-
stuffer.files.
write_file_atomically
(path: Union[pathlib.Path, str, stuffer.content.DeferStr], contents: Union[str, stuffer.content.DeferStr], make_dirs: bool = False, suffix: Union[str, stuffer.content.DeferStr] = '.stuffer_tmp')[source]¶ Write contents to a file in an atomic manner.
This routine prevents corruption in case other processes on the machine read or write the file while it is executed. It is overkill for Docker image building, but provides better safety when stuffer is run on live machines, e.g. developer machines, or when building other types of images, such as AMIs with packer.
- path
- Path of destination file.
- contents
- Contents of file
- make_dirs
- If true, create parent directories if necessary.
- suffix
- Extra suffix added on temporary file.