Use the uploaded app source tarball to build a local docker image
This commit is contained in:
@@ -5,6 +5,7 @@ exports = module.exports = {
|
||||
|
||||
info,
|
||||
df,
|
||||
buildImage,
|
||||
downloadImage,
|
||||
createContainer,
|
||||
startContainer,
|
||||
@@ -159,6 +160,52 @@ async function pullImage(imageRef) {
|
||||
});
|
||||
}
|
||||
|
||||
async function buildImage(manifest) {
|
||||
assert.strictEqual(typeof manifest, 'object');
|
||||
|
||||
const sourceArchivePath = manifest.dockerImage.slice('file:'.length);
|
||||
const imageTag = `local/${manifest.id}:${manifest.version}`;
|
||||
|
||||
debug(`buildImage: building ${imageTag} from ${sourceArchivePath}`);
|
||||
|
||||
const tarStream = fs.createReadStream(sourceArchivePath);
|
||||
const [error, stream] = await safe(gConnection.buildImage(tarStream, { t: imageTag }));
|
||||
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Unable to build image from ${sourceArchivePath}: ${error.message}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let buildError = null;
|
||||
|
||||
stream.on('data', (chunk) => {
|
||||
const data = safe.JSON.parse(chunk) || {};
|
||||
|
||||
if (data.error) {
|
||||
buildError = data.errorDetail || { message: data.error };
|
||||
} else {
|
||||
const message = (data.stream || data.status || data.aux?.ID || '').replace(/\n$/, '');
|
||||
if (message) debug('buildImage: ' + message);
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
if (buildError) {
|
||||
debug(`buildImage: error ${buildError}`);
|
||||
return reject(new BoxError(buildError.message.includes('no space') ? BoxError.FS_ERROR : BoxError.DOCKER_ERROR, buildError.message));
|
||||
} else {
|
||||
debug(`buildImage: success ${imageTag}`);
|
||||
}
|
||||
|
||||
// TODO we should probably use that scheme directly instead of file:....
|
||||
manifest.dockerImage = imageTag;
|
||||
resolve();
|
||||
});
|
||||
|
||||
stream.on('error', (error) => {
|
||||
debug(`buildImage: error building image ${imageTag}: %o`, error);
|
||||
reject(new BoxError(BoxError.DOCKER_ERROR, error.message));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadImage(manifest) {
|
||||
assert.strictEqual(typeof manifest, 'object');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user