Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #242 from gregarndt/improve_image_loading
Browse files Browse the repository at this point in the history
Attempt to remove files once they are no longer needed
  • Loading branch information
gregarndt committed Aug 23, 2016
2 parents 174b4ba + 65282e7 commit 3f068ff
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lib/docker/artifact_image.js
Expand Up @@ -78,21 +78,38 @@ export default class ArtifactImage {
this.runtime.dockerConfig
);
this.runtime.monitor.measure('task.taskImage.downloadTime', Date.now() - start);

await this.renameAndLoad(this.imageName, originalTarball);

} catch(e) {
await removeDir(downloadDir);
debug(`Error loading docker image. ${e.stack}`);
try {
await removeDir(downloadDir);
} catch(e) {
debug(`Error removing download dir. ${e.stack}`);
}
throw new Error(`Error loading docker image. ${e.message}`);
}

await this.renameAndLoad(this.imageName, originalTarball);
this.runtime.monitor.measure('task.taskImage.loadTime', Date.now() - start);
try {
await removeDir(downloadDir);
} catch(e) {
debug(`Error removing download dir. ${e.stack}`);
}
}

async renameAndLoad(imageName, originalTarball) {
this.stream.write(fmtLog('Loading docker image from downloaded archive.'));
debug('Renaming image and creating new archive');
let newTarball = await this.renameImageInTarball(imageName, originalTarball);

try {
await fs.unlink(originalTarball);
} catch(e) {
debug(`Error when attempting to remove downloaded image. ${e.stack}`);
}

debug('Loading docker image');
let readStream = fs.createReadStream(newTarball);
await this.runtime.docker.loadImage(readStream);
Expand All @@ -108,13 +125,6 @@ export default class ArtifactImage {
await sleep(5000);
}

try {
await removeDir(path.dirname(originalTarball));
} catch(e) {
debug(`Error removing temporary task image directory. ` +
`Path: ${path.dirname(originalTarball)}. Error: ${e.message}`);
}

if (!pulledImage) {
throw new Error('Image did not load properly.');
}
Expand Down Expand Up @@ -210,6 +220,13 @@ export default class ArtifactImage {
pack.on('error', reject);
});

try {
await removeDir(extractedPath);
} catch(e) {
debug(`Error removing temporary task image directory. ` +
`Path: ${extractedPath}. Error: ${e.message}`);
}

return editedTarballPath;
}
}

0 comments on commit 3f068ff

Please sign in to comment.