0

我正在通过简单的项目使用 docker 和 kubernetes 学习微服务,现在我正在尝试使用本地注册表安装为带有 h​​elm 的 docker 容器。我在本地注册表中发布了我的包/库(我正在使用 verdaccio),并使用命令“npm install @mycompany/mylibs --registry=http://localhost:4873”将它成功安装在我当前的项目中。我的问题是当我尝试通过 skaffold 将我的项目部署到 kubernetes 时,它无法从 package.json 配置文件中下载包。我尝试将 .npmrc 文件设置到项目的根文件夹和 verdaccio conf 文件上的默认注册表,但都失败了。有没有人遇到过和我一样的问题以及如何解决。请有人帮忙。谢谢

这是我的项目结构:

MyProject
|-auth (this service has dependency to @mycompany/mylibs)
| |-src
| |-Dockerfile
| |-package.json
|
|-infra/kube
| |-auth-depl.yaml
| |-ingress-srv.yaml


MySharedLibrary
| |-src
| |-package.json

auth 的 package.json :

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node-dev src/index.ts",
    "test": "jest --watchAll --no-cache"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "./src/test/setup.ts"
    ]
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@mycompany/mylibs": "^1.0.3",
    "@types/cookie-session": "^2.0.42",
    "@types/express": "^4.17.9",
    "@types/jsonwebtoken": "^8.5.0",
    "cookie-session": "^1.4.0",
    "express": "^4.17.1",
    "express-async-errors": "^3.1.1",
    "express-validator": "^6.7.0",
    "jsonwebtoken": "^8.5.1",
    "mariadb": "^2.5.1",
    "mysql2": "^2.2.5",
    "sequelize": "^6.3.5",
    "ts-node-dev": "^1.0.0",
    "typescript": "^4.1.2"
  },
  "devDependencies": {
    "@types/jest": "^26.0.19",
    "@types/supertest": "^2.0.10",
    "jest": "^26.6.3",
    "supertest": "^6.0.1",
    "ts-jest": "^26.4.4"
  }
}

我在用:

Windows 10 PC 作为 docker 的主要主机和项目托管的位置。

码头工人版本 19.03.13

npm 版本 6.14.6

维达乔 4.12.0

掌舵 3.5.3

脚手架 1.13.0

我部署项目后的错误消息skaffold dev

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@mycompany%2fmylibs - Not found
npm ERR! 404
npm ERR! 404  '@mycompany/mylibs@^1.0.3' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'app'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

我希望我的部署过程中每个容器都可以在本地注册表(http://localhost:4873)上找到所有必需的依赖项,当它找不到它们时,它应该尝试访问公共 npm(https://registry.npmjs.org或 npmjs.com)。

4

2 回答 2

1

感谢大家帮助我,我通过添加以下行重新配置我的 Dockerfile on auth 服务解决了这个问题:

RUN npm config set registry http://<the_local_registry_container_IP>:4873

我成功构建了容器,但它引发了新问题“请求已被弃用,请参阅 github.com/request/request/issues/3142”,因为我正在使用 supertest。我不知道为什么我仍在寻找主要问题。在另一种情况下,如果我使用 public npm repo 构建它,它不会引发这个问题。

于 2021-04-02T09:22:17.147 回答
0

您需要将范围与您的注册表相关联:

npm login --registry=http://localhost:4873 --scope=@mycompany

你可以在这里找到文档

npm install如果包在范围内,则在您的存储库中安装此包之后@mycompany

于 2021-03-25T12:47:36.770 回答