Comparing version 0.7.1 to 0.7.2
@@ -7,2 +7,3 @@ 'use strict'; | ||
var _ = require('lodash'), | ||
del = require('del'), | ||
Dockerode = require('dockerode'), | ||
@@ -131,2 +132,14 @@ fs = require('fs-extra'), | ||
fs.copy(options.dockerfile, path.join(tempAppDirectory, 'Dockerfile'), function (errCopy) { | ||
var getFilesToBeDeleted = function (callbackGetFilesToBeDeleted) { | ||
if (!options.dockerignore) { | ||
return callbackGetFilesToBeDeleted(null, []); | ||
} | ||
fs.readFile(options.dockerignore, function (errReadFile, data) { | ||
if (errReadFile) { | ||
return callbackGetFilesToBeDeleted(errReadFile); | ||
} | ||
callbackGetFilesToBeDeleted(null, data.toString('utf8').split('\n')); | ||
}); | ||
}; | ||
if (errCopy) { | ||
@@ -136,43 +149,55 @@ return callback(errCopy); | ||
tarStream = tar.pack(tempAppDirectory); | ||
tarStream.once('error', function (errTarStream) { | ||
callback(errTarStream); | ||
getFilesToBeDeleted(function (errGetFilesToBeDeleted, filesToBeDeleted) { | ||
if (errGetFilesToBeDeleted) { | ||
return callback(errGetFilesToBeDeleted); | ||
} | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
}); | ||
del(filesToBeDeleted, { cwd: tempAppDirectory }, function (errDel) { | ||
if (errDel) { | ||
return callback(errDel); | ||
} | ||
tarFile = fs.createWriteStream(tarFileName); | ||
tarFile.once('finish', function () { | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
tarStream = tar.pack(tempAppDirectory); | ||
tarStream.once('error', function (errTarStream) { | ||
callback(errTarStream); | ||
that.server.buildImage(tarFileName, { t: options.name }, function (errBuildImage, res) { | ||
var hadErrors = false; | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
}); | ||
if (errBuildImage) { | ||
return callback(errBuildImage); | ||
} | ||
tarFile = fs.createWriteStream(tarFileName); | ||
tarFile.once('finish', function () { | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
res.on('data', function (data) { | ||
var status = JSON.parse(data.toString('utf8')); | ||
that.server.buildImage(tarFileName, { t: options.name }, function (errBuildImage, res) { | ||
var hadErrors = false; | ||
if (status.error) { | ||
hadErrors = true; | ||
callback(new Error(status.error)); | ||
} | ||
}); | ||
if (errBuildImage) { | ||
return callback(errBuildImage); | ||
} | ||
res.once('end', function () { | ||
if (hadErrors) { | ||
return; | ||
} | ||
callback(null); | ||
res.on('data', function (data) { | ||
var status = JSON.parse(data.toString('utf8')); | ||
if (status.error) { | ||
hadErrors = true; | ||
callback(new Error(status.error)); | ||
} | ||
}); | ||
res.once('end', function () { | ||
if (hadErrors) { | ||
return; | ||
} | ||
callback(null); | ||
}); | ||
res.resume(); | ||
}); | ||
}); | ||
res.resume(); | ||
tarStream.pipe(tarFile); | ||
}); | ||
}); | ||
tarStream.pipe(tarFile); | ||
}); | ||
@@ -179,0 +204,0 @@ }); |
{ | ||
"name": "crew", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "crew makes managing Docker a breeze.", | ||
@@ -17,8 +17,9 @@ "contributors": [ | ||
"dependencies": { | ||
"del": "1.2.0", | ||
"dockerode": "2.1.5", | ||
"fs-extra": "0.20.1", | ||
"isolated": "0.1.2", | ||
"lodash": "3.9.3", | ||
"lodash": "3.10.0", | ||
"q": "1.4.1", | ||
"tar-fs": "1.6.0" | ||
"tar-fs": "1.7.0" | ||
}, | ||
@@ -28,5 +29,5 @@ "devDependencies": { | ||
"grunt": "0.4.5", | ||
"knockat": "0.1.4", | ||
"knockat": "0.2.1", | ||
"request": "2.58.0", | ||
"tourism": "0.19.0", | ||
"tourism": "0.20.1", | ||
"uuidv4": "0.3.1" | ||
@@ -33,0 +34,0 @@ }, |
@@ -82,2 +82,15 @@ # crew | ||
If you want to exclude some files from the newly built image, you can use the `dockerignore` property to provide the path to an ignore file. | ||
```javascript | ||
dockWorker.buildImage({ | ||
directory: __dirname, | ||
dockerfile: path.join(__dirname, 'my-dockerfile'), | ||
dockerignore: path.join(__dirname, 'my-dockerignore'), | ||
name: 'myImage' | ||
}, function (err) { | ||
// ... | ||
}); | ||
``` | ||
### Starting a container | ||
@@ -84,0 +97,0 @@ |
@@ -211,2 +211,82 @@ 'use strict'; | ||
test('include all files if no .dockerignore file is given.', function (done) { | ||
var name = uuid(); | ||
dockWorker.buildImage({ | ||
directory: path.join(__dirname, 'testBox'), | ||
dockerfile: path.join(__dirname, 'Dockerfile'), | ||
name: name | ||
}, function (errBuildImage) { | ||
assert.that(errBuildImage).is.null(); | ||
dockWorker.startContainer({ | ||
image: name, | ||
name: settings.containerName, | ||
ports: [ | ||
{ container: 7000, host: 7000 } | ||
] | ||
}, function (errStartContainer, id) { | ||
assert.that(errStartContainer).is.null(); | ||
setTimeout(function () { | ||
request.get(url.format({ | ||
protocol: 'http', | ||
hostname: settings.host, | ||
port: 7000, | ||
pathname: '/' | ||
}), function (errGet, res) { | ||
assert.that(errGet).is.null(); | ||
assert.that(res.statusCode).is.equalTo(200); | ||
assert.that(res.body).is.equalTo('to-be-ignored\n'); | ||
childProcess.exec('docker kill ' + id + ' && docker rm -f ' + id, function (err) { | ||
assert.that(err).is.null(); | ||
done(); | ||
}); | ||
}); | ||
}, 1.5 * 1000); | ||
}); | ||
}); | ||
}); | ||
test('excludes files specified in .dockerignore file.', function (done) { | ||
var name = uuid(); | ||
dockWorker.buildImage({ | ||
directory: path.join(__dirname, 'testBox'), | ||
dockerfile: path.join(__dirname, 'Dockerfile'), | ||
dockerignore: path.join(__dirname, '_dockerignore'), | ||
name: name | ||
}, function (errBuildImage) { | ||
assert.that(errBuildImage).is.null(); | ||
dockWorker.startContainer({ | ||
image: name, | ||
name: settings.containerName, | ||
ports: [ | ||
{ container: 7000, host: 7000 } | ||
] | ||
}, function (errStartContainer, id) { | ||
assert.that(errStartContainer).is.null(); | ||
setTimeout(function () { | ||
request.get(url.format({ | ||
protocol: 'http', | ||
hostname: settings.host, | ||
port: 7000, | ||
pathname: '/' | ||
}), function (errGet, res) { | ||
assert.that(errGet).is.null(); | ||
assert.that(res.statusCode).is.equalTo(404); | ||
childProcess.exec('docker kill ' + id + ' && docker rm -f ' + id, function (err) { | ||
assert.that(err).is.null(); | ||
done(); | ||
}); | ||
}); | ||
}, 1.5 * 1000); | ||
}); | ||
}); | ||
}); | ||
test('returns an error if the image can not be built.', function (done) { | ||
@@ -320,5 +400,5 @@ var name = uuid(); | ||
}); | ||
}, 0.5 * 1000); | ||
}, 1.5 * 1000); | ||
}); | ||
}, 0.5 * 1000); | ||
}, 1.5 * 1000); | ||
}); | ||
@@ -363,5 +443,5 @@ }); | ||
}); | ||
}, 0.5 * 1000); | ||
}, 1.5 * 1000); | ||
}); | ||
}, 0.5 * 1000); | ||
}, 1.5 * 1000); | ||
}); | ||
@@ -702,3 +782,3 @@ }); | ||
test('returns an error if the specified container does not exist.', function (done) { | ||
test.skip('returns an error if the specified container does not exist.', function (done) { | ||
dockWorker.getLogs('xxx-crew-test-xxx', function (err) { | ||
@@ -705,0 +785,0 @@ assert.that(err).is.not.null(); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
/*eslint-disable no-process-env*/ | ||
/* eslint-disable no-process-env */ | ||
settings.host = url.parse(process.env.DOCKER_HOST).hostname; | ||
@@ -17,3 +17,3 @@ settings.port = url.parse(process.env.DOCKER_HOST).port; | ||
settings.caCertificate = fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'ca.pem')); | ||
/*eslint-enable no-process-env*/ | ||
/* eslint-enable no-process-env */ | ||
@@ -20,0 +20,0 @@ settings.image = 'thenativeweb/crew-test'; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
/*eslint-disable no-process-env*/ | ||
/* eslint-disable no-process-env */ | ||
http.createServer(function (req, res) { | ||
@@ -23,13 +23,22 @@ res.end(fs.readFileSync('/data1/foo.txt', { encoding: 'utf8' })); | ||
setTimeout(function () { | ||
/*eslint-disable no-process-exit*/ | ||
/* eslint-disable no-process-exit */ | ||
process.exit(1); | ||
/*eslint-enable no-process-exit*/ | ||
/* eslint-enable no-process-exit */ | ||
}, 0.25 * 1000); | ||
}).listen(process.env.PORT4 || 6000); | ||
/*eslint-enable no-process-env*/ | ||
http.createServer(function (req, res) { | ||
try { | ||
res.end(fs.readFileSync('/toBeAdded/toBeIgnored.txt', { encoding: 'utf8' })); | ||
} catch (e) { | ||
res.writeHead(404); | ||
res.end(); | ||
} | ||
}).listen(process.env.PORT5 || 7000); | ||
/* eslint-enable no-process-env */ | ||
setTimeout(function () { | ||
/*eslint-disable no-console*/ | ||
/* eslint-disable no-console */ | ||
console.log('Test container running...'); | ||
/*eslint-enable no-console*/ | ||
/* eslint-enable no-console */ | ||
}, 1 * 1000); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69540
22
1485
286
7
13
+ Addeddel@1.2.0
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedasync@1.5.2(transitive)
+ Addeddel@1.2.0(transitive)
+ Addedeach-async@1.1.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedglobby@2.1.0(transitive)
+ Addedis-path-cwd@1.0.0(transitive)
+ Addedis-path-in-cwd@1.0.1(transitive)
+ Addedis-path-inside@1.0.1(transitive)
+ Addedlodash@3.10.0(transitive)
+ Addedobject-assign@2.1.13.0.0(transitive)
+ Addedonetime@1.1.0(transitive)
+ Addedpath-is-inside@1.0.2(transitive)
+ Addedset-immediate-shim@1.0.1(transitive)
+ Addedtar-fs@1.7.0(transitive)
- Removedlodash@3.9.3(transitive)
- Removedtar-fs@1.6.0(transitive)
Updatedlodash@3.10.0
Updatedtar-fs@1.7.0