Skip to content

Commit

Permalink
Add --cache-to option without Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
yokonao committed Jul 21, 2023
1 parent 29a8ed1 commit 4cb96b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/spec-node/containerFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export async function extendImage(params: DockerResolverParameters, config: Subs
args.push('--load'); // (short for --output=docker, i.e. load into normal 'docker images' collection)
}
}
if (params.buildxCacheTo) {
args.push('--cache-to', params.buildxCacheTo);
}

for (const buildContext in featureBuildInfo.buildKitContexts) {
args.push('--build-context', `${buildContext}=${featureBuildInfo.buildKitContexts[buildContext]}`);
Expand Down Expand Up @@ -472,4 +475,4 @@ export async function updateRemoteUserUID(params: DockerResolverParameters, merg
await dockerCLI(params, ...args);
}
return fixedImageName;
}
}
19 changes: 18 additions & 1 deletion src/test/cli.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('Dev Containers CLI', function () {
try {
await shellExec(`docker buildx create --name ${builderName} --driver docker-container --use`);

const testFolder = `${__dirname}/configs/dockerfile-with-target`;
const testFolder = `${__dirname}/configs/dockerfile-without-features`;
const outputPath = `${os.tmpdir()}/test-build-cache`;
const res = await shellExec(`${cli} build --workspace-folder ${testFolder} --log-level trace --cache-to=type=local,dest=${outputPath}`);
console.log(res.stdout);
Expand All @@ -226,6 +226,23 @@ describe('Dev Containers CLI', function () {
}
});

it(`should execute successfully and export buildx cache with container builder and image`, async () => {
const builderName = 'test-container-builder-image';
try {
await shellExec(`docker buildx create --name ${builderName} --driver docker-container --use`);

const testFolder = `${__dirname}/configs/image`;
const outputPath = `${os.tmpdir()}/test-build-cache-image`;
const res = await shellExec(`${cli} build --workspace-folder ${testFolder} --log-level trace --cache-to=type=local,dest=${outputPath}`);
console.log(res.stdout);
const response = JSON.parse(res.stdout);
assert.equal(response.outcome, 'success');
assert.equal(fs.existsSync(`${outputPath}/index.json`), true);
} finally {
await shellExec(`docker buildx rm ${builderName}`);
}
});

it('should fail with docker-compose and --cache-to not supported', async () => {
let success = false;
const testFolder = `${__dirname}/configs/compose-image-with-features`;
Expand Down

0 comments on commit 4cb96b7

Please sign in to comment.