mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Add --admin params to bootstrap / installer to set up admin accts
This removes a big step requiring file changes from the quickstart path. You can specify the admin username on the commandline.
This commit is contained in:
@@ -17,6 +17,7 @@ import urllib.request
|
|||||||
import contextlib
|
import contextlib
|
||||||
import hashlib
|
import hashlib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def md5_file(fname):
|
def md5_file(fname):
|
||||||
@@ -118,16 +119,22 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print('Upgrading TLJH installer...')
|
print('Upgrading TLJH installer...')
|
||||||
|
|
||||||
pip_install(hub_prefix, [
|
is_dev = os.environ.get('TLJH_BOOTSTRAP_DEV', 'no') == 'yes'
|
||||||
os.environ.get('TLJH_BOOTSTRAP_PIP_SPEC', 'git+https://github.com/yuvipanda/the-littlest-jupyterhub.git')
|
tljh_repo_path = os.environ.get(
|
||||||
], editable=os.environ.get('TLJH_BOOTSTRAP_DEV', 'no') == 'yes')
|
'TLJH_BOOTSTRAP_PIP_SPEC',
|
||||||
|
'git+https://github.com/yuvipanda/the-littlest-jupyterhub.git'
|
||||||
|
)
|
||||||
|
|
||||||
|
pip_install(hub_prefix, [tljh_repo_path], editable=is_dev)
|
||||||
|
|
||||||
print('Starting TLJH installer...')
|
print('Starting TLJH installer...')
|
||||||
os.execl(
|
os.execv(
|
||||||
os.path.join(hub_prefix, 'bin', 'python3'),
|
os.path.join(hub_prefix, 'bin', 'python3'),
|
||||||
os.path.join(hub_prefix, 'bin', 'python3'),
|
[
|
||||||
'-m',
|
os.path.join(hub_prefix, 'bin', 'python3'),
|
||||||
'tljh.installer'
|
'-m',
|
||||||
|
'tljh.installer',
|
||||||
|
] + sys.argv[1:]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
setup.py
3
setup.py
@@ -11,6 +11,7 @@ setup(
|
|||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'pyyaml==3.*'
|
'pyyaml==3.*',
|
||||||
|
'ruamel.yaml==0.15.*'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import tljh.systemd as systemd
|
|||||||
import tljh.conda as conda
|
import tljh.conda as conda
|
||||||
from tljh import user
|
from tljh import user
|
||||||
import secrets
|
import secrets
|
||||||
|
import argparse
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')
|
INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')
|
||||||
HUB_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'hub')
|
HUB_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'hub')
|
||||||
@@ -11,10 +13,13 @@ USER_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'user')
|
|||||||
|
|
||||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
rt_yaml = YAML()
|
||||||
|
|
||||||
|
|
||||||
def ensure_jupyterhub_service(prefix):
|
def ensure_jupyterhub_service(prefix):
|
||||||
"""
|
"""
|
||||||
Ensure JupyterHub & CHP Services are set up properly """
|
Ensure JupyterHub & CHP Services are set up properly
|
||||||
|
"""
|
||||||
with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f:
|
with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f:
|
||||||
hub_unit_template = f.read()
|
hub_unit_template = f.read()
|
||||||
|
|
||||||
@@ -62,16 +67,14 @@ def ensure_jupyterhub_package(prefix):
|
|||||||
conda.ensure_pip_packages(prefix, [
|
conda.ensure_pip_packages(prefix, [
|
||||||
'jupyterhub-dummyauthenticator==0.3.1',
|
'jupyterhub-dummyauthenticator==0.3.1',
|
||||||
'jupyterhub-systemdspawner==0.9.12',
|
'jupyterhub-systemdspawner==0.9.12',
|
||||||
'jupyterhub-firstuseauthenticator==0.9'
|
'jupyterhub-firstuseauthenticator==0.10'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def ensure_usergroups():
|
||||||
print("Setting up JupyterHub...")
|
"""
|
||||||
ensure_jupyterhub_package(HUB_ENV_PREFIX)
|
Sets up user groups & sudo rules
|
||||||
ensure_jupyterhub_service(HUB_ENV_PREFIX)
|
"""
|
||||||
|
|
||||||
print("Setting up system user groups...")
|
|
||||||
user.ensure_group('jupyterhub-admins')
|
user.ensure_group('jupyterhub-admins')
|
||||||
user.ensure_group('jupyterhub-users')
|
user.ensure_group('jupyterhub-users')
|
||||||
|
|
||||||
@@ -84,6 +87,11 @@ def main():
|
|||||||
# `pip` is in the $PATH we set in jupyterhub_config.py to include the user conda env.
|
# `pip` is in the $PATH we set in jupyterhub_config.py to include the user conda env.
|
||||||
f.write('Defaults exempt_group = jupyterhub-admins\n')
|
f.write('Defaults exempt_group = jupyterhub-admins\n')
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_user_environment():
|
||||||
|
"""
|
||||||
|
Set up user conda environment with required packages
|
||||||
|
"""
|
||||||
print("Setting up user environment...")
|
print("Setting up user environment...")
|
||||||
conda.ensure_conda_env(USER_ENV_PREFIX)
|
conda.ensure_conda_env(USER_ENV_PREFIX)
|
||||||
conda.ensure_conda_packages(USER_ENV_PREFIX, [
|
conda.ensure_conda_packages(USER_ENV_PREFIX, [
|
||||||
@@ -100,6 +108,47 @@ def main():
|
|||||||
'nteract-on-jupyter==1.8.1'
|
'nteract-on-jupyter==1.8.1'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_admins(admins):
|
||||||
|
"""
|
||||||
|
Setup given list of users as admins.
|
||||||
|
"""
|
||||||
|
if not admins:
|
||||||
|
return
|
||||||
|
print("Setting up admin users")
|
||||||
|
config_path = os.path.join(INSTALL_PREFIX, 'config.yaml')
|
||||||
|
if os.path.exists(config_path):
|
||||||
|
with open(config_path, 'r') as f:
|
||||||
|
config = rt_yaml.load(f)
|
||||||
|
else:
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
config['users'] = config.get('users', {})
|
||||||
|
config['users']['admin'] = list(admins)
|
||||||
|
|
||||||
|
with open(config_path, 'w+') as f:
|
||||||
|
rt_yaml.dump(config, f)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
argparser = argparse.ArgumentParser()
|
||||||
|
argparser.add_argument(
|
||||||
|
'--admin',
|
||||||
|
nargs='*',
|
||||||
|
help='List of usernames set to be admin'
|
||||||
|
)
|
||||||
|
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
ensure_admins(args.admin)
|
||||||
|
|
||||||
|
ensure_usergroups()
|
||||||
|
ensure_user_environment()
|
||||||
|
|
||||||
|
print("Setting up JupyterHub...")
|
||||||
|
ensure_jupyterhub_package(HUB_ENV_PREFIX)
|
||||||
|
ensure_jupyterhub_service(HUB_ENV_PREFIX)
|
||||||
|
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user