These are chat archives for creationix/nvm

8th
Mar 2015
Kris Williams
@kriswill
Mar 08 2015 09:24
I’m trying to put togther a minimal nvm image
Jordan Harband
@ljharb
Mar 08 2015 09:25
hm
Kris Williams
@kriswill
Mar 08 2015 09:25
specifically for running sails
Jordan Harband
@ljharb
Mar 08 2015 09:25
i'd feel a bit better if it included install.sh and ran that
Kris Williams
@kriswill
Mar 08 2015 09:25
yeah I could curl it
Jordan Harband
@ljharb
Mar 08 2015 09:25
it'll make for easier updates in the future
Kris Williams
@kriswill
Mar 08 2015 09:25
but that would bake it in
interesting
Jordan Harband
@ljharb
Mar 08 2015 09:26
curling it would be totally ideal
using the version from http://latest.nvm.sh
at some point in the future you'll be able to install it any way, and then do nvm update, but that's not here yet
Kris Williams
@kriswill
Mar 08 2015 09:27
ok, I’ll try that out
Jordan Harband
@ljharb
Mar 08 2015 09:27
also nvm-iojs? nothing in your script is io.js specific
except line 10
Kris Williams
@kriswill
Mar 08 2015 09:27
it defaults to it
Jordan Harband
@ljharb
Mar 08 2015 09:27
k
Kris Williams
@kriswill
Mar 08 2015 09:27
so it’ll be baked into the built docker image
Jordan Harband
@ljharb
Mar 08 2015 09:27
also you can use a .nvmrc file
rather than baking it into the script
Kris Williams
@kriswill
Mar 08 2015 09:27
we wanted to provide the flexibility to upgrade iojs or go back to node
Jordan Harband
@ljharb
Mar 08 2015 09:28
ie, if your docker just runs nvm install it will look for an .nvmrc file, install that if necessary, and then use it
Kris Williams
@kriswill
Mar 08 2015 09:28
that is tru
Jordan Harband
@ljharb
Mar 08 2015 09:28
that way your git project can store its desired node version and you won't need to change docker
Kris Williams
@kriswill
Mar 08 2015 09:28
so in our stack it would be thru docker compose
i.e.,:
docker-compose run server nvm install
we’ll have to put the .nvmrc into our generator
since the server path is empty by default
that’s the user code
Jordan Harband
@ljharb
Mar 08 2015 09:30
right
wait
when you say "our generator"
can't you just grab the user's code, and run nvm install inside that directory?
Kris Williams
@kriswill
Mar 08 2015 09:31
our stack generates an application in the server path
and it’s volume mapped into the docker container
Jordan Harband
@ljharb
Mar 08 2015 09:31
then you can make a default in /.nvmrc and the user can override it by having an .nvmrc in their code
Kris Williams
@kriswill
Mar 08 2015 09:32
oh you mean in the ~/.nvmrc
Jordan Harband
@ljharb
Mar 08 2015 09:32
yes
Kris Williams
@kriswill
Mar 08 2015 09:33
yeah that makes sense, easy enough
Jordan Harband
@ljharb
Mar 08 2015 09:33
nvm will look in pwd and then walk upwards until /
and the first nvmrc it finds wins
Kris Williams
@kriswill
Mar 08 2015 09:33
in that case the default pwd for the container is /server
so it would have to be in root
Jordan Harband
@ljharb
Mar 08 2015 09:33
sure
Kris Williams
@kriswill
Mar 08 2015 09:34
so you think that’s preferable to an alias?
Jordan Harband
@ljharb
Mar 08 2015 09:34
i think that in an env where the system (docker) doesn't change often, but the user code (their git repo) does
it'd be better for user code to have control over which node version is used
Kris Williams
@kriswill
Mar 08 2015 09:35
I agree
Kris Williams
@kriswill
Mar 08 2015 10:10
doing the curl for some reason exit codes 127
out of sh
and it aborts the build
sane@730798121b45:~$ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6841  100  6841    0     0  18849      0 --:--:-- --:--:-- --:--:-- 32117
=> Downloading nvm from git to '/home/.nvm'
=> Cloning into '/home/.nvm'...
remote: Counting objects: 3431, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 3431 (delta 4), reused 0 (delta 0), pack-reused 3417
Receiving objects: 100% (3431/3431), 688.72 KiB, done.
Resolving deltas: 100% (1957/1957), done.
sane@730798121b45:~$ echo $?
127
doing it manually in the docker container returns the same code
Jordan Harband
@ljharb
Mar 08 2015 10:13
that means it can't find the .nvmrc
that's the code it returns when you do a bare nvm install or nvm use and there's no .nvmrc found
Kris Williams
@kriswill
Mar 08 2015 10:13
ah it causes docker build to abort
what’s the content of the .nvmrc file?
I’ve never used one
Jordan Harband
@ljharb
Mar 08 2015 10:14
anything where nvm use X would work - the "X"
Kris Williams
@kriswill
Mar 08 2015 10:14
just iojs?
Jordan Harband
@ljharb
Mar 08 2015 10:14
sure
Kris Williams
@kriswill
Mar 08 2015 10:16
Step 9 : RUN echo $NODE_VERSION > ~/.nvmrc &&     curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | sh
 ---> Running in dbab7e738352
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6841  100  6841    0     0  28823      0 --:--:-- --:--:-- --:--:-- 39091
=> Downloading nvm from git to '/home/.nvm'
=> Cloning into '/home/.nvm'...
INFO[0002] The command [/bin/sh -c echo $NODE_VERSION > ~/.nvmrc &&     curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | sh] returned a non-zero code: 129
now it’s exiting with 129
Jordan Harband
@ljharb
Mar 08 2015 10:18
hm, that might be a git code
Kris Williams
@kriswill
Mar 08 2015 10:18
is there a verbose on the install?
Jordan Harband
@ljharb
Mar 08 2015 10:18
no, unfortunately, that's a good idea
but nvm doesn't throw a 129 anywhere
so it's either curl or git i'd say
doesn’t look like curl
ah it means git can’t parse it’s options
Jordan Harband
@ljharb
Mar 08 2015 10:20
ah, if you have an old git it will break
it needs --quiet
what version do you have?
Kris Williams
@kriswill
Mar 08 2015 10:20
sec
Step 9 : RUN git --version
 ---> Running in f852c5839fb8
