use local/id:version-ts as docker image tag for locally built apps
This commit is contained in:
+1
-1
@@ -226,7 +226,7 @@ async function downloadImage(manifest) {
|
||||
|
||||
if (diskUsage.available < (1024*1024*1024)) throw new BoxError(BoxError.DOCKER_ERROR, `Not enough disk space to pull docker image. available: ${diskUsage.available}`);
|
||||
|
||||
if (manifest.dockerImage.indexOf('file:') === 0) {
|
||||
if (manifest.dockerImage.indexOf('local/') === 0) {
|
||||
await docker.buildImage(manifest);
|
||||
} else {
|
||||
await docker.downloadImage(manifest);
|
||||
|
||||
+5
-8
@@ -163,13 +163,12 @@ 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}`;
|
||||
const sourceArchivePath = '/tmp/' + manifest.dockerImage.slice('local/'.length);
|
||||
|
||||
debug(`buildImage: building ${imageTag} from ${sourceArchivePath}`);
|
||||
debug(`buildImage: building ${manifest.dockerImage} from ${sourceArchivePath}`);
|
||||
|
||||
const tarStream = fs.createReadStream(sourceArchivePath);
|
||||
const [error, stream] = await safe(gConnection.buildImage(tarStream, { t: imageTag }));
|
||||
const [error, stream] = await safe(gConnection.buildImage(tarStream, { t: manifest.dockerImage }));
|
||||
if (error) throw new BoxError(BoxError.DOCKER_ERROR, `Unable to build image from ${sourceArchivePath}: ${error.message}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -191,16 +190,14 @@ async function buildImage(manifest) {
|
||||
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}`);
|
||||
debug(`buildImage: success ${manifest.dockerImage}`);
|
||||
}
|
||||
|
||||
// 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);
|
||||
debug(`buildImage: error building image ${manifest.dockerImage}: %o`, error);
|
||||
reject(new BoxError(BoxError.DOCKER_ERROR, error.message));
|
||||
});
|
||||
});
|
||||
|
||||
+5
-1
@@ -207,7 +207,11 @@ async function install(req, res, next) {
|
||||
data.manifest = result.manifest;
|
||||
|
||||
// if we have a source archive upload, craft a custom docker image URI for later
|
||||
if (req.files.sourceArchive?.path) data.manifest.dockerImage = 'file:' + req.files.sourceArchive.path;
|
||||
if (req.files.sourceArchive?.path) {
|
||||
const newFileName = `${data.manifest.id}:${data.manifest.version}-${Date.now()}`;
|
||||
if (!safe.fs.renameSync(req.files.sourceArchive?.path, `/tmp/${newFileName}`)) return next(new HttpError(500, 'unable to move source archive'));
|
||||
data.manifest.dockerImage = `local/${newFileName}`;
|
||||
}
|
||||
|
||||
[error, result] = await safe(apps.install(data, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
Reference in New Issue
Block a user