-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up cloudant locally with one script
- Loading branch information
Agnes Lin
committed
Nov 18, 2019
1 parent
a0e3699
commit ef41ae7
Showing
8 changed files
with
247 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,23 @@ | |
|
||
const _ = require('lodash'); | ||
const async = require('async'); | ||
const spawn = require('child_process').spawn; | ||
const docker = new require('dockerode')(); | ||
const fmt = require('util').format; | ||
const http = require('http'); | ||
const ms = require('ms'); | ||
const fs = require('fs-extra'); | ||
|
||
// // we don't pass any node flags, so we can call _mocha instead the wrapper | ||
// const mochaBin = require.resolve('mocha/bin/_mocha'); | ||
/** | ||
* This script creates a new couchDB3 container locally. And it also creates the admin for | ||
* the container. Type in bash command: | ||
* ```bash | ||
* CLOUDANT_PASSWORD=myadmin CLOUDANT_PASSWORD=mypass CLOUDANT_DATABASE=mydb node docker.setup.sh | ||
* ``` | ||
* to customize the names. | ||
*/ | ||
|
||
process.env.CLOUDANT_DATABASE = 'testdb'; | ||
process.env.CLOUDANT_PASSWORD = 'pass'; | ||
process.env.CLOUDANT_USERNAME = 'admin'; | ||
process.env.CLOUDANT_DATABASE = process.env.CLOUDANT_DATABASE || 'testdb'; | ||
process.env.CLOUDANT_PASSWORD = process.env.CLOUDANT_PASSWORD || 'pass'; | ||
process.env.CLOUDANT_USERNAME = process.env.CLOUDANT_USERNAME || 'admin'; | ||
|
||
// these are placeholders. They get set dynamically based on what IP and port | ||
// get assigned by docker. | ||
|
@@ -39,7 +43,7 @@ async.waterfall( | |
setCloudantEnv, | ||
waitFor('/_all_dbs'), | ||
createAdmin(), | ||
createDB('testdb'), | ||
createDB(process.env.CLOUDANT_DATABASE), | ||
listUser(), | ||
exportENV(), | ||
], | ||
|
@@ -53,12 +57,14 @@ async.waterfall( | |
|
||
function sleep(n) { | ||
return function delayedPassThrough() { | ||
// eslint-disable-next-line prefer-rest-params | ||
const args = [].slice.call(arguments); | ||
// last argument is the callback | ||
const next = args.pop(); | ||
// prepend `null` to indicate no error | ||
args.unshift(null); | ||
setTimeout(function() { | ||
// eslint-disable-next-line prefer-spread | ||
next.apply(null, args); | ||
}, n); | ||
}; | ||
|
@@ -68,6 +74,7 @@ function dockerStart(imgName) { | |
return function pullAndStart(next) { | ||
console.log('pulling image: %s', imgName); | ||
docker.pull(imgName, function(err, stream) { | ||
// eslint-disable-next-line no-shadow | ||
docker.modem.followProgress(stream, function(err, output) { | ||
if (err) { | ||
return next(err); | ||
|
@@ -80,6 +87,7 @@ function dockerStart(imgName) { | |
PublishAllPorts: true, | ||
}, | ||
}, | ||
// eslint-disable-next-line no-shadow | ||
function(err, container) { | ||
console.log( | ||
'recording container for later cleanup: ', | ||
|
@@ -89,6 +97,7 @@ function dockerStart(imgName) { | |
if (err) { | ||
return next(err); | ||
} | ||
// eslint-disable-next-line no-shadow | ||
container.start(function(err, data) { | ||
next(err, container); | ||
}); | ||
|
@@ -164,6 +173,7 @@ function waitFor(path) { | |
}); | ||
}) | ||
.on('error', tryAgain); | ||
// eslint-disable-next-line no-shadow | ||
function tryAgain(err) { | ||
setTimeout(ping, CONNECT_DELAY, err, tries - 1); | ||
} | ||
|
@@ -173,7 +183,7 @@ function waitFor(path) { | |
|
||
function createAdmin() { | ||
return function createAdminUser(container, next) { | ||
const data = '"pass"'; | ||
const data = `"${process.env.CLOUDANT_PASSWORD}"`; | ||
const uri = | ||
'/_node/[email protected]/_config/admins/' + | ||
process.env.CLOUDANT_USERNAME; | ||
|
@@ -288,6 +298,7 @@ function exportENV() { | |
} | ||
|
||
// clean up any previous containers | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function dockerCleanup(next) { | ||
if (containerToDelete) { | ||
console.log('cleaning up container: %s', containerToDelete.id); | ||
|
Oops, something went wrong.