git version 1.7.10.4
it’s the one in the standard debian wheezy package source
I’ll look to see if there’s an alternate package for a newer version
Jordan Harband
@ljharb
Mar 08 2015 10:22
ah, that's ancient
tons of security issues too
you want 2.3 if possible, 2.2 otherwise
Kris Williams
@kriswill
Mar 08 2015 10:23
yeah not sure how to install a newer one yet
investigating
Kris Williams
@kriswill
Mar 08 2015 10:37
    # backports git for latest git, needed for nvm install
    apt-get -y --no-install-recommends -t wheezy-backports install git && \
actually the backports only has 1.9.1
which isn’t as ancient
Jordan Harband
@ljharb
Mar 08 2015 10:37
that might be new enough
but is still pretty old
Kris Williams
@kriswill
Mar 08 2015 10:38
maybe there’s a newer backports somewhere?
Jordan Harband
@ljharb
Mar 08 2015 10:39
i dunno, i hate package managers like apt
as a rule, i only install software via an official distribution channel for it.
they don’t really have a binary..
Jordan Harband
@ljharb
Mar 08 2015 10:40
k i have to hit the sack but i'll get back to you tomorr
ow
Kris Williams
@kriswill
Mar 08 2015 10:40
yeah me too
seems to have worked tho
Jordan Harband
@ljharb
Mar 08 2015 10:41
nice
Kris Williams
@kriswill
Mar 08 2015 10:41
I’ll add this to the PR
Jordan Harband
@ljharb
Mar 08 2015 10:41
feel free to try to make the git error message more helpful too :-)
(in install.sh)
Kris Williams
@kriswill
Mar 08 2015 10:42
yeah might take me a while, there’s a lot there
but yeah, it would be nice to have a verbose logging mode
here’s the change with install.sh
Jordan Harband
@ljharb
Mar 08 2015 10:44
nice
if you make v0.24.0 configurable it'll make nvm updates easier
Kris Williams
@kriswill
Mar 08 2015 10:44
env var?
Jordan Harband
@ljharb
Mar 08 2015 10:44
sure
no i mean in the install.sh URL
you could also derive it from curl http://latest.nvm/sh if you wanted to get real fancy
Kris Williams
@kriswill
Mar 08 2015 10:45
I don’t see that URL
Jordan Harband
@ljharb
Mar 08 2015 10:46
sorry curl http://latest.nvm.sh
it's late :-)
you'll need curl -L
and the last part of the path is the version number
Kris Williams
@kriswill
Mar 08 2015 10:47
right -L will follow redirs
Jordan Harband
@ljharb
Mar 08 2015 10:49
right
Jordan Harband
@ljharb
Mar 08 2015 10:49
right, so you can parse out the version number
and then insert it into the install.sh url
Kris Williams
@kriswill
Mar 08 2015 10:49
oh I see what you’re saying
Kris Williams
@kriswill
Mar 08 2015 20:58
so I tried:
$ curl -L http://latest.nvm.sh --max-redirs 1 -D nvm.headers
$  cat nvm.headers | grep -Ei "^Location: .*tag/v[0-9.]+" | grep -oEi "v[0-9.]+”
v0.24.0
but, —max-redirs causes a non-zero exit code
Jordan Harband
@ljharb
Mar 08 2015 20:58
you need more than 1
it's always going to be at least 2 hops
Kris Williams
@kriswill
Mar 08 2015 20:59
I think I used 2
Jordan Harband
@ljharb
Mar 08 2015 20:59
do you even need the max redirects?
Kris Williams
@kriswill
Mar 08 2015 20:59
so the other option is to use the github API
Jordan Harband
@ljharb
Mar 08 2015 20:59
sure, that's fine too
Kris Williams
@kriswill
Mar 08 2015 20:59
well, if you allow it to continue
then the headers are gone
Kris Williams
@kriswill
Mar 08 2015 21:10
→ curl -L http://latest.nvm.sh -D nvm.headers >> /dev/null 2>&1 ; cat nvm.headers | grep -Ei "^Location: .*tag/v[0-9.]+" | grep -oEi "v[0-9.]+" ; rm nvm.headers
v0.24.0
now to capture in a variable
Jordan Harband
@ljharb
Mar 08 2015 21:11
yay
hm, do you have to have a temporary file?
i'd think -o - or something would pipe it to stdout
Kris Williams
@kriswill
Mar 08 2015 21:12
ok, let’s try it
the -D parameter captures only headers
-o is for content
Kris Williams
@kriswill
Mar 08 2015 21:22
→ curl -s -L http://latest.nvm.sh -o /dev/null -D - | grep -Ei "^Location: .*tag/v[0-9.]+" | grep -oEi "v[0-9.]+”
v0.24.0
no intermediate file
→ NVM_VERSION="`curl -s -L http://latest.nvm.sh -o /dev/null -D - | grep -Ei "^Location: .*tag/v[0-9.]+" | grep -oEi "v[0-9.]+”`"
→ echo $NVM_VERSION 
v0.24.0
Kris Williams
@kriswill
Mar 08 2015 21:36
@ljharb this works:
# install node version manager
RUN touch $HOME/.bashrc && \
    echo $NODE_VERSION > $HOME/.nvmrc && \
    NVM_VERSION="$(curl -s -L http://latest.nvm.sh -o /dev/null -D - | grep -Ei '^Location: .*tag/v[0-9.]+' | grep -oEi 'v[0-9.]+')" && \
    curl https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh | sh && \
    # install node
    source $NVM_DIR/nvm.sh && \
    nvm install $NODE_VERSION >> /dev/null 2>&1 && \
should be close to final
Jordan Harband
@ljharb
Mar 08 2015 21:41
awesome
that looks pretty robust as well as configurable (altho it'd still be cool to add .nvmrc support somewhere)
Kris Williams
@kriswill
Mar 08 2015 21:46
it is there
all the user has to do is create one in /server/.nvmrc
the start command will be nvm run sails lift
what does nvm do if you nvm install with .nvmrc and it’s already installed?
Jordan Harband
@ljharb
Mar 08 2015 21:50
just uses it
Kris Williams
@kriswill
Mar 08 2015 21:50
I feel like node_modules should have a version folder
seems not obvious that you have to blow out your entire node_modules if you switch nodes
like a newbie mistake users make is npm i from the host, when the app is running in linux inside a container
any binary modules will bomb
and give them very friendly stack traces to be confused by
an interesting idea would be to have node_modules be a symlink to the current node’s installed modules.
but obviously that would be up to npm to figure out
Jordan Harband
@ljharb
Mar 08 2015 21:54
you only do for binary modules
Kris Williams
@kriswill
Mar 08 2015 21:55
right
or that
Jordan Harband
@ljharb
Mar 08 2015 21:55
and yeah, that's definitely on the person switching nodes
but i never use binary modules so i never run into trouble :-)
Kris Williams
@kriswill
Mar 08 2015 21:55
sometimes you are forced to depending on what other servers you’re using
like mongo or bcrypt etc
or sass if you use that
Jordan Harband
@ljharb
Mar 08 2015 21:55
yeah
Kris Williams
@kriswill
Mar 08 2015 21:56
native modules definitely could use some refinement in terms of usability
Jordan Harband
@ljharb
Mar 08 2015 22:02
if they depend on "nan" then i don't think it's problematic actually