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

Updates "outdated" command to display stale image versions #768

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions .github/workflows/dev-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
"src/test/cli.test.ts",
"src/test/cli.up.test.ts",
"src/test/imageMetadata.test.ts",
"src/test/cli.outdated.test.ts",
"src/test/container-features/containerFeaturesOCIPush.test.ts",
# Run all except the above:
"--exclude src/test/container-features/containerFeaturesOrder.test.ts --exclude src/test/container-features/registryCompatibilityOCI.test.ts --exclude src/test/container-features/containerFeaturesOCIPush.test.ts --exclude src/test/container-features/e2e.test.ts --exclude src/test/container-features/featuresCLICommands.test.ts --exclude src/test/cli.build.test.ts --exclude src/test/cli.exec.buildKit.1.test.ts --exclude src/test/cli.exec.buildKit.2.test.ts --exclude src/test/cli.exec.nonBuildKit.1.test.ts --exclude src/test/cli.exec.nonBuildKit.2.test.ts --exclude src/test/cli.test.ts --exclude src/test/cli.up.test.ts --exclude src/test/imageMetadata.test.ts 'src/test/**/*.test.ts'",
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
81 changes: 3 additions & 78 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import * as path from 'path';
import * as URL from 'url';
import * as tar from 'tar';
import * as crypto from 'crypto';
import * as semver from 'semver';
import * as os from 'os';

import { DevContainerConfig, DevContainerFeature, VSCodeCustomizations } from './configuration';
import { mkdirpLocal, readLocalFile, rmLocal, writeLocalFile, cpDirectoryLocal, isLocalFile } from '../spec-utils/pfs';
import { Log, LogLevel, nullLog } from '../spec-utils/log';
import { Log, LogLevel } from '../spec-utils/log';
import { request } from '../spec-utils/httpRequest';
import { fetchOCIFeature, tryGetOCIFeatureSet, fetchOCIFeatureManifestIfExistsFromUserIdentifier } from './containerFeaturesOCI';
import { uriToFsPath } from './configurationCommonUtils';
import { CommonParams, ManifestContainer, OCIManifest, OCIRef, getRef, getVersionsStrictSorted } from './containerCollectionsOCI';
import { CommonParams, OCIManifest, OCIRef } from './containerCollectionsOCI';
import { Lockfile, generateLockfile, readLockfile, writeLockfile } from './lockfile';
import { computeDependsOnInstallationOrder } from './containerFeaturesOrder';
import { logFeatureAdvisories } from './featureAdvisories';
Expand Down Expand Up @@ -511,79 +509,6 @@ export async function generateFeaturesConfig(params: ContainerFeatureInternalPar
return featuresConfig;
}

export async function loadVersionInfo(params: ContainerFeatureInternalParams, config: DevContainerConfig) {
const userFeatures = userFeaturesToArray(config);
if (!userFeatures) {
return { features: {} };
}

const { lockfile } = await readLockfile(config);

const resolved: Record<string, any> = {};

await Promise.all(userFeatures.map(async userFeature => {
const userFeatureId = userFeature.userFeatureId;
const featureRef = getRef(nullLog, userFeatureId); // Filters out Feature identifiers that cannot be versioned (e.g. local paths, deprecated, etc..)
if (featureRef) {
const versions = (await getVersionsStrictSorted(params, featureRef))
?.reverse();
if (versions) {
const lockfileVersion = lockfile?.features[userFeatureId]?.version;
let wanted = lockfileVersion;
const tag = featureRef.tag;
if (tag) {
if (tag === 'latest') {
wanted = versions[0];
} else {
wanted = versions.find(version => semver.satisfies(version, tag));
}
} else if (featureRef.digest && !wanted) {
const { type, manifest } = await getFeatureIdType(params, userFeatureId, undefined);
if (type === 'oci' && manifest) {
const wantedFeature = await findOCIFeatureMetadata(params, manifest);
wanted = wantedFeature?.version;
}
}
resolved[userFeatureId] = {
current: lockfileVersion || wanted,
wanted,
wantedMajor: wanted && semver.major(wanted)?.toString(),
latest: versions[0],
latestMajor: semver.major(versions[0])?.toString(),
};
}
}
}));

// Reorder Features to match the order in which they were specified in config
return {
features: userFeatures.reduce((acc, userFeature) => {
const r = resolved[userFeature.userFeatureId];
if (r) {
acc[userFeature.userFeatureId] = r;
}
return acc;
}, {} as Record<string, any>)
};
}

async function findOCIFeatureMetadata(params: ContainerFeatureInternalParams, manifest: ManifestContainer) {
const annotation = manifest.manifestObj.annotations?.['dev.containers.metadata'];
if (annotation) {
return jsonc.parse(annotation) as Feature;
}

// Backwards compatibility.
const featureSet = tryGetOCIFeatureSet(params.output, manifest.canonicalId, {}, manifest, manifest.canonicalId);
if (!featureSet) {
return undefined;
}

const tmp = path.join(os.tmpdir(), crypto.randomUUID());
const f = await fetchOCIFeature(params, featureSet, tmp, tmp, DEVCONTAINER_FEATURE_FILE_NAME);
return f.metadata as Feature | undefined;
}

async function prepareOCICache(dstFolder: string) {
const ociCacheDir = path.join(dstFolder, 'ociCache');
await mkdirpLocal(ociCacheDir);
Expand Down Expand Up @@ -1115,7 +1040,7 @@ export async function fetchContentsAtTarballUri(params: { output: Log; env: Node

// No 'metadataFile' to look for.
if (!metadataFile) {
await cleanupIterationFetchAndMerge(tempTarballPath, output);
await cleanupIterationFetchAndMerge(tempTarballPath, output);
return { computedDigest, metadata: undefined };
}

Expand Down
3 changes: 3 additions & 0 deletions src/spec-configuration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
},
{
"path": "../spec-utils"
},
{
"path": "../spec-shutdown"
}
]
}
22 changes: 22 additions & 0 deletions src/spec-node/collectionCommonUtils/outdated.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Argv } from 'yargs';
import { UnpackArgv } from '../devContainersSpecCLI';
import { outdated } from './outdatedCommandImpl';

export function outdatedOptions(y: Argv) {
return y.options({
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
'workspace-folder': { type: 'string', required: true, description: 'Workspace folder path. The devcontainer.json will be looked up relative to this path.' },
'config': { type: 'string', description: 'devcontainer.json path. The default is to use .devcontainer/devcontainer.json or, if that does not exist, .devcontainer.json in the workspace folder.' },
'output-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text', description: 'Output format.' },
'log-level': { choices: ['info' as 'info', 'debug' as 'debug', 'trace' as 'trace'], default: 'info' as 'info', description: 'Log level for the --terminal-log-file. When set to trace, the log level for --log-file will also be set to trace.' },
'log-format': { choices: ['text' as 'text', 'json' as 'json'], default: 'text' as 'text', description: 'Log format.' },
'terminal-columns': { type: 'number', implies: ['terminal-rows'], description: 'Number of columns to render the output for. This is required for some of the subprocesses to correctly render their output.' },
'terminal-rows': { type: 'number', implies: ['terminal-columns'], description: 'Number of rows to render the output for. This is required for some of the subprocesses to correctly render their output.' },
});
}

export type OutdatedArgs = UnpackArgv<ReturnType<typeof outdatedOptions>>;

export function outdatedHandler(args: OutdatedArgs) {
(async () => outdated(args))().catch(console.error);
}
Loading
Loading