Как выполнить POST (а не PUT) первый пакет во вновь установленный экземпляр Verdaccio / Docker? - PullRequest
1 голос
/ 09 мая 2020

Я установил Verdaccio как контейнер Docker с файлом docker-compose.yml:

├── docker-compose.yml
├── INSTALLATION.md
├── README.md
└── volumes
    ├── conf
    │   ├── config.yaml
    │   └── htpasswd
    ├── plugins
    └── storage

, который равен:

version: "3.7"
services:
  registry:
    image: verdaccio/verdaccio
    networks:
      verdaccio:
    hostname: verdaccio
    ports:
      - 4873:4873
    volumes:
      - ~/dev/docker/registries/verdaccio/volumes/conf:/verdaccio/conf
      - ~/dev/docker/registries/verdaccio/volumes/plugins:/verdaccio/plugins
      - ~/dev/docker/registries/verdaccio/volumes/storage:/verdaccio/storage
    environment:
      VERDACCIO_PORT: 4873
    deploy:
      replicas: 1
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 30s
networks:
  verdaccio:
    name: verdaccio

и разрешениями для файла:

sudo groupadd verdaccio;
sudo useradd -s /bin/false -d /dev/null -g verdaccio verdaccio;
sudo chown -R verdaccio:verdaccio ~/dev/docker/registries/verdaccio/volumes/
sudo chmod -R 755 ~/dev/docker/registries/verdaccio/volumes

Я пытаюсь опубликовать sh библиотеку Angular командой:

npm publish lib-core-0.0.1.tgz

Но получаю сообщение об ошибке:

npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT http://verdaccio:4873/lib-core - user stephane is not allowed to publish package lib-core
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/stephane/.npm/_logs/2020-05-10T05_40_47_153Z-debug.log
✔ ~/dev/js/projects/angular/lib-core/dist/lib-core [master|…1] 
07:40 $ npm publish @stephane/lib-core-0.0.1.tgz
npm ERR! code E404
npm ERR! 404 Not Found - GET http://verdaccio:4873/@stephane%2flib-core-0.0.1.tgz - no such package available
npm ERR! 404 
npm ERR! 404  '@stephane/lib-core-0.0.1.tgz@latest' 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 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/stephane/.npm/_logs/2020-05-10T05_40_55_652Z-debug.log

Журнал сервера :

verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 403, user: stephane(10.255.0.2), req: 'PUT /lib-core', error: user stephane is not allowed to publish package lib-core
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 403, user: stephane(10.255.0.2), req: 'PUT /lib-core', error: user stephane is not allowed to publish package lib-core
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 403, user: stephane(10.255.0.2), req: 'GET /npm', error: user stephane is not allowed to access package npm
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 403, user: stephane(10.255.0.2), req: 'GET /npm', error: user stephane is not allowed to access package npm
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 404, user: stephane(10.255.0.2), req: 'GET /@stephane%2flib-core-0.0.1.tgz', error: no such package available
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 404, user: stephane(10.255.0.2), req: 'GET /@stephane%2flib-core-0.0.1.tgz', error: no such package available
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 404, user: stephane(10.255.0.2), req: 'GET /@stephane%2flib-core-0.0.1.tgz', error: no such package available
verdaccio-registry_registry.1.662e59l987fw@stephane-pc    |  http <-- 404, user: stephane(10.255.0.2), req: 'GET /@stephane%2flib-core-0.0.1.tgz', error: no such package available

Когда я прочитал эту ошибку, я понял, что пакет просматривается в Verdaccio и не найден (404). Подождите .. Я не пытаюсь добавить сюда новый пакет? Итак, почему он просматривается первым? Есть ли еще какая-нибудь команда, которую я должен ввести, прежде чем делать publi sh? Проблема в том, что до того, как этот запрос PUT будет отправлен на сервер, я не вижу ни одного запроса POST для добавления пакета.

Я также пробовал (и получил ту же ошибку) с префиксом области действия:

npm publish @stephane/lib-core-0.0.1.tgz

Я запускаю Verdaccio с конфигурацией:

storage: /verdaccio/storage
plugins: /verdaccio/plugins

auth:
  htpasswd:
    file: /verdaccio/conf/htpasswd
security:
  api:
    jwt:
      sign:
        expiresIn: 360d
        notBefore: 1
  web:
    sign:
      expiresIn: 7d

packages:
  '@*/*':
    access: $all
    publish: $all
    proxy: npmjs

  '@stephane/*':
    access: $anonymous
    publish: $anonymous
    proxy: npmjs

Хранилище все еще пусто:

stephane@stephane-pc:~/dev/docker/registries/verdaccio$ ll volumes/storage/
total 0

Даже если удалить конфигурацию packages: и перезапустить Verdaccio контейнера, после успешной команды npm login команда publi sh снова завершается с ошибкой 403 Forbidden:

~/dev/js/projects/angular/lib-core/dist/lib-core [master|…1] 
08:04 $ npm publish lib-core-0.0.1.tgz

ОБНОВЛЕНИЕ: вся проблема связана с разрешениями на томах хоста. Я вернул разрешения своему обычному пользователю хоста и назначил этого пользователя контейнеру при его запуске. Я добавил в файл docker-compose.yml следующее свойство user:

user: "${CURRENT_UID}:${CURRENT_GID}"

Я также изменил конфигурацию пакетов, чтобы разрешить аутентифицированным пользователям доступ к пакетам с заданной областью:

packages:
  '@*/*':
    access: $all
    publish: $authenticated
  '**':
    proxy: npmjs

Контейнер теперь работает с пользователем хоста, и проблема исчезла.

...