2018-07-02 15:12:26 -07:00
|
|
|
"""
|
|
|
|
|
Bootstrap an installation of TLJH.
|
|
|
|
|
|
|
|
|
|
Sets up just enough TLJH environments to invoke tljh.installer.
|
|
|
|
|
|
|
|
|
|
This script is run as:
|
|
|
|
|
|
|
|
|
|
curl <script-url> | sudo python3 -
|
|
|
|
|
|
|
|
|
|
Constraints:
|
|
|
|
|
- Be compatible with Python 3.4 (since we support Ubuntu 16.04)
|
|
|
|
|
- Use stdlib modules only
|
|
|
|
|
"""
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
2018-07-03 16:18:32 -07:00
|
|
|
import sys
|
2018-07-29 02:17:12 -07:00
|
|
|
import logging
|
|
|
|
|
|
2018-07-02 15:12:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
install_prefix = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')
|
|
|
|
|
hub_prefix = os.path.join(install_prefix, 'hub')
|
|
|
|
|
|
2018-07-29 02:17:12 -07:00
|
|
|
# Set up logging to print to a file and to stderr
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
os.makedirs(install_prefix, exist_ok=True)
|
2018-07-29 12:53:04 -07:00
|
|
|
file_logger = logging.FileHandler(os.path.join(install_prefix, 'installer.log'))
|
2018-07-29 02:17:12 -07:00
|
|
|
file_logger.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
|
|
|
|
|
logger.addHandler(file_logger)
|
|
|
|
|
|
|
|
|
|
stderr_logger = logging.StreamHandler()
|
|
|
|
|
stderr_logger.setFormatter(logging.Formatter('%(message)s'))
|
|
|
|
|
logger.addHandler(stderr_logger)
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
|
|
logger.info('Checking if TLJH is already installed...')
|
2018-07-19 17:30:09 -07:00
|
|
|
if os.path.exists(os.path.join(hub_prefix, 'bin', 'python3')):
|
2018-07-29 02:17:12 -07:00
|
|
|
logger.info('TLJH already installed, upgrading...')
|
2018-07-02 15:12:26 -07:00
|
|
|
initial_setup = False
|
2018-07-19 17:30:09 -07:00
|
|
|
else:
|
2018-07-29 02:17:12 -07:00
|
|
|
logger.info('Setting up hub environment')
|
2018-07-19 17:30:09 -07:00
|
|
|
initial_setup = True
|
2018-07-29 02:17:12 -07:00
|
|
|
subprocess.check_output(['apt-get', 'update', '--yes'], stderr=subprocess.STDOUT)
|
|
|
|
|
subprocess.check_output(['apt-get', 'install', '--yes', 'python3', 'python3-venv'], stderr=subprocess.STDOUT)
|
|
|
|
|
logger.info('Installed python & virtual environment')
|
2018-07-19 17:30:09 -07:00
|
|
|
os.makedirs(hub_prefix, exist_ok=True)
|
2018-07-29 02:17:12 -07:00
|
|
|
subprocess.check_output(['python3', '-m', 'venv', hub_prefix], stderr=subprocess.STDOUT)
|
|
|
|
|
logger.info('Set up hub virtual environment')
|
2018-07-02 15:12:26 -07:00
|
|
|
|
|
|
|
|
if initial_setup:
|
2018-07-29 02:17:12 -07:00
|
|
|
logger.info('Setting up TLJH installer...')
|
2018-07-02 15:12:26 -07:00
|
|
|
else:
|
2018-07-29 02:17:12 -07:00
|
|
|
logger.info('Upgrading TLJH installer...')
|
2018-07-02 15:12:26 -07:00
|
|
|
|
2018-07-19 17:30:09 -07:00
|
|
|
pip_flags = ['--upgrade']
|
|
|
|
|
if os.environ.get('TLJH_BOOTSTRAP_DEV', 'no') == 'yes':
|
|
|
|
|
pip_flags.append('--editable')
|
2018-07-03 16:18:32 -07:00
|
|
|
tljh_repo_path = os.environ.get(
|
|
|
|
|
'TLJH_BOOTSTRAP_PIP_SPEC',
|
2018-07-20 16:17:33 -07:00
|
|
|
'git+https://github.com/jupyterhub/the-littlest-jupyterhub.git'
|
2018-07-03 16:18:32 -07:00
|
|
|
)
|
|
|
|
|
|
2018-07-19 17:30:09 -07:00
|
|
|
subprocess.check_output([
|
|
|
|
|
os.path.join(hub_prefix, 'bin', 'pip'),
|
|
|
|
|
'install'
|
2018-07-29 02:17:12 -07:00
|
|
|
] + pip_flags + [tljh_repo_path], stderr=subprocess.STDOUT)
|
|
|
|
|
logger.info('Setup tljh package')
|
2018-07-02 15:12:26 -07:00
|
|
|
|
2018-07-29 02:17:12 -07:00
|
|
|
logger.info('Starting TLJH installer...')
|
2018-07-03 16:18:32 -07:00
|
|
|
os.execv(
|
2018-07-02 15:12:26 -07:00
|
|
|
os.path.join(hub_prefix, 'bin', 'python3'),
|
2018-07-03 16:18:32 -07:00
|
|
|
[
|
|
|
|
|
os.path.join(hub_prefix, 'bin', 'python3'),
|
|
|
|
|
'-m',
|
|
|
|
|
'tljh.installer',
|
|
|
|
|
] + sys.argv[1:]
|
2018-07-02 15:12:26 -07:00
|
|
|
)
|
|
|
|
|
|
2018-07-02 15:55:53 -07:00
|
|
|
|
2018-07-02 15:12:26 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|