docs: refresh readme

This commit is contained in:
 Ilya Atamas 2019-04-22 22:33:03 +03:00
parent 1ad9c743ec
commit 2f48346a6f
2 changed files with 84 additions and 32 deletions

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

116
readme.md
View File

@ -1,53 +1,94 @@
# npm-cache-proxy
<h1 align="center">
<img width="400" src="./logo.png">
![Docker Cloud Build Status](https://img.shields.io/docker/cloud/build/emeralt/npm-cache-proxy.svg?style=for-the-badge)
npm-cache-proxy
</h1>
- [npm-cache-proxy](#npm-cache-proxy)
- [Quick start](#quick-start)
- [Deployment](#deployment)
- [Usage](#usage)
- [`ncp`](#ncp)
- [`ncp list`](#ncp-list)
- [`ncp purge`](#ncp-purge)
- [Programmatic usage](#programmatic-usage)
- [Example](#example)
- [Benchmark](#benchmark)
- [License](#license)
<p align="center">
<a href="https://hub.docker.com/r/emeralt/npm-cache-proxy/tags">
<img src="https://img.shields.io/github/release/emeralt/npm-cache-proxy.svg" alt="Current Release" />
</a>
<a href="https://hub.docker.com/r/emeralt/npm-cache-proxy/builds">
<img src="https://img.shields.io/docker/cloud/build/emeralt/npm-cache-proxy.svg" alt="CI Build">
</a>
<a href="https://github.com/emeralt/npm-cache-proxy/blob/master/liscense">
<img src="https://img.shields.io/github/license/emeralt/npm-cache-proxy.svg" alt="Licence">
</a>
</p>
## Quick start
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.
> `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!
<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
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
NCP can be deployed using Kubernetes, Docker Compose or any other container orchestration platform. NCP supports running indefinite amount of instances simultaneously.
## CLI
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`
Start proxy server.
| Options | Env | Default | Description |
| ----------------------------- | ------------------ | ---------------------------- | ----------------------------------- |
| `--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 |
| `--cache-ttl <timeout>` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds |
| `--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 |
```bash
ncp --listen "localhost:1234" # listen on port 1234
```
| Options | Env | Default | Description |
| ----------------------- | ------------------ | ---------------------------- | ----------------------------------- |
| `--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 |
| `--cache-ttl <timeout>` | `CACHE_TTL` | `3600` | Cache expiration timeout in seconds |
---
### `ncp list`
List all cached packages.
List cached packages.
---
### `ncp purge`
Purge all cached packages.
Purge cached packages.
---
## 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).
@ -70,12 +111,18 @@ import (
func main() {
proxy := npmproxy.Proxy{
// you can provide you own Database
// or use an existing one
Database: npmproxy.DatabaseRedis{
Client: redis.NewClient(&redis.Options{
Addr: "localhost:6379",
}),
},
// allows to reuse tcp connections
HttpClient: &http.Client{},
// allows to get options dynamically
GetOptions: func() (npmproxy.Options, error) {
return npmproxy.Options{
DatabasePrefix: "ncp-",
@ -85,16 +132,21 @@ func main() {
},
}
// listen on http://localhost:8080
proxy.Server(npmproxy.ServerOptions{
ListenAddress: "localhost:8080",
}).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
Macbook Pro 15″ 2017, Intel Core i7-7700HQ. Note `GOMACPROCS=1`.
```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
Running 5s test @ http://localhost:8080/ascii