Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added install pkgs extension #295

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should at least validate the environment here is debian if this will only work for debian packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does validate_environment get called anywhere? It seems like it's not used unless I'm missing something

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well that's a regression. It should be being validated at the build stage. It looks like that was lost along the way.

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; \
Copy link
Collaborator

Choose a reason for hiding this comment

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

This template only works for debian like systems. It should be documented.

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
Loading