diff --git a/.gitignore b/.gitignore index df2600f..32befa2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ deb_dist *.pyc .coverage build -rocker_venv \ No newline at end of file +rocker_venv +.vscode diff --git a/README.md b/README.md index 38f14f2..98c0f05 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ You can get full details on the extensions from the main `rocker --help` command - home -- Mount the user's home directory into the container - pulse -- Mount pulse audio into the container - ssh -- Pass through ssh access to the container. +- install_pkgs -- Install a list of additional packages not in the base image As well as access to many of the docker arguments as well such as `device`, `env`, `volume`, `name`, `network`, `ipc`, and `privileged`. diff --git a/setup.py b/setup.py index 2cc1d9d..a73f429 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ 'home = rocker.extensions:HomeDir', 'hostname = rocker.extensions:Hostname', 'ipc = rocker.extensions:Ipc', + 'install_pkgs = rocker.install_pkgs_extension:InstallPkgs', 'name = rocker.extensions:Name', 'network = rocker.extensions:Network', 'nvidia = rocker.nvidia_extension:Nvidia', diff --git a/src/rocker/install_pkgs_extension.py b/src/rocker/install_pkgs_extension.py new file mode 100644 index 0000000..da2556e --- /dev/null +++ b/src/rocker/install_pkgs_extension.py @@ -0,0 +1,43 @@ +import em +import pkgutil +from rocker.extensions import RockerExtension + + +class InstallPkgs(RockerExtension): + + name = 'install_pkgs' + + @classmethod + def get_name(cls): + return cls.name + + def __init__(self): + self._env_subs = None + self.name = InstallPkgs.get_name() + + def precondition_environment(self, cli_args): + pass + + def validate_environment(self, cli_args): + pass + + def get_preamble(self, cli_args): + return '' + + def get_snippet(self, cli_args): + pkgs = set(cli_args['install_pkgs']) + args = {'packages': list(pkgs)} + + snippet = pkgutil.get_data( + 'rocker', 'templates/{}_snippet.Dockerfile.em'.format(self.name)).decode('utf-8') + + return em.expand(snippet, args) + + @staticmethod + def register_arguments(parser, defaults={}): + parser.add_argument('--install-pkgs', + nargs='+', + help='Installs specified packages in container') + + # todo add argument to install common development packages by category + # (e.g dev, debug, viz, sim, etc) that are not in the base image diff --git a/src/rocker/templates/install_pkgs_snippet.Dockerfile.em b/src/rocker/templates/install_pkgs_snippet.Dockerfile.em new file mode 100644 index 0000000..30c0106 --- /dev/null +++ b/src/rocker/templates/install_pkgs_snippet.Dockerfile.em @@ -0,0 +1,7 @@ +# User specified additional packages +RUN export DEBIAN_FRONTEND=noninteractive; \ + apt-get update \ + @# List each package specified in packages list + && apt-get install -y @[for package in packages] @package @[end for] \ + # Clean + && apt-get clean