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
/** | |
* Run a series of async functions in "batches", | |
* so that `batchSize` number of fns are running concurrently | |
* | |
* @param {function():Promise<T>[]} fns | |
* @param {int} batchSize | |
* @return {Promise<T[]>} | |
*/ | |
function batch(fns, batchSize) { | |
const batchFns = _.chunk(fns, batchSize) |
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
const co = require('co'); | |
const stream = require('stream'); | |
function S3InMemoryClient() { | |
var memFs = {}; | |
const client = { | |
upload: (opts, cb) => co(function*() { | |
const data = opts.Body instanceof stream.Readable ? |
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
import * as assert from 'assert'; | |
function assertPartial(actualObj:any, expectedPartial: any, msg?:string) { | |
const actualPartial:any = Object.keys(expectedPartial) | |
.reduce((part, key) => ({ | |
...part, | |
[key]: actualPartial[key] | |
}), {}); | |
assert.deepStrictEqual(actualPartial, expectedPartial, msg); |
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
const co = require('co'); | |
const portfinder = require('portfinder'); | |
const mongoServer = require('mongodb-prebuilt'); | |
const tmp = require('tmp'); | |
tmp.setGracefulCleanup(); | |
var db, mongoDataTmp; | |
before(() => co(function*() { | |
const dsn = process.env.MONGO_DB_DSN || (yield startMongoServer()); |
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
/** | |
* @param {Promise<T>} p | |
* @param {int} duration Milliseconds until timeout | |
* | |
* @returns {Promise<T, TimeoutError>} | |
*/ | |
function timeout(p, duration) { | |
const failAfterDuration = new Promise((resolve, reject) => { | |
const err = Object.assign(new Error(`Timed out after ${duration}ms`), { name: 'TimeoutError' }); | |
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
/** | |
* | |
* @param {string|Object} reqOpts Url, or `request` options | |
* @param {string} destFile file path | |
* @throws ExternalServiceError | |
* @return {Promise} | |
*/ | |
function download(reqOpts, destFile) { | |
return new Promise((resolve, reject) => { | |
request(reqOpts) |
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
const co = require('co'); | |
const _tmp = require('tmp'); | |
_tmp.setGracefulCleanup(); | |
// Promise wrappers around tmp | |
const tmp = { | |
/** @return {Promise<{path, cleanup}>} */ | |
file: () => co(function* () { | |
return yield cb => _tmp.file({ unsafeCleanup: true }, (err, path, fd, cleanup) => cb(err, { | |
path, |
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
const S3 = require('aws-sdk').S3; | |
const dotenv = require('dotenv'); | |
const Url = require('url'); | |
const p = require('util').promisify; | |
const fs = require('fs'); | |
/** | |
* @param {string} envUri | |
* @returns {Promise<Object>} | |
*/ |
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
const _ = require('lodash'); | |
/** | |
* @param {{ | |
* name: string, | |
* version: string, | |
* image: string, | |
* labels?: Object, | |
* replicas?: int, | |
* imagePullPolicy?: 'Always' | 'Never' | 'IfNotPresent', |
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
// See https://gist.github.com/eschwartz/4f16fcb963954d433753ffe32ce5d5ca | |
const ReplicationController = require('./ReplicationController'); | |
const fs = require('fs-extra'); | |
// See https://gist.github.com/eschwartz/310a7d9938b60eaf49c8d56c1ccfb759 | |
const loadS3Env = require('./loadS3Env'); | |
const path = require('path'); | |
const Cli = require('admiral-cli'); | |
const co = require('co'); | |
function main() { |