Giter VIP home page Giter VIP logo

npm_lazy's Introduction

Docker npm_lazy

Stories in Ready

Add this Docker container to your orchestration and enjoy near-instantaneous package dependency resolutions, courtesy of mixu's lazy npm cache (repository mixu/npm_lazy).

Usage

In order to utilize the container's service, you'll have to configure the server's settings and also direct your local npm clients to use it as it's source for registry data.

There are two ways you can use the containerized npm_lazy server:

  • by mapping the server's port locally, exposing it within your host environment
  • by linking it to other containers

Using the server from your local host

The server defaults are configured to play nicely with local setups, i.e. when you want the npm client from your host to retrieve the packages through the cache from the running container.

The only important thing you need to do is to map the default exposed port from the container to the same port on your host:

# Start a detached container, mapping the exposed port locally
sudo docker run -d -p 8080:8080 langrisha/npm-lazy

You can verify that the service is then accessible from your host via:

$ curl http://localhost:8080
{"db_name":"registry"}

Linking with other containers

If you would like containers residing on your host to use the npm_lazy server, give your container a hostname and add your configuration module to the container.

Then, configure the npm clients on all the linked containers and configure their registries to point to the npm_lazy host.

Here's a high-level overview using fig.sh:

web:
  image: google/nodejs
  environment:
    - npm_config_registry=http://npmlazy
  links:
    - npmlazy
npmlazy:
  image: langrisha/npm-lazy
  command: --show-config --port=80 --external-url=http://npmlazy

Configuring the npm_lazy server

The npm_lazy/server is wrapped with a thin client that allows you to dynamically configure the server from the command-line options or the environment on startup.

You can configure the server by passing arguments when starting the container.

$ node index.js --help

  Usage: index [options]

  Starts a dynamically configured npm_lazy server instance

  Options:

    -h, --help                             output usage information
    -V, --version                          output the version number
    --show-config                          display the effective server configuration on startup
    --logging-opts_log-to-console [value]  
    --logging-opts_log-to-file [value]
    --logging-opts_filename [value]
    --cache-directory [value]
    --cache-age [value]
    --http-timeout [value]
    --max-retries [value]
    --reject-unauthorized [value]
    --external-url [value]
    --remote-url [value]
    --port [value]
    --host [value]
    --proxy_https [value]
    --proxy_http [value]

Environment variables

Any environment variables that start with NPM_LAZY_ will be interpreted as a configuration argument. For example, putting NPM_LAZY_PORT=80 in your environment will set the --port argument to 80. Environment variables are case-sensitive, so npm_lazy_port will not work.

$ export NPM_LAZY_CACHE_DIRECTORY=/tmp/npm_lazy
$ export NPM_LAZY_EXTERNAL_URL=http://npm_lazy
$ export NPM_LAZY_PORT=80
$ node index.js

Configuring the npm client

There are several ways you can configure the npm client, outlined from official sources.

A few great examples involve configuring the environment:

docker run -e npm_config_registry=http://localhost:8080 nodejsapp

or providing a project-specific npmrc file:

# myproj/.npmrc
registry = http://localhost:8080/

Troubleshooting

You'll have to pay attention to the configured server's port and external URL. The server's provided defaults configure the server to listen on 0.0.0.0:8080 and to be accessible from the URL http://localhost:8080.

Make sure the networking requirements for the server are satisfied correctly and that the server running within your container matches the details of how it is accessed externally.

You can pass the --show-config container command to display the server's runtime configuration. Use npm install --verbose to get more output from the client and make sure the hosts for the package URLs when they're looked up and downloaded always match up.

See also

npm_lazy's People

Contributors

langri-sha avatar ralfschimmel avatar stanangeloff avatar wojas avatar waffle-iron avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.