docs: refresh readme
This commit is contained in:
parent
1ad9c743ec
commit
2f48346a6f
116
readme.md
116
readme.md
@ -1,53 +1,94 @@
|
|||||||
# npm-cache-proxy
|
<h1 align="center">
|
||||||
|
<img width="400" src="./logo.png">
|
||||||
|
|
||||||

|
npm-cache-proxy
|
||||||
|
</h1>
|
||||||
|
|
||||||
- [npm-cache-proxy](#npm-cache-proxy)
|
<p align="center">
|
||||||
- [Quick start](#quick-start)
|
<a href="https://hub.docker.com/r/emeralt/npm-cache-proxy/tags">
|
||||||
- [Deployment](#deployment)
|
<img src="https://img.shields.io/github/release/emeralt/npm-cache-proxy.svg" alt="Current Release" />
|
||||||
- [Usage](#usage)
|
</a>
|
||||||
- [`ncp`](#ncp)
|
<a href="https://hub.docker.com/r/emeralt/npm-cache-proxy/builds">
|
||||||
- [`ncp list`](#ncp-list)
|
<img src="https://img.shields.io/docker/cloud/build/emeralt/npm-cache-proxy.svg" alt="CI Build">
|
||||||
- [`ncp purge`](#ncp-purge)
|
</a>
|
||||||
- [Programmatic usage](#programmatic-usage)
|
<a href="https://github.com/emeralt/npm-cache-proxy/blob/master/liscense">
|
||||||
- [Example](#example)
|
<img src="https://img.shields.io/github/license/emeralt/npm-cache-proxy.svg" alt="Licence">
|
||||||
- [Benchmark](#benchmark)
|
</a>
|
||||||
- [License](#license)
|
</p>
|
||||||
|
|
||||||
## Quick start
|
> `npm-cache-proxy` is a lightweight npm caching proxy written in Go that achives warp speeds by using Redis for data storage. B-b-blazing fast!
|
||||||
Release binaries for different platforms can be downloaded on the [Releases](https://github.com/emeralt/npm-cache-proxy/releases) page. Also, [Docker Image](https://cloud.docker.com/u/emeralt/repository/docker/emeralt/npm-cache-proxy) is provided.
|
|
||||||
|
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Table of Contents</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
- [Getting started](#getting-started)
|
||||||
|
- [CLI](#cli)
|
||||||
|
- [`ncp`](#ncp)
|
||||||
|
- [`ncp list`](#ncp-list)
|
||||||
|
- [`ncp purge`](#ncp-purge)
|
||||||
|
- [Programmatic usage](#programmatic-usage)
|
||||||
|
- [Example](#example)
|
||||||
|
- [Deployment](#deployment)
|
||||||
|
- [Benchmark](#benchmark)
|
||||||
|
- [License](#license)
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
Release binaries for different platforms can be downloaded on the [Releases](https://github.com/emeralt/npm-cache-proxy/releases) page. Also, [Docker image](https://cloud.docker.com/u/emeralt/repository/docker/emeralt/npm-cache-proxy) is provided.
|
||||||
|
|
||||||
|
The fastest way to get started with NCP is to use Docker image:
|
||||||
```bash
|
```bash
|
||||||
docker run -e REDIS_ADDRESS=host.docker.internal:6379 -p 8080:8080 -it emeralt/npm-cache-proxy
|
# run proxy inside of docker container in background
|
||||||
|
docker run -e REDIS_ADDRESS=host.docker.internal:6379 -p 8080:8080 -it emeralt/npm-cache-proxy -d
|
||||||
|
|
||||||
|
# configure npm to use caching proxy as registry
|
||||||
|
npm config set registry http://localhost:8080
|
||||||
```
|
```
|
||||||
|
|
||||||
## Deployment
|
## CLI
|
||||||
NCP can be deployed using Kubernetes, Docker Compose or any other container orchestration platform. NCP supports running indefinite amount of instances simultaneously.
|
Additionally, NCP provides a command line utility for proxy configuration and data management.
|
||||||
|
|
||||||
## Usage
|
---
|
||||||
|
|
||||||
|
| Global Options | Env | Default | Description |
|
||||||
|
| ----------------------------- | ---------------- | ----------------------- | ----------------- |
|
||||||
|
| `--redis-address <address>` | `REDIS_ADDRESS` | `http://localhost:6379` | Redis address |
|
||||||
|
| `--redis-database <database>` | `REDIS_DATABASE` | `0` | Redis database |
|
||||||
|
| `--redis-password <password>` | `REDIS_PASSWORD` | - | Redis password |
|
||||||
|
| `--redis-prefix <prefix>` | `REDIS_PREFIX` | `ncp-` | Redis keys prefix |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### `ncp`
|
### `ncp`
|
||||||
|
|
||||||
Start proxy server.
|
Start proxy server.
|
||||||
|
|
||||||
| Options | Env | Default | Description |
|
```bash
|
||||||
| ----------------------------- | ------------------ | ---------------------------- | ----------------------------------- |
|
ncp --listen "localhost:1234" # listen on port 1234
|
||||||
| `--listen <address>` | `LISTEN_ADDRESS` | `locahost:8080` | Address to listen |
|
```
|
||||||
| `--upstream <address>` | `UPSTREAM_ADDRESS` | `https://registry.npmjs.org` | Upstream registry address |
|
|
||||||
| `--cache-limit <count>` | `CACHE_LIMIT` | - | Cached packages count limit |
|
| Options | Env | Default | Description |
|
||||||
| `--cache-ttl <timeout>` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds |
|
| ----------------------- | ------------------ | ---------------------------- | ----------------------------------- |
|
||||||
| `--redis-address <address>` | `REDIS_ADDRESS` | `http://localhost:6379` | Redis address |
|
| `--listen <address>` | `LISTEN_ADDRESS` | `locahost:8080` | Address to listen |
|
||||||
| `--redis-database <database>` | `REDIS_DATABASE` | `0` | Redis database |
|
| `--upstream <address>` | `UPSTREAM_ADDRESS` | `https://registry.npmjs.org` | Upstream registry address |
|
||||||
| `--redis-password <password>` | `REDIS_PASSWORD` | - | Redis password |
|
| `--cache-limit <count>` | `CACHE_LIMIT` | - | Cached packages count limit |
|
||||||
| `--redis-prefix <prefix>` | `REDIS_PREFIX` | `ncp-` | Redis keys prefix |
|
| `--cache-ttl <timeout>` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### `ncp list`
|
### `ncp list`
|
||||||
|
List all cached packages.
|
||||||
|
|
||||||
List cached packages.
|
---
|
||||||
|
|
||||||
### `ncp purge`
|
### `ncp purge`
|
||||||
|
Purge all cached packages.
|
||||||
|
|
||||||
Purge cached packages.
|
---
|
||||||
|
|
||||||
## Programmatic usage
|
## Programmatic usage
|
||||||
Along with the CLI, go package is provided. Documentation is available on [godoc.org](https://godoc.org/github.com/emeralt/npm-cache-proxy/proxy).
|
Along with the CLI, go package is provided. Documentation is available on [godoc.org](https://godoc.org/github.com/emeralt/npm-cache-proxy/proxy).
|
||||||
@ -70,12 +111,18 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
proxy := npmproxy.Proxy{
|
proxy := npmproxy.Proxy{
|
||||||
|
// you can provide you own Database
|
||||||
|
// or use an existing one
|
||||||
Database: npmproxy.DatabaseRedis{
|
Database: npmproxy.DatabaseRedis{
|
||||||
Client: redis.NewClient(&redis.Options{
|
Client: redis.NewClient(&redis.Options{
|
||||||
Addr: "localhost:6379",
|
Addr: "localhost:6379",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// allows to reuse tcp connections
|
||||||
HttpClient: &http.Client{},
|
HttpClient: &http.Client{},
|
||||||
|
|
||||||
|
// allows to get options dynamically
|
||||||
GetOptions: func() (npmproxy.Options, error) {
|
GetOptions: func() (npmproxy.Options, error) {
|
||||||
return npmproxy.Options{
|
return npmproxy.Options{
|
||||||
DatabasePrefix: "ncp-",
|
DatabasePrefix: "ncp-",
|
||||||
@ -85,16 +132,21 @@ func main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// listen on http://localhost:8080
|
||||||
proxy.Server(npmproxy.ServerOptions{
|
proxy.Server(npmproxy.ServerOptions{
|
||||||
ListenAddress: "localhost:8080",
|
ListenAddress: "localhost:8080",
|
||||||
}).ListenAndServe()
|
}).ListenAndServe()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
NCP can be deployed using Kubernetes, Docker Compose or any other container orchestration platform. NCP supports running indefinite amount of instances simultaneously.
|
||||||
|
|
||||||
## Benchmark
|
## Benchmark
|
||||||
|
Macbook Pro 15″ 2017, Intel Core i7-7700HQ. Note `GOMACPROCS=1`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# GOMAXPROCS=1 GIN_MODE=release ncp --listen localhost:8080
|
# GOMAXPROCS=1 ncp --listen localhost:8080
|
||||||
|
|
||||||
$ go-wrk -c 100 -d 5 http://localhost:8080/ascii
|
$ go-wrk -c 100 -d 5 http://localhost:8080/ascii
|
||||||
Running 5s test @ http://localhost:8080/ascii
|
Running 5s test @ http://localhost:8080/ascii
|
||||||
|
Loading…
x
Reference in New Issue
Block a user