Skip to content

Commit

Permalink
fix: delete previous log, etc
Browse files Browse the repository at this point in the history
Signed-off-by: Tim deBoer <[email protected]>
  • Loading branch information
deboer-tim committed Jan 10, 2024
1 parent 4efe4eb commit 624efa1
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
// or else it will fail.
// for demo right now, don't bother checking

const logPath = resolve(selectedFolder, selectedType, 'image-build.log');
await fs.unlink(logPath);
// create log folder
const logFolder = resolve(selectedFolder, selectedType);
if (!fs.existsSync(logFolder)) {
await fs.mkdirSync(logFolder);
}
const logPath = resolve(logFolder, 'image-build.log');
if (fs.existsSync(logPath)) {
await fs.unlinkSync(logPath);
}

let logData: string = 'Build Image Log --------\n';
try {
await pullBootcImageBuilderImage();
progress.report({ increment: 4 });
Expand All @@ -87,8 +95,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
const containerId = await createImage(image, selectedType, selectedFolder);
progress.report({ increment: 6 });

let logData: string;
await logContainer(image, containerId, progress, (data) => {logData += data });
await logContainer(image, containerId, progress, (data) => { logData += data;console.log('log:' +logData) });

// Wait for container to exit so that the task doesn't end and we can monitor progress
let containerRunning = true;
Expand All @@ -106,10 +113,15 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
});
await new Promise(r => setTimeout(r, 1000));
}

fs.writeFileSync(logPath, logData, {flag: 'w'});
} catch (error) {
console.error(error);
try {
fs.writeFileSync(logPath, logData, {flag: 'w'});
} catch (e) {
// ignore
}
await extensionApi.window.showErrorMessage(`Unable to build disk image: ${error}. Check logs at ${logPath}`);
}
// Mark the task as completed
Expand Down Expand Up @@ -186,7 +198,7 @@ $IMAGE
SecurityOpt: ['label=type:unconfined_t'],
Binds: [folder + ':/tmp/' + type],
},
Labels,
//Labels,
// Outputs to:
// <type>/disk.<type>
// in the directory provided
Expand Down

0 comments on commit 624efa1

Please sign in to comment.