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 cff5cb2 commit cad50d6
Show file tree
Hide file tree
Showing 5 changed files with 54 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
7 changes: 7 additions & 0 deletions src/rocker/templates/install_pkgs_snippet.Dockerfile.em
Original file line number Diff line number Diff line change
@@ -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

1 comment on commit cad50d6

@blooop
Copy link

@blooop blooop commented on cad50d6 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it is trying to do a similar thing to: https://github.com/blooop/deps_rocker

Please sign in to comment.