Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticating to a private repository #92

Open
dtoubelis opened this issue Jan 30, 2018 · 1 comment
Open

Authenticating to a private repository #92

dtoubelis opened this issue Jan 30, 2018 · 1 comment

Comments

@dtoubelis
Copy link

I'm trying to use run npm install to pull packages from a private repository that requires authentication.
Normally I would put .npmrc file with the proper token into user's home but this didn't work. I also tried few locations that I could think of and in particular ${NPM_HOME_DIR} and ${S} but neither did any good.

What would be correct location to put the .npmrc file for authentication to work.?

@dtoubelis dtoubelis changed the title How to authenticate to private repository Authenticating to a private repository Mar 15, 2018
@dtoubelis
Copy link
Author

Answering my own question here:

inherit node-base

NPM_TOKEN ?= "00000000-0000-0000-0000-000000000000"
NPM_REGISTRY ?= "https://nexus.example.com/repository/npm-all/"

do_configure () {
    echo "${NPM_REGISTRY}:_authToken=${NPM_TOKEN}" | sed "s/^https://" > ${NPM_HOME_DIR}/.npmrc
    echo "registry=${NPM_REGISTRY}" >> ${NPM_HOME_DIR}/.npmrc

    # Uncoment for nodejs 7.+
    #echo "always-auth=true" >> ${NPM_HOME_DIR}/.npmrc
}

do_compile () {
    ...
}

do_install () {
    ...
}

What thrown me off is that we use node-6 in the image but npm-base class uses nodejs-native for running npm. We were setting preferred version for nodejs but not for nodejs-native and as a result nodejs-7/npm-4 were used by oe_runnpm for pulling dependencies.

Apparently there is a subtle difference in how authentication works between node6/npm3 and node7/npm4 (the always-auth=true part) and it took me only 2 days to figure this out :-)

And this is the right way to setup preferred version:

PREFERRED_VERSION_nodejs = "6.%"
PREFERRED_VERSION_nodejs-native = "6.%"

I hope it helps someone some day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant