Ejemplo n.º 1
0
    def __init__(self, config, name=None):
        self.config = config
        self.clickable_dir = '.clickable/{}'.format(self.config.build_arch)
        if name:
            self.clickable_dir = '{}/{}'.format(self.clickable_dir, name)
        self.docker_name_file = '{}/name.txt'.format(self.clickable_dir)
        self.docker_file = '{}/Dockerfile'.format(self.clickable_dir)

        if not self.config.container_mode:
            if self.config.lxd:
                print_warning(
                    'Use of lxd is deprecated and will be removed in a future version'
                )
                check_command('usdk-target')
            else:
                check_command('docker')

                self.docker_image = self.config.docker_image
                self.base_docker_image = self.docker_image

                if self.docker_image in self.config.container_list:
                    self.base_docker_image = self.docker_image

                    if os.path.exists(self.docker_name_file):
                        self.restore_cached_container()
Ejemplo n.º 2
0
    def setup_docker(self):
        print_info('Setting up docker')

        check_command('docker')
        self.start_docker()

        if not self.docker_group_exists():
            print_info('Asking for root to create docker group')
            subprocess.check_call(shlex.split('sudo groupadd docker'))

        if self.user_part_of_docker_group():
            print_info('Setup has already been completed')
        else:
            print_info('Asking for root to add the current user to the docker group')
            subprocess.check_call(shlex.split('sudo usermod -aG docker {}'.format(getpass.getuser())))

            raise Exception('Log out or restart to apply changes')
Ejemplo n.º 3
0
    def __init__(self, config, name=None):
        self.config = config
        self.clickable_dir = '.clickable/{}'.format(self.config.build_arch)
        if name:
            self.clickable_dir = '{}/{}'.format(self.clickable_dir, name)
        self.docker_name_file = '{}/name.txt'.format(self.clickable_dir)
        self.docker_file = '{}/Dockerfile'.format(self.clickable_dir)

        if not self.config.container_mode:
            check_command('docker')

            self.docker_image = self.config.docker_image
            self.base_docker_image = self.docker_image

            if self.docker_image in self.config.container_list:
                self.base_docker_image = self.docker_image

                if os.path.exists(self.docker_name_file):
                    self.restore_cached_container()
Ejemplo n.º 4
0
    def setup_docker(self):
        logger.info('Setting up docker')

        check_command('docker')
        self.start_docker()

        if not self.docker_group_exists():
            logger.info('Asking for root to create docker group')
            subprocess.check_call(shlex.split('sudo groupadd docker'))

        if self.user_part_of_docker_group():
            logger.info('Setup has already been completed')
        else:
            logger.info(
                'Asking for root to add the current user to the docker group')
            subprocess.check_call(
                shlex.split('sudo usermod -aG docker {}'.format(
                    getpass.getuser())))

            raise ClickableException('Log out or restart to apply changes')
Ejemplo n.º 5
0
    def __init__(self, config):
        self.config = config

        if not self.config.container_mode:
            if self.config.lxd:
                print_warning(
                    'Use of lxd is deprecated and will be removed in a future version'
                )
                check_command('usdk-target')
            else:
                check_command('docker')

                self.docker_image = self.config.docker_image
                self.base_docker_image = self.docker_image

                if 'clickable/ubuntu-sdk' in self.docker_image:
                    if self.config.use_nvidia:
                        self.docker_image += '-nvidia'
                        check_command('nvidia-docker')

                    self.base_docker_image = self.docker_image

                    if os.path.exists('.clickable/name.txt'):
                        with open('.clickable/name.txt', 'r') as f:
                            self.docker_image = f.read().strip()
Ejemplo n.º 6
0
    def __init__(self, config):
        self.config = config
        self.clickableDir = '.clickable/{}'.format(self.config.build_arch)
        self.dockerNameFile = '{}/name.txt'.format(self.clickableDir)
        self.dockerFile = '{}/Dockerfile'.format(self.clickableDir)

        if not self.config.container_mode:
            if self.config.lxd:
                print_warning('Use of lxd is deprecated and will be removed in a future version')
                check_command('usdk-target')
            else:
                check_command('docker')

                self.docker_image = self.config.docker_image
                self.base_docker_image = self.docker_image

                if 'clickable/ubuntu-sdk' in self.docker_image:
                    if self.config.use_nvidia:
                        self.docker_image += '-nvidia'
                        check_command('nvidia-docker')

                    self.base_docker_image = self.docker_image

                    if os.path.exists(self.dockerNameFile):
                        with open(self.dockerNameFile, 'r') as f:
                            self.docker_image = f.read().strip()
