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.
command()[source]

Shell command to run. Override this or run().

Should either return a list of strings to pass to subprocess.check_output, or a string, in which case shell=True will be passed with subprocess.check_output..

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.
command()[source]

Shell command to run. Override this or run().

Should either return a list of strings to pass to subprocess.check_output, or a string, in which case shell=True will be passed with subprocess.check_output..

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.
run()[source]

Run the Action command(s).

The default implementation runs the command returned by command().

str
The output of the command
subprocess.CalledProcessError
On execution failure.
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.
run()[source]

Run the Action command(s).

The default implementation runs the command returned by command().

str
The output of the command
subprocess.CalledProcessError
On execution failure.
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.
command()[source]

Shell command to run. Override this or run().

Should either return a list of strings to pass to subprocess.check_output, or a string, in which case shell=True will be passed with subprocess.check_output..

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
run()[source]

Run the Action command(s).

The default implementation runs the command returned by command().

str
The output of the command
subprocess.CalledProcessError
On execution failure.
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.
run()[source]

Run the Action command(s).

The default implementation runs the command returned by command().

str
The output of the command
subprocess.CalledProcessError
On execution failure.
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.