飞道科技

飞道科技文档总汇

cnpm仓库部署

1. DockerFile

version: '3.7'

services:
  verdaccio:
    image: docker.ifeidao.com/verdaccio_minio:4.4
    ports:
      - 4873:4873
    volumes:
      - /data/verdaccio/feidao/logs/:/opt/verdaccio/logs/
      - /data/verdaccio/feidao/conf:/verdaccio/conf
      - /data/verdaccio/feidao/htpasswd:/verdaccio/storage/htpasswd
    depends_on:
      - minio
    environment:
      VERDACCIO_PROTOCOL: http
      VERDACCIO_PORT: 4873

  minio:
    image: minio/minio:RELEASE.2019-12-30T05-45-39Z
    command: server /data
    volumes:
      - /data/verdaccio/feidao/minio:/data
    ports:
      - 9000:9000
    environment:
      MINIO_ACCESS_KEY: feidao
      MINIO_SECRET_KEY: Feidao111111

volumes:
  minio:

2. 部署结构

feidao:
  d000001:
    proxy
  d000002:
    proxy
  d000003:
    proxy

3. dfeidao

3.1. 包含内容

框架,原子操作,控件

3.2. 配置文件

3.2.1. htpasswd

taoqf:xxx
d000001:xxx
d000002:xxx
d000003:xxx

其中,xxx可以由htpasswd生成,生成方式可以使用npm上的一个工具

npm i -g htpasswd
# or
# yarn global add htpasswd

使用以下命令生成

htpasswd -bdn d000001 d000001-secret
htpasswd -bdn d000002 d000002-secret
htpasswd -bdn d000003 d000003-secret

3.2.2. conf/config.yml

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# Here's the plugin configuration option
store:
  minio:
    # The HTTP port of your minio instance
    port: 9000

    # The endpoint on which verdaccio will access minio (without scheme)
    endPoint: minio

    # The minio access key
    accessKey: feidao

    # The minio secret key
    secretKey: Feidao111111

    # Disable SSL if you're accessing minio directly through HTTP
    useSSL: false

    # The region used by your minio instance (optional, default to "us-east-1")
    # region: eu-west-1

    # A bucket where verdaccio will store it's database & packages (optional, default to "verdaccio")
    # bucket: 'npm'

    # Number of retry when a request to minio fails (optional, default to 10)
    # retries: 3

    # Delay between retries (optional, default to 100)
    # delay: 50

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc

auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
    max_users: -1

uplinks:
  npmjs:
    url: https://registry.npmjs.org/
    maxage: 30m
    cache: true
  taobao:
    url: https://registry.npm.taobao.org/
    maxage: 30m
    cache: true

packages:
  '@dfeidao/*':
    access: $authenticated
    publish: taoqf
    unpublish: taoqf

  '@*/*':
    access: $authenticated
    proxy: taobao

  '**':
    access: $authenticated
    proxy: taobao

middlewares:
  audit:
    enabled: true

# log settings
logs:
  # - { type: stdout, format: pretty, level: http }
  - {type: file, path: logs/verdaccio.log, level: info}

3.3. d00000(1-n)

3.4. 包含内容

项目发布包

3.5. 配置文件

3.5.1. htpasswd

生成方法同上.

为了使用简单,可以为所有开发人员分配统一帐户,如feidao@feidao<feidao@ifeidao.com>

3.5.2. conf/config.yml

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# Here's the plugin configuration option
store:
  minio:
    # The HTTP port of your minio instance
    port: 9000

    # The endpoint on which verdaccio will access minio (without scheme)
    endPoint: minio

    # The minio access key
    accessKey: feidao

    # The minio secret key
    secretKey: Feidao111111

    # Disable SSL if you're accessing minio directly through HTTP
    useSSL: false

    # The region used by your minio instance (optional, default to "us-east-1")
    # region: eu-west-1

    # A bucket where verdaccio will store it's database & packages (optional, default to "verdaccio")
    # bucket: 'npm'

    # Number of retry when a request to minio fails (optional, default to 10)
    # retries: 3

    # Delay between retries (optional, default to 100)
    # delay: 50

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc

auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
    max_users: -1

# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
    maxage: 30m
    cache: true
  taobao:
    url: https://registry.npm.taobao.org/
    maxage: 30m
    cache: true
  feidao:
    url: http://registry.npm.ifeidao.com:7001/
    maxage: 2m
    cache: true
    auth:
      type: bearer
      token: xxx

