diff --git a/src/commands/image/imageSource/buildImageInAzure/BuildFromProjectListStep.ts b/src/commands/image/imageSource/buildImageInAzure/BuildFromProjectListStep.ts index a966ee3c4..3992ad334 100644 --- a/src/commands/image/imageSource/buildImageInAzure/BuildFromProjectListStep.ts +++ b/src/commands/image/imageSource/buildImageInAzure/BuildFromProjectListStep.ts @@ -14,6 +14,7 @@ import { ImageNameStep } from "./ImageNameStep"; import { OSPickStep } from "./OSPickStep"; import { RootFolderStep } from "./RootFolderStep"; import { RunStep } from "./RunStep"; +import { SourcePathStep } from "./SourcePathStep"; import { TarFileStep } from "./TarFileStep"; import { UploadSourceCodeStep } from "./UploadSourceCodeStep"; @@ -49,7 +50,7 @@ export class BuildFromProjectListStep extends AzureWizardPromptStep { + public async prompt(context: BuildImageInAzureImageSourceContext): Promise { + const srcPath: string | undefined = (await context.ui.showQuickPick(this.getPicks(context), { + placeHolder: localize('sourceDirectoryPick', 'Choose your source code directory'), + suppressPersistence: true + })).data; + + context.srcPath = srcPath ?? (await context.ui.showOpenDialog({ + defaultUri: context.rootFolder?.uri, + canSelectFiles: false, + canSelectFolders: true + }))[0].fsPath; + } + + public async configureBeforePrompt(context: BuildImageInAzureImageSourceContext): Promise { + if (this.hasRootDockerfile(context)) { + context.srcPath = context.rootFolder.uri.fsPath; + } + } + + public shouldPrompt(context: BuildImageInAzureImageSourceContext): boolean { + return !context.srcPath; + } + + private getPicks(context: BuildImageInAzureImageSourceContext): IAzureQuickPickItem[] { + const rootPath: string = context.rootFolder.uri.fsPath; + const directories: string[] = path.relative(rootPath, path.dirname(context.dockerfilePath)).split(path.sep); + const picks: IAzureQuickPickItem[] = [{ label: '.' + path.sep, data: rootPath }]; + + let p: string = ''; + for (const directory of directories) { + p += path.sep + directory; + picks.push({ label: '.' + p, data: rootPath + p }); + } + + picks.push(browseItem); + return picks; + } + + private hasRootDockerfile(context: BuildImageInAzureImageSourceContext): boolean { + if (!context.rootFolder || !context.dockerfilePath) { + return false; + } + + const rootPath: string = context.rootFolder.uri.fsPath; + return path.relative(rootPath, context.dockerfilePath) === path.basename(context.dockerfilePath); + } +} diff --git a/src/commands/image/imageSource/buildImageInAzure/UploadSourceCodeStep.ts b/src/commands/image/imageSource/buildImageInAzure/UploadSourceCodeStep.ts index c8ddbf27f..6764fde85 100644 --- a/src/commands/image/imageSource/buildImageInAzure/UploadSourceCodeStep.ts +++ b/src/commands/image/imageSource/buildImageInAzure/UploadSourceCodeStep.ts @@ -19,24 +19,22 @@ const vcsIgnoreList = ['.git', '.gitignore', '.bzr', 'bzrignore', '.hg', '.hgign export class UploadSourceCodeStep extends ExecuteActivityOutputStepBase { public priority: number = 430; + /** Relative path of src folder from rootFolder and what gets deployed */ private _sourceFilePath: string; protected async executeCore(context: BuildImageInAzureImageSourceContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise { - /* relative path of src folder from rootFolder and what gets deployed */ - this._sourceFilePath = path.dirname(path.relative(context.rootFolder.uri.path, context.dockerfilePath)); + this._sourceFilePath = context.rootFolder.uri.fsPath === context.srcPath ? '.' : path.relative(context.rootFolder.uri.fsPath, context.srcPath); context.telemetry.properties.sourceDepth = this._sourceFilePath === '.' ? '0' : String(this._sourceFilePath.split(path.sep).length); context.registryName = nonNullValue(context.registry?.name); context.resourceGroupName = getResourceGroupFromId(nonNullValue(context.registry?.id)); context.client = await createContainerRegistryManagementClient(context); - const uploading: string = localize('uploadingSourceCode', 'Uploading source code...', this._sourceFilePath); - progress.report({ message: uploading }); + progress.report({ message: localize('uploadingSourceCode', 'Uploading source code...') }); + const source: string = path.join(context.rootFolder.uri.fsPath, this._sourceFilePath); let items = await AzExtFsExtra.readDirectory(source); - items = items.filter(i => { - return !vcsIgnoreList.includes(i.name) - }); + items = items.filter(i => !vcsIgnoreList.includes(i.name)); tar.c({ cwd: source }, items.map(i => i.name)).pipe(fse.createWriteStream(context.tarFilePath));