Skip to content

Commit

Permalink
Record feature dependencies in the lockfile (devcontainers#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jul 14, 2023
1 parent 87e38d1 commit 3e7ba9a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/spec-configuration/lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ export async function writeLockfile(params: ContainerFeatureInternalParams, conf
const lockfile: Lockfile = featuresConfig.featureSets
.map(f => [f, f.sourceInformation] as const)
.filter((tup): tup is [FeatureSet, OCISourceInformation] => tup[1].type === 'oci')
.map(([set, source]) => ({
id: source.userFeatureId,
version: set.features[0].version!,
resolved: `${source.featureRef.registry}/${source.featureRef.path}@${set.computedDigest}`,
integrity: set.computedDigest!,
}))
.map(([set, source]) => {
const dependsOn = Object.keys(set.features[0].dependsOn || {});
return {
id: source.userFeatureId,
version: set.features[0].version!,
resolved: `${source.featureRef.registry}/${source.featureRef.path}@${set.computedDigest}`,
integrity: set.computedDigest!,
dependsOn: dependsOn.length ? dependsOn : undefined,
};
})
.sort((a, b) => a.id.localeCompare(b.id))
.reduce((acc, cur) => {
const feature = { ...cur };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/codspace/dependson/A:2": {},
"ghcr.io/codspace/dependson/E:1": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"features": {
"ghcr.io/codspace/dependson/A:2": {
"version": "2.0.1",
"resolved": "ghcr.io/codspace/dependson/a@sha256:932027ef71da186210e6ceb3294c3459caaf6b548d2b547d5d26be3fc4b2264a",
"integrity": "sha256:932027ef71da186210e6ceb3294c3459caaf6b548d2b547d5d26be3fc4b2264a",
"dependsOn": [
"ghcr.io/codspace/dependson/E"
]
},
"ghcr.io/codspace/dependson/E": {
"version": "2.0.0",
"resolved": "ghcr.io/codspace/dependson/e@sha256:9f36f159c70f8bebff57f341904b030733adb17ef12a5d58d4b3d89b2a6c7d5a",
"integrity": "sha256:9f36f159c70f8bebff57f341904b030733adb17ef12a5d58d4b3d89b2a6c7d5a"
},
"ghcr.io/codspace/dependson/E:1": {
"version": "1.0.0",
"resolved": "ghcr.io/codspace/dependson/e@sha256:90b84127edab28ecb169cd6c6f2101ce0ea1d77589cee01951fec7f879f3a11c",
"integrity": "sha256:90b84127edab28ecb169cd6c6f2101ce0ea1d77589cee01951fec7f879f3a11c"
}
}
}
14 changes: 14 additions & 0 deletions src/test/container-features/lockfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ describe('Lockfile', function () {
assert.equal(actual.toString(), expected.toString());
});

it('lockfile with dependencies', async () => {
const workspaceFolder = path.join(__dirname, 'configs/lockfile-dependson');

const lockfilePath = path.join(workspaceFolder, '.devcontainer-lock.json');
await rmLocal(lockfilePath, { force: true });

const res = await shellExec(`${cli} build --workspace-folder ${workspaceFolder} --experimental-lockfile`);
const response = JSON.parse(res.stdout);
assert.equal(response.outcome, 'success');
const actual = await readLocalFile(lockfilePath);
const expected = await readLocalFile(path.join(workspaceFolder, 'expected.devcontainer-lock.json'));
assert.equal(actual.toString(), expected.toString());
});

it('frozen lockfile', async () => {
const workspaceFolder = path.join(__dirname, 'configs/lockfile-frozen');
const lockfilePath = path.join(workspaceFolder, '.devcontainer-lock.json');
Expand Down

0 comments on commit 3e7ba9a

Please sign in to comment.