Skip to content

Commit

Permalink
Switch behavior of nvida based on 18.04 vs 16.04
Browse files Browse the repository at this point in the history
Partial solution for #14
  • Loading branch information
tfoote committed Jan 10, 2019
1 parent a21ef20 commit 1cb41a6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import getpass
import pkgutil
from pathlib import Path

import subprocess
import sys

import distro

Expand Down Expand Up @@ -94,34 +94,35 @@ def __init__(self):
self.env_subs = None
self.name = Nvidia.get_name()
self.xauth = '/tmp/.docker.xauth'
self.supported_distros = ['ubuntu']
self.supported_versions = ['16.04', '18.04']


def get_environment_subs(self):
def get_environment_subs(self, cliargs={}):
if not self.env_subs:
self.env_subs = {}
self.env_subs['user_id'] = os.getuid()
self.env_subs['username'] = getpass.getuser()
self.env_subs['DISPLAY'] = os.getenv('DISPLAY')
self.env_subs['distro_id'] = distro.id()
if self.env_subs['distro_id'] != 'ubuntu':
print("WARNING distro id %s not supported by Nvidia " % self.env_subs['distro_id'])
self.env_subs['distro_id'] = cliargs['distro_id'] if 'distro_id' in cliargs and cliargs['distro_id'] else distro.id()
if self.env_subs['distro_id'] not in self.supported_distros:
print("WARNING distro id %s not supported by Nvidia supported " % self.env_subs['distro_id'], self.supported_distros)
sys.exit(1)
self.env_subs['distro_version'] = distro.version()
self.env_subs['distro_version'] = cliargs['distro_version'] if 'distro_version' in cliargs and cliargs['distro_version'] else distro.version()
if self.env_subs['distro_version'] not in self.supported_versions:
print("WARNING distro version %s not in supported list by Nvidia " % self.env_subs['distro_id'])
print("WARNING distro version %s not in supported list by Nvidia supported versions" % self.env_subs['distro_version'], self.supported_versions)
sys.exit(1)
# TODO(tfoote) add a standard mechanism for checking preconditions and disabling plugins

return self.env_subs

def get_preamble(self, cliargs):
preamble = pkgutil.get_data('rocker', 'templates/%s_preamble.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(preamble, self.get_environment_subs())
return em.expand(preamble, self.get_environment_subs(cliargs))

def get_snippet(self, cliargs):
snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(snippet, self.get_environment_subs())
return em.expand(snippet, self.get_environment_subs(cliargs))

def get_docker_args(self, cliargs):
xauth = self.xauth
Expand Down

0 comments on commit 1cb41a6

Please sign in to comment.