diff --git a/Dockerfile b/Dockerfile index 5a1800ddc..c79d327e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/conf/default.yaml b/conf/default.yaml index a39155377..75f639944 100644 --- a/conf/default.yaml +++ b/conf/default.yaml @@ -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 diff --git a/conf/docker.yaml b/conf/docker.yaml index 483741ea2..eb703725b 100644 --- a/conf/docker.yaml +++ b/conf/docker.yaml @@ -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 diff --git a/conf/full.yaml b/conf/full.yaml index 77ece316a..42b6b36d9 100644 --- a/conf/full.yaml +++ b/conf/full.yaml @@ -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 diff --git a/docs/config.md b/docs/config.md index 80ed1402b..b12f32fad 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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). diff --git a/docs/docker.md b/docs/docker.md index 005c3a3f1..98000bf1c 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -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. diff --git a/package.json b/package.json index 1e9e67e9d..f30ae2e6d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/config.js b/src/lib/config.js index c28673380..a2966ccfc 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -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) { diff --git a/src/lib/plugin-loader.js b/src/lib/plugin-loader.js index 1bfdeaf27..c240923ff 100644 --- a/src/lib/plugin-loader.js +++ b/src/lib/plugin-loader.js @@ -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( // 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}`); diff --git a/types/index.js b/types/index.js index 9956d46b7..b5f989119 100644 --- a/types/index.js +++ b/types/index.js @@ -23,6 +23,7 @@ export type StringValue = verdaccio$StringValue; export type StartUpConfig = { storage: string; + plugins?: string; self_path: string; } diff --git a/yarn.lock b/yarn.lock index 12ff47662..b19e8b989 100644 Binary files a/yarn.lock and b/yarn.lock differ