Docker Interface (rever.docker
)¶
Dockers tools for rever.
-
class
rever.docker.
InContainer
(image=None, lang='xonsh', args=('-c'), env=True, mounts=(), **kwargs)¶ Macro context manager for running code within a container. This runs a command of the following form within the container:
lang args block
For example:
xonsh -c "echo Wow Mom!\n"
This allows you to run your own code within a container without having to worry about polluting the local namespace.
- Parameters
- imagestr or None, optional
Name of the image to run, defaults to $DOCKER_INSTALL_IMAGE. Environment variables will be expanded.
- langstr, optional
Language to execute the body in, default xonsh. This may also be a full path to an executable.
- argssequence of str, optional
Extra arguments to pass in after the executable but before the main body. Defaults to the standard compile flag
'-c'
.- envbool or dict, optional
Environment to use. This has the same meaning as in
run_in_container()
. Please see that function for more details, default True.- mountslist of dict, optional
Locations to mount in the running container. This has the same meaning as ing
run_in_container()
. Please see that function for more details, default does not mount anything.- kwargsdict, optional
All other keyword arguments are passed into
ensure_images()
when the context is entered.
-
rever.docker.
apt_deps
(apt=None)¶ Constructs apt-based install command
-
rever.docker.
build_image
(dockerfile, image, maker, **kwargs)¶ Builds a docker image.
-
rever.docker.
collate_deps
(apt=None, conda=None, conda_channels=None, pip=None, pip_requirements=None)¶ Constructs a string that installs all known dependencies.
-
rever.docker.
conda_deps
(conda=None, conda_channels=None)¶ Constructs conda-based install command
-
rever.docker.
docker_envvars
(envvars=None)¶ Constructs a string that sets envvars in docker from a dictionary mapping environment variable names to value strings.
-
rever.docker.
docker_root
(root=None)¶ Gets the root-level directory for the repo that docker should use.
-
rever.docker.
docker_source_from
(source=None, url=None, root=None, workdir=None)¶ This constructs a docker command detailing how to get the source code for the project. In order of precedence, this will use,
A command as provided by source or $DOCKER_INSTALL_SOURCE
A URL to clone with $REVER_VCS as provided by url or $DOCKER_INSTALL_URL
A directory on the file system, defaulting to $DOCKER_ROOT or the root directory of the project repo.
-
rever.docker.
ensure_images
(base_file=None, base_image=None, force_base=False, base_from=None, apt=None, conda=None, conda_channels=None, pip=None, pip_requirements=None, install_file=None, install_image=None, force_install=False, root=None, command=None, envvars=None, workdir=None, url=None, source=None)¶ This verifies that docker images have been built for rever, and builds them if they haven’t.
-
rever.docker.
git_configure
(name=None, email=None)¶ Make basic git configuration.
-
rever.docker.
incontainer
(*args, **kwargs)¶ Macro context manager for running code within a container.
- Parameters
- imagestr or None, optional
Name of the image to run, defaults to $DOCKER_INSTALL_IMAGE. Environment variables will be expanded.
- langstr, optional
Language to execute the body in, default xonsh. This may also be a full path to an executable.
- argssequence of str, optional
Extra arguments to pass in after the executable but before the main body. Defaults to the standard compile flag
'-c'
.- envbool or dict, optional
Environment to use. This has the same meaning as in
run_in_container()
. Please see that function for more details, default True.- mountslist of dict, optional
Locations to mount in the running container. This has the same meaning as in
run_in_container()
. Please see that function for more details, default does not mount anything.- kwargsdict, optional
All other keyword arguments are passed into
ensure_images()
when the context is entered.
- Returns
- New macro context manager InContainer instance.
-
rever.docker.
make_base_dockerfile
(base_from=None, apt=None, conda=None, conda_channels=None, pip=None, pip_requirements=None, git_name=None, git_email=None)¶ Constructs the base dockerfile.
-
rever.docker.
make_install_dockerfile
(base=None, root=None, command=None, envvars=None, workdir=None, url=None, source=None)¶ Constructs a dockerfile that installs the source code.
-
rever.docker.
mount_argument
(mount)¶ Creates a mount command argument from a mount dictionary.
-
rever.docker.
pip_deps
(pip=None, pip_requirements=None)¶ Constructs pip-based install command
-
rever.docker.
run_in_container
(image, command, env=True, mounts=())¶ Run a command inside of a docker container.
- Parameters
- imagestr
Name of the image to start the container with.
- commandlist of str
The command to run inside of the container.
- envbool or dict, optional
If False, not environment variables are passed down to the container. If True, all rever environment variables are passed into the container (default). Otherwise, this is a dictionary of enviroment variable names (str) to values (str).
- mountslist of dict, optional
This is a list of dictionaries that specifies files or directories, volumes, or temporary file systems to mount. Valid keys in the dictionary are:
'type'
'src'
or'source'
'dst'
or'destination'
or'target'
'ro'
or'readonly'
'consistency'
See https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-volumes-or-memory-filesystems for more information
-
rever.docker.
should_build_image
(dockerfile, image, maker, force=False, **kwargs)¶ Determines if we should (re)build the dockerfile image.
-
rever.docker.
supports_mount
()¶ Checks if docker run supports the –mount option.
-
rever.docker.
text_wrapper
()¶ Obtains docker text wrapper.
-
rever.docker.
validate_mount
(mount)¶ Validates a docker mount description. Returns a boolean flag and a message.
-
rever.docker.
volume_arguments
(mount)¶ Creates a list of volume arguments for older versions of docker that don’t support –mount.
-
rever.docker.
wrap
(s, indent='', suffix=' \\', width=70)¶ Wraps a dockerfile line.