def install_with_npm(version): pkg = 'npm-offline-registry@{}'.format(version) with maintenance_status('Installing {} with NPM'.format(pkg), '{} installed'.format(pkg)): npm('install {}'.format(pkg)) service_restart('npm-offline-registry') set_state('npm-offline-registry.installed')
def install_from_repo(repo, version): pkg = 'npm-offline-registry@{}'.format(version) dist_dir = node_dist_dir() apt_pkg_map = { 'git': 'git-core', 'hg': 'mercurial', 'svn': 'subversion', } repo_types = ('git', 'hg', 'svn') with maintenance_status('Installing {} from {}'.format(pkg, repo), '{} installed'.format(pkg)): repo_type = hookenv.config('repo_type').lower() if repo_type in repo_types: # Ensure we have the required underlying SCM installed firtst fetch.apt_install( fetch.filter_installed_packages([apt_pkg_map[repo_type]])) # We use the excellent peru to pull in builds from SCM repos # but it requires a pregenerated YAML file on disk with NamedTemporaryFile() as f: render(source='npm-offline-registry_peru.yaml.j2', target=f.name, context={ 'url': repo, 'module': repo_type, 'revision': version, }) check_call(['sudo', 'su', '-s', '/bin/sh', '-', get_user(), '-c', ' '.join(('peru', '--file={}'.format(f.name), '--sync-dir={}'.format(dist_dir), 'sync'))]) # If the repo did not bundle the Node.js dependencies for # npm-offline-registry, then let's try to install them with NPM if not exists(join(dist_dir, 'node_modules')): npm('install') service_restart('npm-offline-registry') set_state('npm-offline-registry.installed') else: raise ValueError('Unknown repo_type "{}",not one of {}'.format( repo_type, repo_types))
def install_from_charm_dir(src_path): pkg = 'npm-offline-registry' dist_dir = node_dist_dir() wildcard_src = join(src_path, '*') wildcard_dest = join(dist_dir.rstrip('.'), '*') with maintenance_status('Installing {} from charm directory'.format(pkg), '{} installed'.format(pkg)): check_call(['rm', '-rf', wildcard_dest]) check_call('cp -R {} {}'.format(wildcard_src, dist_dir), shell=True) # If the vendored payload did not bundle the Node.js dependencies for # npm-offline-registry, then let's try to install them with NPM if not exists(join(dist_dir, 'node_modules')): npm('install') service_restart('npm-offline-registry') set_state('npm-offline-registry.installed')
def install_apollo_graphql(): status_set('maintenance', 'installing graphql-demo') npm('install', '-g', 'github', 'n-pochet/graphql-demo') set_flag('apollo-graphql.installed') clear_flag('apollo-graphql.started') status_set('active', 'graphql-demo installed')
def install_forever(): """ Once NodeJS is ready, install the NPM forever package. """ npm('install', 'forever', '-g') set_state('ghost.forever.installed')
def update_ghost(): stop_ghost() download_archive() npm('install', '--production')