Skip to content
This repository has been archived by the owner on Nov 16, 2019. It is now read-only.

Commit

Permalink
MULTISKIM all squashed and cleaned up.
Browse files Browse the repository at this point in the history
* Replaced cuttlefish with multi-fs.
* Removed the dependency on mcouch; restructured signficantly.
* Added bunyan logging output for more diagnosible logs.
* Added 'log' events to emit debugging information.
* Switched from tap testing to lab testing.
* Expanded the tests somewhat & based them on a couchdb snapshot starting point.
* Tweaked command-line options slightly.
* Added semicolons like a stodgy person.
* Added a functional test in `npm run dev` that skims from fullfatdb into
  a local couchdb.
  • Loading branch information
C J Silverio committed May 7, 2014
1 parent 841ad86 commit 96609ed
Show file tree
Hide file tree
Showing 21 changed files with 1,306 additions and 547 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
.sequence
.DS_Store
1 change: 1 addition & 0 deletions .npmignore
@@ -0,0 +1 @@
test/
20 changes: 20 additions & 0 deletions .wercker.yml
@@ -0,0 +1,20 @@
box: wercker/nodejs
services:
- mies/couchdb

build:
steps:
- npm-install
- npm-test

- script:
name: echo nodejs information
code: |
echo "node version $(node -v) running"
echo "npm version $(npm -v) running"
- script:
name: curl
code: |
echo $WERCKER_COUCHDB_HOST
curl -X PUT "$WERCKER_COUCHDB_HOST:5984/registry"
curl -X GET "$WERCKER_COUCHDB_HOST:5984/_all_dbs"
43 changes: 19 additions & 24 deletions README.md
Expand Up @@ -3,6 +3,8 @@
[Mcouch](http://npm.im/mcouch) for npm registries. The opposite of
[npm-fullfat-registry](http://npm.im/npm-fullfat-registry).

[![wercker status](https://app.wercker.com/status/185fe5071b01008479f47c654f86cdbc/m/ "wercker status")](https://app.wercker.com/project/bykey/185fe5071b01008479f47c654f86cdbc)

This moves attachments to the target in manta, but then *also* deletes
them out of the couchdb. It avoids then deleting them out of manta,
by specifying a `{skip: true}` value for each tarball associated with
Expand All @@ -13,26 +15,25 @@ This results in deleting attachments that don't belong (except for
but keeping attachments in Manta if they are needed for a published
version, even as they are removed from couchdb.

You probably don't need this. It's super niche. More likely, if
You probably don't need this. It's super niche. More likely, if
you're even reading this, you want either [mcouch](http://npm.im/mcouch)
or [npm-fullfat-registry](http://npm.im/npm-fullfat-registry).

## USAGE

```javascript
Skim({
client: myMantaClient,
db: myCouchDBUrl,
path: pathInMantaWhereStuffGoes,
seqFile: '.sequence',
client: multiFSClient,
source: myCouchDBUrl,
sequenceFile: '.sequence',
inactivity_ms: 60*60*1000,
delete: true
delete: true
}).on('put', function(doc) {
console.log('PUT %s', doc._id);
}).on('rm', function(doc) {
console.log('RM %s', doc._id);
}).on('send', function(doc, file) {
console.log('-> sent %s/%s', doc._id, file.name);
console.log('-> sent %s/%s', doc._id, filename);
}).on('delete', function(doc, remote) {
console.log('-> deleted %s/%s', doc._id, remote);
});
Expand All @@ -41,25 +42,19 @@ Skim({
Or on the cli:

```
> ./bin/skim.js --help
npm-skim-registry - Skim the fat out of your registry couchdb
Usage: npm-skim-registry [args] COUCHDB MANTAPATH
Usage: npm-skim-registry [args] COUCHDB
COUCHDB Full url to your couch, like
http://localhost:5984/database
MANTAPATH Remote path in Manta, like
~~/stor/database
-Q FILE, --seq-file=FILE File to store the sequence in
-q NUMBER, --seq=NUMBER Sequence ID to start at
--inactivity-ms=MS Max ms to wait before assuming
disconnection.
-d, --delete Delete removed attachments and docs from
manta
-s URL, --skim=URL Target to write attachment free docs.
Defaults to put back into COUCHDB arg.
-a ACCOUNT, --account=ACCOUNT Manta Account (login name)
-h, --help Print this help and exit
-i, --insecure Do not validate SSL certificate
-k FINGERPRINT, --keyId=FINGERPRINT SSH key fingerprint
-u URL, --url=URL Manta URL
-v, --verbose verbose mode
-f FILE, --config=FILE config file for multifs targets; required
-Q FILE, --seq-file=FILE File to store the sequence in, required
-q NUMBER, --seq=NUMBER Sequence ID to start at; overrides sequence in file
-r URL, --registry=URL The registry where attachments can be found; optional
--inactivity-ms=MS Max ms to wait before assuming disconnection.
-d, --delete Delete removed attachments and docs from targets
-s URL, --skimdb=URL Target to write attachment-free docs. Defaults to
put back into COUCHDB arg.
-h, --help Print this help and exit
```
134 changes: 79 additions & 55 deletions bin/skim.js
@@ -1,92 +1,116 @@
#!/usr/bin/env node
var createClient = require('manta-client');
var manta = require('manta');
var Skim = require('../');
var dashdash = require('dashdash');

var
Skimmer = require('../skim'),
bunyan = require('bunyan'),
dashdash = require('dashdash'),
MultiFS = require('multi-fs'),
path = require('path'),
util = require('util')
;

var parser = dashdash.createParser({
options: [
{ names: [ 'config', 'f' ],
type: 'string',
help: 'config file for multifs targets; required',
helpArg: 'FILE' },
{ names: [ 'seq-file', 'Q' ],
type: 'string',
help: 'File to store the sequence in',
help: 'File to store the sequence in, required',
helpArg: 'FILE' },
{ names: [ 'seq', 'q' ],
type: 'number',
help: 'Sequence ID to start at',
help: 'Sequence ID to start at; overrides sequence in file',
helpArg: 'NUMBER' },
{ names: [ 'registry', 'r' ],
type: 'string',
help: 'The registry where attachments can be found. Optional.',
help: 'The registry where attachments can be found; optional',
helpArg: 'URL' },
{ names: [ 'inactivity-ms' ],
type: 'number',
help: 'Max ms to wait before assuming disconnection.',
helpArg: 'MS' },
{ names: [ 'delete', 'd' ],
type: 'bool',
help: 'Delete removed attachments and docs from manta' },
{ names: [ 'skim', 's'] ,
help: 'Delete removed attachments and docs from targets' },
{ names: [ 'skimdb', 's'] ,
type: 'string',
helpArg: 'URL',
help: 'Target to write attachment free docs. ' +
'Defaults to put back into COUCHDB arg.' }

].concat(manta.DEFAULT_CLI_OPTIONS)
help: 'Target to write attachment-free docs. ' +
'Defaults to put back into COUCHDB arg.' },
{ names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit' },
]
});

var opts = parser.parse(process.argv, process.env);
var args = opts._args;

if (opts.help || args.length !== 4)
return usage();

var client = createClient(process.argv, process.env);
var db = args[2];
var path = args[3];
var seqFile = opts.seq_file;
var seq = opts.seq;
var inactivity_ms = opts.inactivity_ms;
var del = opts.delete;
var skim = opts.skim || opts.db;
var registry = opts.registry || null;
if (opts.help || args.length !== 3)
{
usage();
process.exit();
}

if (args.length !== 3)
{
usage();
process.exit(1);
}

if (!db || !path) {
usage();
process.exit(1);
function usage()
{
console.log(
'npm-skim-registry - Skim the fat out of your registry couchdb\n' +
'Usage: npm-skim-registry [args] COUCHDB\n' +
'\n' +
' COUCHDB Full url to your couch, e.g.,\n'+
' http://localhost:5984/database');
console.log(parser.help());
}

function usage() {
console.log(usage.toString().split(/\n/).slice(4, -2).join('\n'));
console.log(parser.help());
/*
npm-skim-registry - Skim the fat out of your registry couchdb
Usage: npm-skim-registry [args] COUCHDB MANTAPATH
var logopts =
{
name: 'npm-skim-registry',
serializers: bunyan.stdSerializers,
streams: [ ]
};

COUCHDB Full url to your couch, like
http://localhost:5984/database
MANTAPATH Remote path in Manta, like
~~/stor/database
*/
}
if (process.env.NODE_ENV === 'dev')
logopts.streams.push({level: 'debug', stream: process.stdout});
else
logopts.streams.push({level: 'info', stream: process.stdout});

var logger = bunyan.createLogger(logopts);

Skim({
client: client,
db: db,
path: path,
seqFile: seqFile,
inactivity_ms: inactivity_ms,
seq: seq,
delete: del,
skim: skim,
registry: registry

var targets = require(path.resolve(opts.config));
var client = new MultiFS(targets);

var skimmer = new Skimmer({
client: client,
sequence: opts.seq,
sequenceFile: opts.seq_file,
inactivity_ms: opts.inactivity_ms,
delete: opts.delete,
source: args[2],
skimdb: opts.skimdb,
registry: opts.registry || null,
}).on('put', function(change) {
console.log('PUT %s', change.id);
logger.info('PUT ' + change.id);
}).on('rm', function(change) {
console.log('RM %s', change.id);
logger.info('RM ' + change.id);
}).on('send', function(change, file) {
console.log('-> sent %s/%s', change.id, file.name);
logger.info(util.format('-> sent %s', file));
}).on('delete', function(change, remote) {
console.log('-> deleted %s/%s', change.id, remote);
logger.info(util.format('-> deleted %s/%s', change.id, remote));
}).on('putBack', function(change) {
console.error('-> putback %s', change.id);
logger.warning(util.format('-> putback %s', change.id));
}).on('log', function(msg) {
// logger.debug('LOG: ' + msg);
});

skimmer.start();
logger.info('now skimming ' + skimmer.source + ' into ' + skimmer.skimdb);
45 changes: 30 additions & 15 deletions package.json
@@ -1,24 +1,31 @@
{
"name": "npm-skim-registry",
"version": "1.0.2",
"description": "Move attachments into Manta and out of the registry",
"main": "skim.js",
"version": "1.0.2",
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"bin": "bin/skim.js",
"bugs": "https://github.com/npm/npm-skim-registry/issues",
"dependencies": {
"async": "^0.8.0",
"bunyan": "^0.22.3",
"dashdash": "~1.4.0",
"mcouch": "~2.0.1",
"manta-client": "~1.0.5",
"follow": "^0.10.4",
"http-https": "~1.0.0",
"parse-json-response": "~1.0.0",
"manta": "~1.2.6",
"npm-registry-readme-trim": "~1.0.0"
"multi-fs": "~0.2.0",
"npm-registry-readme-trim": "~1.0.0",
"request": "^2.34.0",
"seq-file": "^1.0.1"
},
"scripts": {
"test": "tap test/*.js"
},
"repository": {
"type": "git",
"url": "git://github.com/isaacs/npm-mcouch"
"devDependencies": {
"lab": "^3.0.1",
"manta": "~1.2.6",
"manta-client": "~1.0.5",
"mkdirp": "^0.3.5",
"must": "^0.11.0",
"parse-json-response": "~1.0.0",
"rimraf": "^2.2.6"
},
"homepage": "https://github.com/npm/npm-skim-registry",
"keywords": [
"npm",
"manta",
Expand All @@ -28,7 +35,15 @@
"registry",
"attachments"
],
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC",
"bin": "bin/skim.js"
"main": "skim.js",
"repository": {
"type": "git",
"url": "git://github.com/npm/npm-skim-registry"
},
"scripts": {
"test": "lab test/test*.js",
"coverage": "lab -vc test/test*.js",
"dev": "NODE_ENV=dev ./bin/skim.js -Q .sequence -s http://localhost:5984/registry -f test/dev-targets.js https://fullfatdb.npmjs.com/registry | bunyan -o short"
}
}

0 comments on commit 96609ed

Please sign in to comment.