feat: adds support for external plugin directory (#532)

This commit is contained in:
Michiel De Mey 2018-07-18 14:53:08 +02:00 committed by Ayush Sharma
parent a14a737241
commit 11dcf798cc
11 changed files with 44 additions and 7 deletions

View File

@ -27,7 +27,7 @@ RUN npm config set registry http://registry.npmjs.org/ && \
yarn cache clean && \
yarn install --production=true --pure-lockfile
RUN mkdir -p /verdaccio/storage /verdaccio/conf
RUN mkdir -p /verdaccio/storage /verdaccio/plugins /verdaccio/conf
ADD conf/docker.yaml /verdaccio/conf/config.yaml

View File

@ -8,6 +8,8 @@
# path to a directory with all packages
storage: ./storage
# path to a directory with plugins to include
plugins: ./plugins
web:
# WebUI is enabled as default, if you want disable it, just uncomment this line

View File

@ -12,6 +12,8 @@
# path to a directory with all packages
storage: /verdaccio/storage
# path to a directory with plugins to include
plugins: /verdaccio/plugins
web:
# WebUI is enabled as default, if you want disable it, just uncomment this line

View File

@ -1,5 +1,7 @@
# path to a directory with all packages
storage: ./storage
# path to a directory with plugins to include
plugins: ./plugins
web:
# WebUI is enabled as default, if you want disable it, just uncomment this line

View File

@ -42,6 +42,14 @@ Is the location of the default storage. **Verdaccio is by default based on local
storage: ./storage
```
### Plugins
Is the location of the plugin directory. Useful for Docker/Kubernetes based deployments.
```yaml
plugins: ./plugins
```
### Authentification
The authentification set up is done here, the default auth is based on `htpasswd` and is built-in. You can modify this behaviour via [plugins](plugins.md). For more information about this section read the [auth page](auth.md).

View File

@ -58,15 +58,19 @@ The above line will pull the latest prebuilt image from dockerhub, if you haven'
If you have [build an image locally](#build-your-own-docker-image) use `verdaccio` as the last argument.
You can use `-v` to bind mount `conf` and `storage` to the hosts filesystem:
You can use `-v` to bind mount `conf`, `storage` and `plugins` to the hosts filesystem:
```bash
V_PATH=/path/for/verdaccio; docker run -it --rm --name verdaccio -p 4873:4873 \
-v $V_PATH/conf:/verdaccio/conf \
-v $V_PATH/storage:/verdaccio/storage \
-v $V_PATH/plugins:/verdaccio/plugins \
verdaccio/verdaccio
```
>Note: Verdaccio runs as a non-root user (uid=100, gid=101) inside the container, if you use bind mount to override default, you need to make sure the mount directory is assigned to the right user. In above example, you need to run `sudo chown -R 100:101 /opt/verdaccio` otherwise you will get permission errors at runtime. [Use docker volume](https://docs.docker.com/storage/volumes/) is recommended over using bind mount.
### Plugins
Plugins can be installed in a separate directory and mounted using Docker or Kubernetes, however make sure you build plugins with native dependencies using the same base image as the Verdaccio Dockerfile.
### Docker and custom port configuration
Any `host:port` configured in `conf/config.yaml` under `listen` is currently ignored when using docker.

View File

@ -52,7 +52,7 @@
"devDependencies": {
"@commitlint/cli": "6.1.3",
"@commitlint/config-conventional": "6.1.3",
"@verdaccio/types": "3.4.1",
"@verdaccio/types": "3.4.2",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.2",

View File

@ -37,6 +37,7 @@ class Config implements AppConfig {
server_id: string;
self_path: string;
storage: string | void;
plugins: string | void;
$key: any;
$value: any;
@ -45,6 +46,7 @@ class Config implements AppConfig {
this.logger = LoggerApi.logger;
this.self_path = config.self_path;
this.storage = config.storage;
this.plugins = config.plugins;
for (let configProp in config) {
if (self[configProp] == null) {

View File

@ -37,7 +37,8 @@ function isES6(plugin) {
/**
* Load a plugin following the rules
* - First try to load from the internal directory plugins (which will disappear soon or later).
* - A seccond attempt from node_modules, in case to have multiple match as for instance verdaccio-ldap
* - A second attempt from the external plugin directory
* - A third attempt from node_modules, in case to have multiple match as for instance verdaccio-ldap
* and sinopia-ldap. All verdaccio prefix will have preferences.
* @param {*} config a reference of the configuration settings
* @param {*} pluginConfigs
@ -56,6 +57,21 @@ export default function loadPlugin<T>(
// try local plugins first
plugin = tryLoad(Path.resolve(__dirname + '/../plugins', pluginId));
// try the external plugin directory
if (plugin === null && config.plugins) {
const pluginDir = config.plugins;
plugin = tryLoad(Path.resolve(pluginDir, pluginId));
// npm package
if (plugin === null && pluginId.match(/^[^\.\/]/)) {
plugin = tryLoad(Path.resolve(pluginDir, `verdaccio-${pluginId}`));
// compatibility for old sinopia plugins
if (!plugin) {
plugin = tryLoad(Path.resolve(pluginDir, `sinopia-${pluginId}`));
}
}
}
// npm package
if (plugin === null && pluginId.match(/^[^\.\/]/)) {
plugin = tryLoad(`verdaccio-${pluginId}`);

View File

@ -23,6 +23,7 @@ export type StringValue = verdaccio$StringValue;
export type StartUpConfig = {
storage: string;
plugins?: string;
self_path: string;
}

View File

@ -234,9 +234,9 @@
version "1.0.0"
resolved "https://registry.npmjs.org/@verdaccio/streams/-/streams-1.0.0.tgz#d5d24c6747208728b9fd16b908e3932c3fb1f864"
"@verdaccio/types@3.4.1":
version "3.4.1"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-3.4.1.tgz#be18fb695bcd014c94c89b7805ace36dc9da2636"
"@verdaccio/types@3.4.2":
version "3.4.2"
resolved "https://registry.npmjs.org/@verdaccio/types/-/types-3.4.2.tgz#e1b0952df73167428dbbe071663e72911df3404e"
"@webassemblyjs/ast@1.5.9":
version "1.5.9"