Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use Google Cloud Functions with a registry other than registry.npmjs.org

I'm currently trying to deploy a node.js cloud function using a (private) package from the GitHub package registry (npm.pkg.github.com).

According to the official docs here, using private modules is supported by adding a .npmrc file with an access token, however there is no mention of using custom registries.

The .npmrc which I upload to Cloud Functions alongside the package.json and the rest of the code looks like this:

registry=https://npm.pkg.github.com/<myorg>
//npm.pkg.github.com/:_authToken=<mytoken>

However, the deployment fails due to:

Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/<mypackage> - Not found
npm ERR! 404 
npm ERR! 404 '<mypackage>' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

So as you can see, the registry definition from the .npmrc seems to be ignored, as it tries to pull the package from npmjs.org, where it does indeed not exist.

Do Google Cloud Functions not support custom registries?


Edit: added verbose log output

Deploying function (may take a while - up to 2 minutes)...failed.
DEBUG: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:\nnpm ERR! code E404\nnpm ERR! 404 Not Found - GET https://registry.npmjs.org/<redacted> - Not found\nnpm ERR! 404 \nnpm ERR! 404  '<redacted>' is not in the npm registry.\nnpm ERR! 404 You should bug the author to publish it (or use the name yourself!)\nnpm ERR! 404 It was specified as a dependency of 'functions'\nnpm ERR! 404 \nnpm ERR! 404 Note that you can also install from a\nnpm ERR! 404 tarball, folder, http url, or git url.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-02-12T14_14_22_565Z-debug.log\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! @ preinstall: `./install-function-dependencies`\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the @ preinstall script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-02-12T14_14_22_586Z-debug.log\n\nerror: `npm_install` returned code: 1", "errorType": "InternalError", "errorId": "BDE5340F"}}
Traceback (most recent call last):
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 981, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 807, in Run
    resources = command_instance.Run(args)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/surface/functions/deploy.py", line 307, in Run
    return _Run(args, track=self.ReleaseTrack())
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/surface/functions/deploy.py", line 263, in _Run
    op, do_every_poll=TryToSetInvokerPermission)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 306, in CatchHTTPErrorRaiseHTTPExceptionFn
    return func(*args, **kwargs)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/util.py", line 353, in WaitForFunctionUpdateOperation
    do_every_poll=do_every_poll)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 137, in Wait
    _WaitForOperation(client, request, notice, do_every_poll)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 111, in _WaitForOperation
    sleep_ms=SLEEP_MS)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 219, in RetryOnResult
    result = func(*args, **kwargs)
  File "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/lib/googlecloudsdk/api_lib/functions/operations.py", line 70, in _GetOperationStatus
    raise exceptions.FunctionsError(OperationErrorToString(op.error))
FunctionsError: OperationError: code=3, message=Build failed: {"error": {"canonicalCode": "INVALID_ARGUMENT", "errorMessage": "`npm_install` had stderr output:\nnpm ERR! code E404\nnpm ERR! 404 Not Found - GET https://registry.npmjs.org/<redacted> - Not found\nnpm ERR! 404 \nnpm ERR! 404  '<redacted>' is not in the npm registry.\nnpm ERR! 404 You should bug the author to publish it (or use the name yourself!)\nnpm ERR! 404 It was specified as a dependency of 'functions'\nnpm ERR! 404 \nnpm ERR! 404 Note that you can also install from a\nnpm ERR! 404 tarball, folder, http url, or git url.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-02-12T14_14_22_565Z-debug.log\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! @ preinstall: `./install-function-dependencies`\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the @ preinstall script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /builder/home/.npm/_logs/2020-02-12T14_14_22_586Z-debug.log\n\nerror: `npm_install` returned code: 1", "errorType": "InternalError", "errorId": "BDE5340F"}}
like image 403
Leo Avatar asked Feb 12 '20 09:02

Leo


People also ask

What is Npmjs registry?

The public npm registry is a database of JavaScript packages, each comprised of software and metadata. Open source developers and developers at companies use the npm registry to contribute packages to the entire community or members of their organizations, and download packages to use in their own projects.

Do cloud functions support custom dependencies?

After executing your custom build step, Cloud Functions removes and regenerates the node_modules folder by only installing the production dependencies declared in the dependencies field of your package. json file. If there is no gcp-build script in package. json , Cloud Functions just installs production dependencies.

Why do we need .npmrc file?

The npmrc manages the npm config files. The config setting for npm is gotten from the command line, environment variables and the npmrc files. You can use the npm config command to update and edit the contents of the user and global npmrc files.

What is the default registry for npm?

The default is typically set to the public npm registry at https://registry.npmjs.org/ . For more information about npm configuration files, see the npm config file documentation.


1 Answers

Do Google Cloud Functions not support custom registries?

Google Cloud Functions should support custom registries. What version of Nodejs are you using? There were reported some other similar issues: Runtime doesn't support private npm packages with Nodejs 10.

On the thread it is mentionded that:

I would like to inform you that the Cloud Functions engineering team has rolled out a change to resolve this issue. You may feel free to try your migration efforts from Node.js 8 to Node.js 10 again. The roll out addresses the 404 NOT_FOUND issue when trying to install private packages.

Also I would suggest to test deploying your cloud function using env variables.

gcloud functions deploy functionName 
 --region europe-west1 
 --runtime nodejs10 
 --source=SOURCE
 --set-env-vars= NPM_REGISTRY=<your private registry URL>, NPM_SCOPE=<@private-registry-scope>, NPM_CONFIG_EXTRA=auth_token

EDIT

It seems that the issue resurfaced again for Nodejs10 link

like image 189
marian.vladoi Avatar answered Oct 31 '22 10:10

marian.vladoi