From e43b318d615abb68d42bc915c4b58e5f6b0b9c8c Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Fri, 28 Jun 2019 19:56:37 +0800 Subject: [PATCH] Fix node deploy path handling. (#49) * Fix node deploy path handling. This patch uses a temporary symlink to envs/APP/node_modules to force node to install the modules into the right place even on older node versions, like v4.2.6 which ships with Unbuntu 16.04. Apps launching node servers will need to manually set NODE_PATH="${VIRTUAL_ENV}/node_modules" to have it run correctly, and in future we should consider setting this in spawn_app (though currently spawn_app does not know what kind of app it's spawning). * Add NODE_PATH to spawn env if node env present. --- piku.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/piku.py b/piku.py index 4668dcc..44c95db 100755 --- a/piku.py +++ b/piku.py @@ -415,26 +415,29 @@ def deploy_go(app, deltas={}): def deploy_node(app, deltas={}): """Deploy a Node application""" - node_path = join(ENV_ROOT, app) + node_path = join(ENV_ROOT, app, "node_modules") + node_path_tmp = join(APP_ROOT, app, "node_modules") env_file = join(APP_ROOT, app, 'ENV') - deps = join(ENV_ROOT, app, 'lib', 'node_modules') + deps = join(APP_ROOT, app, 'package.json') first_time = False - if not exists(deps): + if not exists(node_path): echo("-----> Creating node_modules for '{}'".format(app), fg='green') - makedirs(deps) + makedirs(node_path) first_time = True if exists(deps): if first_time or getmtime(deps) > getmtime(node_path): echo("-----> Running npm for '{}'".format(app), fg='green') env = { - 'NODE_PATH': '{}/lib/node_modules'.format(node_path), - 'NPM_CONFIG_PREFIX': node_path, + 'NODE_PATH': node_path, + 'NPM_CONFIG_PREFIX': abspath(join(node_path, "..")), } if exists(env_file): env.update(parse_settings(env_file, env)) + symlink(node_path, node_path_tmp) call('npm install', cwd=join(APP_ROOT, app), env=env, shell=True) + unlink(node_path_tmp) spawn_app(app, deltas) @@ -507,7 +510,12 @@ def spawn_app(app, deltas={}): 'NGINX_IPV6_ADDRESS': '[::]', 'BIND_ADDRESS': '127.0.0.1', } - + + # add node path if present + node_path = join(virtualenv_path, "node_modules") + if exists(node_path): + env["NODE_PATH"] = node_path + # Load environment variables shipped with repo (if any) if exists(env_file): env.update(parse_settings(env_file, env))