Skip to content
Open
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: 16 additions & 0 deletions src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ export function parseMount(str: string): Mount {
.reduce((acc, [key, value]) => ({ ...acc, [(normalizedMountKeys[key] || key)]: value }), {}) as Mount;
}

const mountArgRegex = /^type=(bind|volume),source=([^,]+),target=([^,]+)(?:,external=(true|false))?$/;

export function parseMountArg(str: string): Mount | string {
const match = mountArgRegex.exec(str);
if (!match) {
return str;
}
const [, type, source, target, external] = match;
return {
type: type as Mount['type'],
source,
target,
external: external === 'true',
};
}

export type SourceInformation = GithubSourceInformation | DirectTarballSourceInformation | FilePathSourceInformation | OCISourceInformation;

interface BaseSourceInformation {
Expand Down
2 changes: 1 addition & 1 deletion src/spec-node/devContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface ProvisionOptions {
skipNonBlocking: boolean;
prebuild: boolean;
persistedFolder: string | undefined;
additionalMounts: Mount[];
additionalMounts: (Mount | string)[];
updateRemoteUserUIDDefault: UpdateRemoteUserUIDDefault;
remoteEnv: Record<string, string>;
additionalCacheFroms: string[];
Expand Down
20 changes: 3 additions & 17 deletions src/spec-node/devContainersSpecCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { readDevContainerConfigFile } from './configContainer';
import { getDefaultDevContainerConfigPath, getDevContainerConfigPathIn, uriToFsPath } from '../spec-configuration/configurationCommonUtils';
import { CLIHost, getCLIHost } from '../spec-common/cliHost';
import { loadNativeModule, processSignals } from '../spec-common/commonUtils';
import { loadVersionInfo } from '../spec-configuration/containerFeaturesConfiguration';
import { loadVersionInfo, parseMountArg } from '../spec-configuration/containerFeaturesConfiguration';
import { featuresTestOptions, featuresTestHandler } from './featuresCLI/test';
import { featuresPackageHandler, featuresPackageOptions } from './featuresCLI/package';
import { featuresPublishHandler, featuresPublishOptions } from './featuresCLI/publish';
Expand All @@ -50,8 +50,6 @@ import { parseCrossOriginAuthHosts } from '../spec-configuration/httpOCIRegistry

const defaultDefaultUserEnvProbe: UserEnvProbe = 'loginInteractiveShell';

const mountRegex = /^type=(bind|volume),source=([^,]+),target=([^,]+)(?:,external=(true|false))?$/;

(async () => {

const packageFolder = path.join(__dirname, '..', '..');
Expand Down Expand Up @@ -157,7 +155,7 @@ function provisionOptions(y: Argv) {
'skip-non-blocking-commands': { type: 'boolean', default: false, description: 'Stop running user commands after running the command configured with waitFor or the updateContentCommand by default.' },
prebuild: { type: 'boolean', default: false, description: 'Stop after onCreateCommand and updateContentCommand, rerunning updateContentCommand if it has run before.' },
'user-data-folder': { type: 'string', description: 'Host path to a directory that is intended to be persisted and share state between sessions.' },
'mount': { type: 'string', description: 'Additional mount point(s). Format: type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>]' },
'mount': { type: 'string', description: 'Additional mount point(s). Format: type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>]. Any other value is passed as is to the --mount option of the container runtime (not supported with Docker Compose configurations).' },
'remote-env': { type: 'string', description: 'Remote environment variables of the format name=value. These will be added when executing the user commands.' },
'cache-from': { type: 'string', description: 'Additional image to use as potential layer cache during image building' },
'cache-to': { type: 'string', description: 'Additional image to use as potential layer cache during image building' },
Expand Down Expand Up @@ -188,10 +186,6 @@ function provisionOptions(y: Argv) {
if (!argv['workspace-folder'] && !argv['id-label'] && !argv['override-config']) {
argv['workspace-folder'] = process.cwd();
}
const mounts = (argv.mount && (Array.isArray(argv.mount) ? argv.mount : [argv.mount])) as string[] | undefined;
if (mounts?.some(mount => !mountRegex.test(mount))) {
throw new Error('Unmatched argument format: mount must match type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>]');
}
const remoteEnvs = (argv['remote-env'] && (Array.isArray(argv['remote-env']) ? argv['remote-env'] : [argv['remote-env']])) as string[] | undefined;
if (remoteEnvs?.some(remoteEnv => !/.+=.*/.test(remoteEnv))) {
throw new Error('Unmatched argument format: remote-env must match <name>=<value>');
Expand Down Expand Up @@ -305,15 +299,7 @@ async function provision({
skipNonBlocking,
prebuild,
persistedFolder,
additionalMounts: mount ? (Array.isArray(mount) ? mount : [mount]).map(mount => {
const [, type, source, target, external] = mountRegex.exec(mount)!;
return {
type: type as 'bind' | 'volume',
source,
target,
external: external === 'true'
};
}) : [],
additionalMounts: mount ? (Array.isArray(mount) ? mount : [mount]).map(parseMountArg) : [],
dotfiles: {
repository: dotfilesRepository,
installCommand: dotfilesInstallCommand,
Expand Down
8 changes: 6 additions & 2 deletions src/spec-node/dockerCompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ async function writeFeaturesComposeOverrideFile(
imageDetails: () => Promise<ImageDetails>,
service: any,
additionalLabels: string[],
additionalMounts: Mount[],
additionalMounts: (Mount | string)[],
overrideFilePath: string,
overrideFilePrefix: string,
buildCLIHost: CLIHost,
Expand Down Expand Up @@ -510,7 +510,7 @@ async function generateFeaturesComposeOverrideContent(
imageDetails: () => Promise<ImageDetails>,
service: any,
additionalLabels: string[],
additionalMounts: Mount[],
additionalMounts: (Mount | string)[],
params: DockerResolverParameters,
) {
const overrideImage = updatedImageName !== originalImageName;
Expand All @@ -519,6 +519,10 @@ async function generateFeaturesComposeOverrideContent(
const env = mergedConfig.containerEnv || {};
const capAdd = mergedConfig.capAdd || [];
const securityOpts = mergedConfig.securityOpt || [];
const unsupportedMount = additionalMounts.find(m => typeof m === 'string');
if (unsupportedMount) {
throw new ContainerError({ description: `--mount "${unsupportedMount}" is not supported with Docker Compose configurations. Use type=<bind|volume>,source=<source>,target=<target>[,external=<true|false>].` });
}
const mounts = [
...mergedConfig.mounts || [],
...additionalMounts,
Expand Down
2 changes: 1 addition & 1 deletion src/spec-node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export interface DockerResolverParameters {
buildNoCache?: boolean;
expectExistingContainer?: boolean;
userRepositoryConfigurationPaths: string[];
additionalMounts: Mount[];
additionalMounts: (Mount | string)[];
updateRemoteUserUIDDefault: UpdateRemoteUserUIDDefault;
additionalCacheFroms: string[];
buildKitVersion: { versionString: string; versionMatch?: string } | undefined;
Expand Down
19 changes: 19 additions & 0 deletions src/test/mountArg.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assert } from 'chai';
import { parseMountArg } from '../spec-configuration/containerFeaturesConfiguration';

describe('parseMountArg', () => {

it('parses the bind/volume form into a mount object', () => {
assert.deepEqual(parseMountArg('type=volume,source=cache,target=/cache,external=true'), {
type: 'volume',
source: 'cache',
target: '/cache',
external: true,
});
});

it('passes any other mount through to the container runtime unchanged', () => {
const mount = 'type=image,source=localhost/devtools:latest,target=/nix,subpath=/nix';
assert.strictEqual(parseMountArg(mount), mount);
});
});