packages:
  '@dfeidao-works/*':
    access: $authenticated
    publish: feidao
    unpublish: feidao
  '@feidao-works/*':
    access: $authenticated
    proxy: feidao
  '@dfeidao/*':
    access: $authenticated
    proxy: feidao
  '@feidao/*':
    access: $authenticated
    proxy: feidao
  '**':
    access: $authenticated
    proxy: feidao

middlewares:
  audit:
    enabled: true

# log settings
logs:
  # - { type: stdout, format: pretty, level: http }
  - {type: file, path: logs/verdaccio.log, level: debug}

注意:该配置文件中以下配置必须修改

获取方法:

  1. uplinks.feidao.url上进行登陆
npm login --registry=http://registry.npm.ifeidao.com:7001

登陆成功后通过cat ~/.npmrc找到对应的服务器,如

//registry.npm.ifeidao.com/:_authToken="xxxxxxx"

其中,xxxxxxx部分就是我们要的token.

如果由于服务器重启等原因该token失效了(具体表现为开发人员无法下载新发布的软件包),需要使用以上步骤重新生成.

3.6. proxy

3.7. 包含内容

本身没有任何包在上面发布,只作为代理服务器使用,一般用作内网加速,如果没有内网环境,则不需要进行该项配置.

3.8. 配置文件

3.8.1. htpasswd

由于我们在使用代理服务器的时候环境一定为内网环境,所以为了使用方便,可以保持该配置文件内容为空,并且放开所有权限(见下面配置文件部分)

3.8.2. conf/config.yml

# path to a directory with all packages
storage: /verdaccio/storage/data
# path to a directory with plugins to include
plugins: /verdaccio/plugins

# Here's the plugin configuration option
store:
  minio:
    # The HTTP port of your minio instance
    port: 9000

    # The endpoint on which verdaccio will access minio (without scheme)
    endPoint: minio

    # The minio access key
    accessKey: feidao

    # The minio secret key
    secretKey: Feidao111111

    # Disable SSL if you're accessing minio directly through HTTP
    useSSL: false

    # The region used by your minio instance (optional, default to "us-east-1")
    # region: eu-west-1

    # A bucket where verdaccio will store it's database & packages (optional, default to "verdaccio")
    # bucket: 'npm'

    # Number of retry when a request to minio fails (optional, default to 10)
    # retries: 3

    # Delay between retries (optional, default to 100)
    # delay: 50

web:
  # WebUI is enabled as default, if you want disable it, just uncomment this line
  #enable: false
  title: Verdaccio
  # comment out to disable gravatar support
  # gravatar: false
  # by default packages are ordercer ascendant (asc|desc)
  # sort_packages: asc

auth:
  htpasswd:
    file: /verdaccio/storage/htpasswd
    max_users: -1

# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
    maxage: 30m
    cache: true
  taobao:
    url: https://registry.npm.taobao.org/
    maxage: 30m
    cache: true
  daoke:
    url: http://npm.yourcompany.com/
    maxage: 2m
    cache: true
    auth:
      type: bearer
      token: xxx

packages:
  '@dfeidao/*':
    access: $all
    proxy: daoke

  '@dfeidao-works/*':
    access: $all
    proxy: daoke

  '@feidao-works/*':
    access: $all
    proxy: daoke

  '**':
    access: $all
    proxy: taobao

middlewares:
  audit:
    enabled: true

# log settings
logs:
  # - { type: stdout, format: pretty, level: http }
  - {type: file, path: logs/verdaccio.log, level: info}

如上所述,uplinks.feidao.auth.token配置部分见上.

4. 仓库地址

4.1. 访问页面地址

http://npm.yourcompany.com

4.2. 项目配置

.yarnrc

--registry "http://proxy"
--no-lockfile false

// 注意,这里通常应该为内网的代理服务器地址,如果没有部署代理服务器,可以直接使用外网地址,它通常为http://npm.yourcompany.com

.npmrc

registry=http://npm.yourcompany.com
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs
puppeteer_download_host=http://npm.ifeidao.com/mirrors
sharp_dist_base_url=https://npm.ifeidao.com/mirrors/sharp-libvips/v8.8.1/
package-lock=true