Skip to content

Commit

Permalink
Added install pkgs extension
Browse files Browse the repository at this point in the history
  • Loading branch information
agyoungs committed Oct 30, 2024
1 parent 3c9ea15 commit 3ee9b75
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ deb_dist
*.pyc
.coverage
build
rocker_venv
rocker_venv
.vscode
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
43 changes: 43 additions & 0 deletions src/rocker/install_pkgs_extension.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3ee9b75

Please sign in to comment.