Comparing version 0.7.7 to 0.8.0
@@ -103,15 +103,11 @@ 'use strict'; | ||
} | ||
if (!options.directory) { | ||
throw new Error('Directory is missing.'); | ||
} | ||
if (!options.dockerfile) { | ||
throw new Error('Dockerfile is missing.'); | ||
} | ||
if (!options.name) { | ||
throw new Error('Name is missing.'); | ||
} | ||
if (!callback) { | ||
@@ -121,3 +117,10 @@ throw new Error('Callback is missing.'); | ||
isolated(options.directory, function (errIsolated, tempDirectory) { | ||
options.preBuild = options.preBuild || function (preBuildOptions, done) { | ||
done(null); | ||
}; | ||
isolated({ | ||
files: options.directory, | ||
preserveTimestamps: false | ||
}, function (errIsolated, tempDirectory) { | ||
var tarFile, | ||
@@ -164,43 +167,51 @@ tarFileName, | ||
tarStream = tar.pack(tempAppDirectory); | ||
tarStream.once('error', function (errTarStream) { | ||
callback(errTarStream); | ||
options.preBuild({ | ||
directory: tempAppDirectory | ||
}, function (errPreBuild) { | ||
if (errPreBuild) { | ||
return callback(errPreBuild); | ||
} | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
}); | ||
tarStream = tar.pack(tempAppDirectory); | ||
tarStream.once('error', function (errTarStream) { | ||
callback(errTarStream); | ||
tarFile = fs.createWriteStream(tarFileName); | ||
tarFile.once('finish', function () { | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
}); | ||
that.server.buildImage(tarFileName, { t: options.name }, function (errBuildImage, res) { | ||
var hadErrors = false; | ||
tarFile = fs.createWriteStream(tarFileName); | ||
tarFile.once('finish', function () { | ||
tarStream.removeAllListeners(); | ||
tarFile.removeAllListeners(); | ||
if (errBuildImage) { | ||
return callback(errBuildImage); | ||
} | ||
that.server.buildImage(tarFileName, { t: options.name }, function (errBuildImage, res) { | ||
var hadErrors = false; | ||
res.on('data', function (data) { | ||
var status = JSON.parse(data.toString('utf8')); | ||
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); | ||
}); | ||
@@ -207,0 +218,0 @@ }); |
{ | ||
"name": "crew", | ||
"version": "0.7.7", | ||
"version": "0.8.0", | ||
"description": "crew makes managing Docker a breeze.", | ||
@@ -20,3 +20,3 @@ "contributors": [ | ||
"fs-extra": "0.22.1", | ||
"isolated": "0.2.1", | ||
"isolated": "0.3.0", | ||
"lodash": "3.10.0", | ||
@@ -30,3 +30,3 @@ "q": "1.4.1", | ||
"knockat": "0.2.1", | ||
"request": "2.58.0", | ||
"request": "2.59.0", | ||
"tourism": "0.20.2", | ||
@@ -33,0 +33,0 @@ "uuidv4": "0.3.1" |
@@ -97,2 +97,23 @@ # crew | ||
If you want to modify the build context right before the image gets built, register a `preBuild` hook and do whatever you want to do. | ||
```javascript | ||
dockWorker.buildImage({ | ||
directory: __dirname, | ||
dockerfile: path.join(__dirname, 'my-dockerfile'), | ||
dockerignore: path.join(__dirname, 'my-dockerignore'), | ||
preBuild: function (preBuildOptions, done) { | ||
console.log(preBuildOptions); | ||
// => { | ||
// directory: '...' | ||
// } | ||
done(null); | ||
}, | ||
name: 'myImage' | ||
}, function (err) { | ||
// ... | ||
}); | ||
``` | ||
### Starting a container | ||
@@ -99,0 +120,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var assert = require('assertthat'), | ||
fs = require('fs-extra'), | ||
knock = require('knockat'), | ||
@@ -305,2 +306,50 @@ request = require('request'), | ||
test('runs the preBuild hook before building the image.', function (done) { | ||
var name = uuid(); | ||
dockWorker.buildImage({ | ||
directory: path.join(__dirname, 'testBox'), | ||
dockerfile: path.join(__dirname, 'Dockerfile'), | ||
dockerignore: path.join(__dirname, '_dockerignore'), | ||
name: name, | ||
preBuild: function (preBuildOptions, callback) { | ||
fs.copy( | ||
path.join(__dirname, 'testBox', 'toBeAdded', 'toBeIgnored.txt'), | ||
path.join(preBuildOptions.directory, 'toBeAdded', 'toBeIgnored.txt'), | ||
callback | ||
); | ||
} | ||
}, 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('returns an error if the image can not be built.', function (done) { | ||
@@ -307,0 +356,0 @@ var name = uuid(); |
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
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
72990
1559
309
14
+ Addedasync@1.4.0(transitive)
+ Addedisolated@0.3.0(transitive)
- Removedasync@1.3.0(transitive)
- Removedisolated@0.2.1(transitive)
Updatedisolated@0.3.0