Skip to content

Commit a5966c9

Browse files
committed
Use docker save to extract manifest list platform annotations
1 parent 2c7b7e8 commit a5966c9

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

.github/workflows/dev-containers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Package
8585
run: yarn package
8686
- name: Run Tests
87-
run: yarn test-matrix --forbid-only ${{ matrix.mocha-args }}
87+
run: yarn test-matrix ${{ matrix.mocha-args }}
8888
env:
8989
CI: true
9090

src/spec-node/containerFeatures.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,23 @@ export async function updateRemoteUserUID(params: DockerResolverParameters, merg
466466
const inspectResult = await dockerCLI(params, 'inspect', '--type', 'image', imageName);
467467
const inspectJson = inspectResult.stdout.toString().trim();
468468
output.write(`updateUID: docker inspect ${imageName}: ${inspectJson}`, LogLevel.Info);
469-
// Read the raw manifest list from the containerd content store using the image digest
469+
// Extract the OCI index from docker save to see manifest list platform annotations
470470
try {
471471
const parsed = JSON.parse(inspectJson);
472-
const digest = parsed[0]?.Id || parsed[0]?.Descriptor?.digest;
472+
const digest = parsed[0]?.Descriptor?.digest;
473473
if (digest) {
474-
const hash = digest.replace('sha256:', '');
475-
const blobPath = `/var/lib/docker/containerd/daemon/io.containerd.content.v1.content/blobs/sha256/${hash}`;
476-
const catResult = await runCommandNoPty({ exec: common.cliHost.exec, cmd: 'cat', args: [blobPath], output: nullLog });
477-
output.write(`updateUID: manifest list (${blobPath}): ${catResult.stdout.toString().trim()}`, LogLevel.Info);
474+
const hash = digest.replace('sha256:', '').replace(':', '/');
475+
// docker save outputs OCI layout; extract the manifest list blob by digest
476+
const saveResult = await runCommandNoPty({
477+
exec: common.cliHost.exec,
478+
cmd: '/bin/sh',
479+
args: ['-c', `docker save ${imageName} | tar -xO blobs/sha256/${hash} 2>/dev/null || docker save ${imageName} | tar -xO index.json 2>/dev/null`],
480+
output: nullLog
481+
});
482+
output.write(`updateUID: manifest list for ${imageName}: ${saveResult.stdout.toString().trim()}`, LogLevel.Info);
478483
}
479484
} catch (blobErr) {
480-
output.write(`updateUID: reading manifest list blob failed: ${blobErr instanceof Error ? blobErr.message : JSON.stringify(blobErr)}`, LogLevel.Warning);
485+
output.write(`updateUID: reading manifest list failed: ${blobErr instanceof Error ? blobErr.message : JSON.stringify(blobErr)}`, LogLevel.Warning);
481486
}
482487
} catch (err) {
483488
output.write(`updateUID: docker inspect failed: ${err}`, LogLevel.Warning);

src/test/updateUID.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { devContainerDown, devContainerUp, shellExec } from './testUtils';
99

1010
const pkg = require('../../package.json');
1111

12-
(process.platform === 'linux' ? describe : describe.skip)('Dev Containers CLI', function () {
12+
(process.platform === 'linux' ? describe.only : describe.skip)('Dev Containers CLI', function () {
1313
this.timeout('120s');
1414

1515
const tmp = path.relative(process.cwd(), path.join(__dirname, 'tmp'));

0 commit comments

Comments
 (0)