Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record feature dependencies in the lockfile #566

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
chrmarti marked this conversation as resolved.
Show resolved Hide resolved
.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