Skip to content

Commit

Permalink
Scaffold Dockerfile next to project file for .NET (microsoft#1502)
Browse files Browse the repository at this point in the history
* Sketch switch to scaffolder.

* Sketch moving .NET Core configuration to scaffolder.

* Fixup relative paths.

* Scaffold Dockerfile to the project directory.

* Add back telemetry capture of prompts.

* Capture project prompt cancellation step.

* Fixup .NET telemetry properties.

* Consolidate dockerignore generation.

* Add copyright text.

* Fixup tests.

* Prevent tests from generating debug tasks.

* Fixup test telemetry.

* Fixup tests.

* More merge from master.

* Updates per PR feedback.

* Some comments per PR feedback.
  • Loading branch information
philliphoff authored Jan 9, 2020
1 parent 7975729 commit 1ef900a
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 246 deletions.
2 changes: 1 addition & 1 deletion extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export { activateInternal } from './src/extension';
//
// The tests should import '../extension.bundle.ts'. At design-time they live in tests/ and so will pick up this file (extension.bundle.ts).
// At runtime the tests live in dist/tests and will therefore pick up the main webpack bundle at dist/extension.bundle.js.
export { configure, ConfigureApiOptions, ConfigureTelemetryProperties } from './src/configureWorkspace/configure';
export { configure, ConfigureApiOptions } from './src/configureWorkspace/configure';
export { configPrefix } from './src/constants';
export { ProcessProvider } from './src/debugging/coreclr/ChildProcessProvider';
export { DockerBuildImageOptions, DockerClient } from './src/debugging/coreclr/CliDockerClient';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/containers/browseContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type BrowseTelemetryProperties = TelemetryProperties & { possiblePorts?: number[
type ConfigureBrowseCancelStep = 'node' | 'port';

async function captureBrowseCancelStep<T>(cancelStep: ConfigureBrowseCancelStep, properties: BrowseTelemetryProperties, prompt: () => Promise<T>): Promise<T> {
return await captureCancelStep(cancelStep, properties, prompt)
return await captureCancelStep(cancelStep, properties, prompt)();
}

// NOTE: These ports are ordered in order of preference.
Expand Down
57 changes: 56 additions & 1 deletion src/configureWorkspace/configUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as path from 'path';
import vscode = require('vscode');
import { IAzureQuickPickItem } from 'vscode-azureextensionui';
import { IAzureQuickPickItem, TelemetryProperties } from 'vscode-azureextensionui';
import { DockerOrchestration } from '../constants';
import { ext } from "../extensionVariables";
import { captureCancelStep } from '../utils/captureCancelStep';
import { Platform, PlatformOS } from '../utils/platform';

export type ConfigureTelemetryProperties = {
configurePlatform?: Platform;
configureOs?: PlatformOS;
orchestration?: DockerOrchestration;
packageFileType?: string; // 'build.gradle', 'pom.xml', 'package.json', '.csproj', '.fsproj'
packageFileSubfolderDepth?: string; // 0 = project/etc file in root folder, 1 = in subfolder, 2 = in subfolder of subfolder, etc.
};

export type ConfigureTelemetryCancelStep = 'folder' | 'platform' | 'os' | 'compose' | 'port' | 'project';

export async function captureConfigureCancelStep<TReturn, TPrompt extends (...args: []) => Promise<TReturn>>(cancelStep: ConfigureTelemetryCancelStep, properties: TelemetryProperties, prompt: TPrompt): Promise<TReturn> {
return await captureCancelStep(cancelStep, properties, prompt)();
}

/**
* Prompts for port numbers
* @throws `UserCancelledError` if the user cancels.
Expand Down Expand Up @@ -110,3 +127,41 @@ export async function quickPickGenerateComposeFiles(): Promise<boolean> {

return response.data;
}

export function getSubfolderDepth(outputFolder: string, filePath: string): string {
let relativeToRoot = path.relative(outputFolder, path.resolve(outputFolder, filePath));
let matches = relativeToRoot.match(/[\/\\]/g);
let depth: number = matches ? matches.length : 0;
return String(depth);
}

export function genCommonDockerIgnoreFile(platformType: Platform): string {
const ignoredItems = [
'**/.classpath',
'**/.dockerignore',
'**/.env',
'**/.git',
'**/.gitignore',
'**/.project',
'**/.settings',
'**/.toolstarget',
'**/.vs',
'**/.vscode',
'**/*.*proj.user',
'**/*.dbmdl',
'**/*.jfm',
'**/azds.yaml',
platformType !== 'Node.js' ? '**/bin' : undefined,
'**/charts',
'**/docker-compose*',
'**/Dockerfile*',
'**/node_modules',
'**/npm-debug.log',
'**/obj',
'**/secrets.dev.yaml',
'**/values.dev.yaml',
'README.md'
];

return ignoredItems.filter(item => item !== undefined).join('\n');
}
Loading

0 comments on commit 1ef900a

Please sign in to comment.