def command_inspect(args): 'Implements the inspect subcommand' command_line = [ 'docker', 'run', '-it', '--entrypoint', args.shell, ] if 'submission' in args and args.submission is not None: command_line.append('-v') command_line.append(common.mk_submission_volume_str(args.submission)) if not args.allow_network: command_line.append('--net') command_line.append('none') if not args.unlimited_memory: command_line.append('-m') command_line.append('1g') if not args.no_rm: command_line.append('--rm') if not args.super_user: # Note: docker run CLI doesn't support setting the group. :-( command_line.append('-u') command_line.append('1000') command_line.append(args.containerId) logging.debug("About to execute command: %s", ' '.join(command_line)) os.execvp('docker', command_line)
def command_grade_local(args): """ The 'local' sub-sub-command of the 'grade' sub-command simulates running a grader on a sample submission from the local file system. """ # TODO: Support arguments to pass to the graders. d = utils.docker_client(args) try: volume_str = common.mk_submission_volume_str(args.dir) logging.debug("Volume string: %s", volume_str) container = d.create_container( image=args.containerId, user='******' % 1000, host_config=docker.utils.create_host_config( binds=[volume_str, ], network_mode='none', mem_limit='1g', memswap_limit='1g', ), ) except: logging.error( "Could not set up the container to run the grade command in. Most " "likely, this means that you specified an inappropriate container " "id.") raise run_container(d, container, args)
def command_inspect(args): 'Implements the inspect subcommand' command_line = [ 'docker', 'run', '-it', '--entrypoint', args.shell, ] if 'submission' in args and args.submission is not None: command_line.append('-v') command_line.append(common.mk_submission_volume_str(args.submission)) if not args.allow_network: command_line.append('--net') command_line.append('none') if not args.unlimited_memory: command_line.append('-m') command_line.append('1g') if not args.super_user: # Note: docker run CLI doesn't support setting the group. :-( command_line.append('-u') command_line.append('1000') command_line.append(args.containerId) logging.debug("About to execute command: %s", ' '.join(command_line)) os.execvp('docker', command_line)
def command_grade_local(args): """ The 'local' sub-sub-command of the 'grade' sub-command simulates running a grader on a sample submission from the local file system. """ d = utils.docker_client(args) memory_limit = compute_memory_limit(args) try: volume_str = common.mk_submission_volume_str(args.dir) logging.debug("Volume string: %s", volume_str) extra_hosts = { 'somehost': "192.168.1.2", } host_config = d.create_host_config( binds=[ volume_str, ], network_mode='none', mem_limit=memory_limit, memswap_limit=memory_limit, extra_hosts=extra_hosts, ) user = '******' % 1000 if 'args' in args and len(args.args) > 0: # Handle additional command-line arguments which will # be passed to the grader. inspect = d.inspect_image(image=args.imageId) cmd = inspect['Config']['Entrypoint'] if not type(cmd) is list: logging.error('ENTRYPOINT in Dockerfile must be a list in ' + 'order to pass in command-line arguments') raise cmd.extend(args.args) container = d.create_container( image=args.imageId, entrypoint=cmd, user=user, host_config=host_config, hostname='somehost', ) else: container = d.create_container( image=args.imageId, user=user, host_config=host_config, ) except: logging.error( "Could not set up the container to run the grade command in. Most " "likely, this means that you specified an inappropriate container " "id.") raise run_container(d, container, args)
def command_grade_local(args): """ The 'local' sub-sub-command of the 'grade' sub-command simulates running a grader on a sample submission from the local file system. """ d = utils.docker_client(args) memory_limit = compute_memory_limit(args) try: volume_str = common.mk_submission_volume_str(args.dir) logging.debug("Volume string: %s", volume_str) host_config = d.create_host_config( binds=[volume_str, ], network_mode='none', mem_limit=memory_limit, memswap_limit=memory_limit, ) user = '******' % 1000 if 'args' in args and len(args.args) > 0: # Handle additional command-line arguments which will # be passed to the grader. inspect = d.inspect_image(image=args.imageId) cmd = inspect['Config']['Entrypoint'] if not type(cmd) is list: logging.error('ENTRYPOINT in Dockerfile must be a list in ' + 'order to pass in command-line arguments') raise cmd.extend(args.args) container = d.create_container( image=args.imageId, entrypoint=cmd, user=user, host_config=host_config, ) else: container = d.create_container( image=args.imageId, user=user, host_config=host_config, ) except: logging.error( "Could not set up the container to run the grade command in. Most " "likely, this means that you specified an inappropriate container " "id.") raise run_container(d, container, args)