dockershit
dockershit.dockershit
parse_args
def parse_args(argv: list[str] = sys.argv[1:])
Nobody likes an argument, but sometimes you just have to parse them.
run
def run(path: str,
image: str,
shell: str,
tag: str,
debug: bool,
engine_name="auto")
The input loop.
main
def main(argv: str = sys.argv[1:])
The main course.
dockershit.engine
Container engines used to run commands and build images.
Engine Objects
class Engine(ABC)
The container operations dockershit needs.
build
@abstractmethod
def build(dockerfile, tag, debug=False)
Build and tag an image from a Dockerfile.
run
@abstractmethod
def run(workdir, tag, shell, command)
Run a command in a throwaway container.
is_top_layer_empty
@abstractmethod
def is_top_layer_empty(tag)
Return whether the newest image layer contains no filesystem changes.
CommandEngine Objects
class CommandEngine(Engine)
Shared command-line behavior for Docker-compatible engines.
select_engine
def select_engine(name="auto")
Select an installed engine, preferring Podman in auto mode.
dockershit.docker_file
For dealing with Dockerfiles
Dockerfile Objects
class Dockerfile()
parse_lines
def parse_lines(raw_lines: list[str]) -> list[str]
Parses multi-line commands into single lines
exists
def exists() -> bool
Returns True if the file exists
set_image
def set_image(image: str)
Sets the base image, in text. Example: “alpine:latest”
cd
def cd(pwd: str)
Set the working directory for the Dockerfile
resolve_workdir
def resolve_workdir(pwd: str)
Resolve a path relative to the current working directory.
append_many
def append_many(lines)
Append logical lines with one atomic file replacement.
append_comment
def append_comment(line, reason)
Append a comment that is safe even when the input spans lines.
snapshot
def snapshot()
Capture the exact file contents for transactional restoration.
restore
def restore(snapshot: DockerfileSnapshot)
Restore an exact snapshot and recompute derived state.
remove_last_command
def remove_last_command(reason: str = "removed")
Actually comment it out then reload the file
save
def save()
Write the thing to a file
dockershit.docker
BrokenBaselineError Objects
class BrokenBaselineError(RuntimeError)
The Dockerfile still fails after the candidate change is restored.
Session Objects
class Session()
build
def build()
Build the current Dockerfile without changing it on failure.
apply
def apply(instruction, change, check_noop=False)
Apply and build one Dockerfile change as a transaction.
run
def run(cmd)
Run a command in a throwaway container.
dockershit.command
Helpers for dealing with commands
split_command
def split_command(line: str) -> str
Get the command and args from a line
is_dockerfile
def is_dockerfile(line: str) -> bool
Case sensitive to avoid shell mismatches
is_simple
def is_simple(line: str) -> bool
Just a command with params; no operators, subshells, pipes, redirects or any of that fancy stuff.
is_hidden
def is_hidden(line: str) -> bool
If this line should be hidden
matters
def matters(line: str) -> bool
Does this line even do anything?
flatten
def flatten(lines: str) -> str
Flatten a multi-line command into a single line
dockershit.keyboard
Keyboard Objects
class Keyboard()
input
def input()
Get input from the user, with multi-line continuation via backslash.