NPM private repository
Address: https://verdaccio.org/zh-CN/docs/docker
1. Server installation
1. Log in to the server
Log in to the warehouse server. If the account is not root, add sudo before key commands.
2. Create the main installation directory
sudo mkdir verdaccio
cd verdaccio
3. Download mirror verdaccio
docker pull verdaccio/verdaccio
4. Write docker-compose file
#Copy the configuration in the "Using docker-compose" section.
sudo vi docker-compose.yaml
#Copy the "use docker-compose" content to the yaml file, and wq! exit and save.
——Optional: restart the machine to automatically start the container
version: '3.1'
services:
verdaccio:
image: verdaccio/verdaccio
container_name: "verdaccio"
restart: always
networks:
- node-network
environment:
- VERDACCIO_PORT=4873
ports:
- "4873:4873"
volumes:
- "./storage:/verdaccio/storage"
- "./config:/verdaccio/conf"
- "./plugins:/verdaccio/plugins"
networks:
node-network:
driver: bridge
5. Run docker-compose
sudo docker-compose up
By default, an error will be prompted:
cannot open config file /verdaccio/conf/config.yaml: Error: CONFIG: it does not look like a valid config file
Reason explanation:
In the docker-compose file, there are 3 volume files, conf, log, and storage.
The purpose of these volumes is to permanently retain the system configuration files for easy migration.
Verdaccio uses uid=10001 in docker. This account does not have root privileges; at the same time, it lacks config.yaml map.
6. Change authorization
cd ..
sudo chown -R 10001:65533 verdaccio
7. Add configuration files
cd verdaccio/config
sudo vi config.yaml
#Copy https://github.com/verdaccio/verdaccio/blob/5.x/conf/docker.yaml content to config.yaml
# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins
# https://verdaccio.org/docs/webui
web:
title: Verdaccio
auth:
htpasswd:
file: /verdaccio/storage/htpasswd
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
# three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish/publish packages
# (anyone can register by default, remember?)
publish: $authenticated
unpublish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
8. Modify authorization
sudo vi config.yaml
Modify the authorization configuration of the package section
'@*/*': 节
access由$all 改为 $authenticated
——目的,所有Pull指令均需要账号认证。
publish由 $authenticated修改为admin
——目的,所有向服务器发布包需要管理员admin账号。
'**':节
同上修改。
9. Start the service
cd ..
docker-compose up
10. Auxiliary commands
view log
docker logs --tail 20 verdaccio
11. Create an administrator account
npm adduser --registry http://192.168.xxx.xxx:4873
username:admin
password:[yourpsw]
email:[yourmail]
cat ~/.npmrc
//192.168.xxx.xxx:4873/:_authToken="XXXXXiXXXXXXXXXXXXX"
Important: Record the admin's token into Notepad for subsequent project references, CI&CD.
12. Create an account that can only be pulled
npm adduser --registry http://192.168.xxx.xxx:4873
username:pulluser
password:[yourpsw]
email:[yourmail]
cat ~/.npmrc
//192.168.xxx.xxx:4873/:_authToken="XXXXXiXXXXXXXXXXXXX"
Important: Record the token of the pulluser into Notepad for subsequent project references and CI&CD.
13. Restart docker
docker ps
docker restart [verdaccioid]
2. Visit the warehouse
Visit the website:
http://192.168.xxx.xxx:4873/
Login: admin/[yourpsw]
3. Project configuration
1. Publish the NPM package to the server
1) Open the project and enter npm whoami to verify the current login
2) Create .npmrc in the project root directory
3) Configuration content:
always-auth=true
registry=http://192.168.xxx.xxx:4873/
//192.168.xxx.xxx:4873/:_authToken='[admin's token]'
4) Modify the project package.json
-- "private": false
-- "name": "[npm name what you want]"
-- "publishConfig": {
"registry": "http://192.168.xxx.xxx:4873/"
}
- terminal console, enter
npm publish --registry http://192.168.xxx.xxx:4873/
2. Apply NPM package
1) Create .npmrc in the project root directory
2) Configuration content:
always-auth=true
registry=http://192.168.xxx.xxx:4873/
//192.168.xxx.xxx:4873/:_authToken='[pulluser's token]'
3) Terminal console, enter
npm i --registry http://192.168.xxx.xxx:4873/ [npm name what you want]
3. Remove the NPM package [operate with caution]
npm unpublish --force [yourPackage]