Fix to upgrade node version correctly. (#73)

This patch changes piku to check the installed node version and leave it
if correct.

It also separates the nodeenv install and the npm install steps.

It will also warn the user if they try to change the node version in a
running app, and tells them to stop and then deploy the app again in
order to update the node version.

Fixes #70.
pull/79/head^2
Chris McCormick 2019-08-05 16:08:48 +08:00 zatwierdzone przez Rui Carmo
rodzic 29cff3a819
commit 9876ecc2e0
2 zmienionych plików z 30 dodań i 14 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
## Configuring Piku via ENV
# Configuring Piku via ENV
You can configure deployment settings by placing special variables in an `ENV` file deployed with your app.
@ -10,7 +10,9 @@ You can configure deployment settings by placing special variables in an `ENV` f
### Node
* `NODE_VERSION`: installs a particular version of node for your app if `nodeenv` is found on the path
* `NODE_VERSION`: installs a particular version of node for your app if `nodeenv` is found on the path.
**Note**: you will need to stop and re-deploy the app to change the node version in a running app.
## Network Settings

38
piku.py
Wyświetl plik

@ -371,6 +371,7 @@ def do_deploy(app, deltas={}, newrev=None):
echo("-----> Releasing", fg='green')
retval = call(workers["release"], cwd=app_path, env=settings, shell=True)
if retval:
echo("-----> Exiting due to release command error value: {}".format(retval))
exit(retval)
workers.pop("release", None)
else:
@ -426,19 +427,32 @@ def deploy_node(app, deltas={}):
makedirs(node_path)
first_time = True
if exists(deps):
if first_time or getmtime(deps) > getmtime(node_path):
env = {
'VIRTUAL_ENV': virtualenv_path,
'NODE_PATH': node_path,
'NPM_CONFIG_PREFIX': abspath(join(node_path, "..")),
"PATH": ':'.join([join(virtualenv_path, "bin"), join(node_path, ".bin"),environ['PATH']])
}
if exists(env_file):
env.update(parse_settings(env_file, env))
if env.get("NODE_VERSION") and check_requirements(['nodeenv']):
env = {
'VIRTUAL_ENV': virtualenv_path,
'NODE_PATH': node_path,
'NPM_CONFIG_PREFIX': abspath(join(node_path, "..")),
"PATH": ':'.join([join(virtualenv_path, "bin"), join(node_path, ".bin"),environ['PATH']])
}
if exists(env_file):
env.update(parse_settings(env_file, env))
version = env.get("NODE_VERSION")
node_binary = join(virtualenv_path, "bin", "node")
installed = check_output("{} -v".format(node_binary), cwd=join(APP_ROOT, app), env=env, shell=True).decode("utf8").rstrip("\n") if exists(node_binary) else ""
if version and check_requirements(['nodeenv']):
if not installed.endswith(version):
started = glob(join(UWSGI_ENABLED, '{}*.ini'.format(app)))
if installed and len(started):
echo("Warning: Can't update node with app running. Stop the app & retry.", fg='yellow')
else:
echo("-----> Installing node version '{NODE_VERSION:s}' using nodeenv".format(**env), fg='green')
call("nodeenv --prebuilt --node={NODE_VERSION:s} --force {VIRTUAL_ENV:s}".format(**env), cwd=virtualenv_path, env=env, shell=True)
call("nodeenv --prebuilt --node={NODE_VERSION:s} --clean-src --force {VIRTUAL_ENV:s}".format(**env), cwd=virtualenv_path, env=env, shell=True)
else:
echo("-----> Node is installed at {}.".format(version))
if exists(deps) and check_requirements(['npm']):
if first_time or getmtime(deps) > getmtime(node_path):
echo("-----> Running npm for '{}'".format(app), fg='green')
symlink(node_path, node_path_tmp)
call('npm install', cwd=join(APP_ROOT, app), env=env, shell=True)