Ejemplo n.º 7
0
    def run(self, path_arg=None):
        if self.config.lxd:
            raise Exception('Using lxd for desktop mode is not supported')

        clean = CleanCommand(self.config)
        clean.run()
        build = BuildCommand(self.config)
        build.run()

        desktop_path = None
        hooks = self.config.get_manifest().get('hooks', {})
        app = self.config.find_app_name()
        if app:
            if app in hooks and 'desktop' in hooks[app]:
                desktop_path = hooks[app]['desktop']
        else:
            for key, value in hooks.items():
                if 'desktop' in value:
                    desktop_path = value['desktop']
                    break

        if not desktop_path:
            raise Exception(
                'Could not find desktop file for app "{}"'.format(app))

        desktop_path = os.path.join(self.config.temp, desktop_path)
        if not os.path.exists(desktop_path):
            raise Exception(
                'Could not desktop file does not exist: "{}"'.format(
                    desktop_path))

        execute = None
        with open(desktop_path, 'r') as desktop_file:
            lines = desktop_file.readlines()
            for line in lines:
                if line.startswith('Exec='):
                    execute = line.replace('Exec=', '')
                    break

        if not execute:
            raise Exception('No "Exec" line found in the desktop file')
        else:
            execute = execute.strip()

        # Inspired by https://stackoverflow.com/a/1160227
        xauth = '/tmp/.docker.xauth'
        with open(xauth, 'a'):
            os.utime(xauth, None)

        self.container.check_docker()

        share = '/tmp/clickable/share'
        if not os.path.isdir(share):
            os.makedirs(share)

        cache = '/tmp/clickable/cache'
        if not os.path.isdir(cache):
            os.makedirs(cache)

        config = '/tmp/clickable/config'
        if not os.path.isdir(config):
            os.makedirs(config)

        volumes = '-v {}:{} -v /tmp/.X11-unix:/tmp/.X11-unix -v {}:{} -v {}:/tmp/.local/share -v {}:/tmp/.cache -v {}:/tmp/.config'.format(
            self.config.cwd,
            self.config.cwd,
            xauth,
            xauth,
            share,
            cache,
            config,
        )

        if self.config.use_nvidia:
            volumes += ' -v /dev/snd/pcmC2D0c:/dev/snd/pcmC2D0c -v /dev/snd/controlC2:/dev/snd/controlC2 --device /dev/snd'

        lib_path = ':'.join([
            os.path.join(self.config.temp, 'lib/x86_64-linux-gnu'),
            os.path.join(self.config.temp, 'lib'),
            '/usr/local/nvidia/lib',
            '/usr/local/nvidia/lib64',
        ])

        path = ':'.join([
            '/usr/local/nvidia/bin',
            '/bin',
            '/usr/bin',
            os.path.join(self.config.temp, 'bin'),
            os.path.join(self.config.temp, 'lib/x86_64-linux-gnu/bin'),
            self.config.temp,
        ])
        environment = '-e XAUTHORITY=/tmp/.docker.xauth -e DISPLAY={} -e QML2_IMPORT_PATH={} -e LD_LIBRARY_PATH={} -e PATH={} -e HOME=/tmp -e OXIDE_NO_SANDBOX=1'.format(
            os.environ['DISPLAY'],
            lib_path,
            lib_path,
            path,
        )

        if execute.startswith('webapp-container'):
            # This is needed for the webapp-container, so only do it for this case
            volumes = '{} -v /etc/passwd:/etc/passwd'.format(volumes)
            environment = '{} -e APP_ID={}'.format(
                environment, self.config.find_package_name())

        go_config = ''
        if self.config.gopath:
            go_config = '-v {}:/gopath -e GOPATH=/gopath'.format(
                self.config.gopath)

        run_xhost = False
        try:
            check_command('xhost')
            run_xhost = True
        except Exception:  # TODO catch a specific Exception
            print_warning('xhost not installed, desktop mode may fail')
            run_xhost = False

        if run_xhost:
            subprocess.check_call(shlex.split('xhost +local:docker'))

        command = '{} run {} {} {} -w {} -u {} --rm -i {} bash -c "{}"'.format(
            'nvidia-docker' if self.config.use_nvidia else 'docker',
            volumes,
            go_config,
            environment,
            self.config.temp,
            os.getuid(),
            self.container.docker_image,
            execute,
        )

        subprocess.check_call(shlex.split(command), cwd=self.config.temp)
Ejemplo n.º 8
0
 def is_xhost_installed(self):
     try:
         check_command('xhost')
         return True
     except Exception:  # TODO catch a specific Exception
         return False