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

[ENH]: Change uid and gid permissions on bucket creation #29

Open
wants to merge 4 commits into
base: develop
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
12 changes: 9 additions & 3 deletions resen/Resen.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,15 @@ def create_container(self,**input_kwargs):
image_name = input_kwargs.get('image_name',None)
image_id = input_kwargs.get('image_id',None)
pull_image = input_kwargs.get('pull_image',None)

nb_uid = input_kwargs.get('nb_uid',os.getuid())
nb_gid = input_kwargs.get('nb_gid',os.getgid())

# TODO: jupyterlab or jupyter notebook, pass ports, mount volumes, generate token for lab/notebook server
create_kwargs = dict()
create_kwargs['name'] = self.container_prefix + bucket_name
create_kwargs['command'] = 'bash'
create_kwargs['command'] = '/usr/local/bin/start.sh bash'
create_kwargs['tty'] = True
create_kwargs['environment'] = ['NB_UID=%s' % nb_uid, 'NB_GID=%s' % nb_gid]
create_kwargs['ports'] = dict()

for host, container, tcp in ports:
Expand Down Expand Up @@ -677,7 +679,11 @@ def create_container(self,**input_kwargs):
print("Done!")

container_id = self.docker.containers.create(image_id,**create_kwargs)

status = self.start_container(container_id.id)
# setup the user and group permissions
result = container_id.exec_run(create_kwargs['command'],
environment=create_kwargs['environment'],
user='root',detach=True)
return container_id.id

def stream_pull_image(self,pull_image):
Expand Down
19 changes: 8 additions & 11 deletions resen/resencmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def do_create_bucket(self,args):
print("Syntax Error. Usage: create_bucket bucket_name")
return

# check if creating bucket with name bucket_name is possible:
print("Creating bucket with name: %s" % bucket_name)
status = self.program.create_bucket(bucket_name)
if not status:
print("Failed to create bucket!")
return

# First, ask user about the bucket they want to create
# resen-core version?
valid_versions = sorted([x['version'] for x in self.program.bucket_manager.valid_cores])
Expand Down Expand Up @@ -93,13 +100,6 @@ def do_create_bucket(self,args):
msg = '>>> Start bucket and jupyterlab? (y/n): '
start = self.get_valid_input(msg,valid_inputs) == 'y'

# Now that we have the bucket creation recipe, let's actually create it.
print("Creating bucket with name: %s" % bucket_name)
status = self.program.create_bucket(bucket_name)
if not status:
print("Failed to create bucket!")
return

success = True
print("...adding core...")
status = self.program.add_image(bucket_name,docker_image)
Expand All @@ -118,10 +118,7 @@ def do_create_bucket(self,args):
if success:
print("Bucket created successfully!")
if start:
# start bucket
status = self.program.start_bucket(bucket_name)
if not status:
return
# bucket should already be running
# start jupyterlab
print("...starting jupyterlab...")
status = self.program.start_jupyter(bucket_name,local_port,container_port,lab=True)
Expand Down