Skip to content

Commit

Permalink
feat: More targeted pruning (#4)
Browse files Browse the repository at this point in the history
* Add some logging to validate behavior

* More logging

* Additional logging

* Fix logging

* Fix flag name

* More logging

* Fix broken logging

* discard all regular cache layers

* Stop tar complaining about absolute paths

* More logging, more pruning

* Fix incorrect variable name

* Remember to start the buildx builder again

* Clean things up a bit

* Fix flag

* start docker buildx back up so that we can log the cache state

* start docker buildx back up so that we can log the cache state
  • Loading branch information
philomory authored Nov 15, 2022
1 parent 56a1e55 commit 49b4fd4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
6 changes: 5 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ async function run() {
alpine /bin/sh -c "cd / && tar xf /cache/buildkit-state.tar"`);

core.info('Cache restored successfully');

await execAsync('docker buildx inspect --bootstrap');
var {stdout, stderr} = await execAsync(`docker buildx du --verbose`);
core.info(`Cache now contains:\n${stdout}\n`);
} catch (error) {
core.error(`Cache restore failed: ${ error }`)
core.error(`Cache restore failed: ${ error }`);
}
}

Expand Down
61 changes: 48 additions & 13 deletions post.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
const core = require('@actions/core');
const core = require("@actions/core");

const { exec } = require('child_process');
const { promisify } = require('util');
const { exec } = require("child_process");
const { promisify } = require("util");

const execAsync = promisify(exec);

const builder = core.getInput('builder');
const path = core.getInput('cache-path');
const builder = core.getInput("builder");
const path = core.getInput("cache-path");

async function post() {
try {
await execAsync(`docker buildx prune --force --keep-storage ${ core.getInput('cache-max-size')}`)
core.info("Before pruning:");
var {stdout, stderr} = await execAsync(`docker buildx du`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

await execAsync(`docker run --rm \
--volumes-from ${ builder } \
-v ${ path }:/cache \
alpine /bin/sh -c "cd / && tar cf /cache/buildkit-state.tar /var/lib/buildkit"`);
var {stdout, stderr} = await execAsync(`docker buildx prune --force --filter type=regular`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

core.info('Cache archived successfully');
var {stdout, stderr} = await execAsync(`docker buildx prune --force --filter type=source.local`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

var {stdout, stderr} = await execAsync(`docker buildx prune --force --filter type=frontend`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

var {stdout, stderr} = await execAsync(`docker buildx prune --force --filter type=internal`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

var {stdout, stderr} = await execAsync(`docker buildx prune --force --filter type=exec.cachemount --keep-storage ${core.getInput('cache-max-size')}`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

core.info("After pruning:");

var {stdout, stderr} = await execAsync(`docker buildx du`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

var {stdout, stderr} = await execAsync(`docker buildx du --verbose`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

var {stdout, stderr} = await execAsync(`docker run --rm \
--volumes-from ${builder} \
-v ${path}:/cache \
alpine /bin/sh -c "cd / && tar cf /cache/buildkit-state.tar var/lib/buildkit"`);
core.info(`stdout:\n${stdout}\n`);
if (stderr) { core.error(`stderr:\n${stderr}\n`); }

core.info("Cache archived successfully");
} catch (error) {
core.error(`Cache archive failed: ${ error }`);
core.error(`Cache archive failed: ${error}`);
}
}

post()
post();

0 comments on commit 49b4fd4

Please sign in to comment.