mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
SQL Database Project - Deploy db to docker (#16406)
Added a new command to deploy the project to docker
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from '../common/constants';
|
||||
import { AppSettingType, IDeployProfile, ILocalDbSetting } from '../models/deploy/deployProfile';
|
||||
import { Project } from '../models/project';
|
||||
import * as generator from 'generate-password';
|
||||
import { getPublishDatabaseSettings } from './publishDatabaseQuickpick';
|
||||
import * as path from 'path';
|
||||
import * as fse from 'fs-extra';
|
||||
|
||||
/**
|
||||
* Create flow for Deploying a database using only VS Code-native APIs such as QuickPick
|
||||
*/
|
||||
export async function launchDeployDatabaseQuickpick(project: Project): Promise<IDeployProfile | undefined> {
|
||||
|
||||
// Show options to user for deploy to existing server or docker
|
||||
|
||||
const deployOption = await vscode.window.showQuickPick(
|
||||
[constants.deployToExistingServer, constants.deployToDockerContainer],
|
||||
{ title: constants.selectDeployOption, ignoreFocusOut: true });
|
||||
|
||||
// Return when user hits escape
|
||||
if (!deployOption) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let localDbSetting: ILocalDbSetting | undefined;
|
||||
// Deploy to docker selected
|
||||
if (deployOption === constants.deployToDockerContainer) {
|
||||
let portNumber = await vscode.window.showInputBox({
|
||||
title: constants.enterPortNumber,
|
||||
ignoreFocusOut: true,
|
||||
value: constants.defaultPortNumber,
|
||||
validateInput: input => isNaN(+input) ? constants.portMustBeNumber : undefined
|
||||
}
|
||||
);
|
||||
|
||||
// Return when user hits escape
|
||||
if (!portNumber) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let password: string | undefined = generator.generate({
|
||||
length: 10,
|
||||
numbers: true,
|
||||
symbols: true,
|
||||
lowercase: true,
|
||||
uppercase: true,
|
||||
exclude: '`"\'' // Exclude the chars that cannot be included in the password. Some chars can make the command fail in the terminal
|
||||
});
|
||||
password = await vscode.window.showInputBox({
|
||||
title: constants.enterPassword,
|
||||
ignoreFocusOut: true,
|
||||
value: password,
|
||||
password: true
|
||||
}
|
||||
);
|
||||
|
||||
// Return when user hits escape
|
||||
if (!password) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
localDbSetting = {
|
||||
serverName: 'localhost',
|
||||
userName: 'sa',
|
||||
dbName: project.projectFileName,
|
||||
password: password,
|
||||
port: +portNumber,
|
||||
};
|
||||
}
|
||||
let deploySettings = await getPublishDatabaseSettings(project, deployOption !== constants.deployToDockerContainer);
|
||||
|
||||
// Return when user hits escape
|
||||
if (!deploySettings) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// TODO: Ask for SQL CMD Variables or profile
|
||||
|
||||
let envVarName: string | undefined = '';
|
||||
const integrateWithAzureFunctions: boolean = true; //TODO: get value from settings or quickpick
|
||||
|
||||
//TODO: find a better way to find if AF or local settings is in the project
|
||||
//
|
||||
const localSettings = path.join(project.projectFolderPath, constants.azureFunctionLocalSettingsFileName);
|
||||
const settingExist: boolean = await fse.pathExists(localSettings);
|
||||
if (integrateWithAzureFunctions && settingExist) {
|
||||
|
||||
// Ask user to update app settings or not
|
||||
//
|
||||
let choices: { [id: string]: boolean } = {};
|
||||
let options = {
|
||||
placeHolder: constants.appSettingPrompt
|
||||
};
|
||||
choices[constants.yesString] = true;
|
||||
choices[constants.noString] = false;
|
||||
let result = await vscode.window.showQuickPick(Object.keys(choices).map(c => {
|
||||
return {
|
||||
label: c
|
||||
};
|
||||
}), options);
|
||||
|
||||
// Return when user hits escape
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (result !== undefined && choices[result.label] || false) {
|
||||
envVarName = await vscode.window.showInputBox(
|
||||
{
|
||||
title: constants.enterConnectionStringEnvName,
|
||||
ignoreFocusOut: true,
|
||||
value: constants.defaultConnectionStringEnvVarName,
|
||||
validateInput: input => input === '' ? constants.valueCannotBeEmpty : undefined,
|
||||
placeHolder: constants.enterConnectionStringEnvNameDescription
|
||||
}
|
||||
);
|
||||
|
||||
// Return when user hits escape
|
||||
if (!envVarName) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (localDbSetting && deploySettings) {
|
||||
deploySettings.serverName = localDbSetting.serverName;
|
||||
}
|
||||
|
||||
return {
|
||||
localDbSetting: localDbSetting,
|
||||
envVariableName: envVarName,
|
||||
appSettingFile: settingExist ? localSettings : undefined,
|
||||
deploySettings: deploySettings,
|
||||
appSettingType: settingExist ? AppSettingType.AzureFunction : AppSettingType.None
|
||||
};
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import { IDeploySettings } from '../models/IDeploySettings';
|
||||
/**
|
||||
* Create flow for Publishing a database using only VS Code-native APIs such as QuickPick
|
||||
*/
|
||||
export async function launchPublishDatabaseQuickpick(project: Project, projectController: ProjectsController): Promise<void> {
|
||||
export async function getPublishDatabaseSettings(project: Project, promptForConnection: boolean = true): Promise<IDeploySettings | undefined> {
|
||||
|
||||
// 1. Select publish settings file (optional)
|
||||
// Create custom quickpick so we can control stuff like displaying the loading indicator
|
||||
@@ -74,23 +74,26 @@ export async function launchPublishDatabaseQuickpick(project: Project, projectCo
|
||||
quickPick.hide(); // Hide the quickpick immediately so it isn't showing while the API loads
|
||||
|
||||
// 2. Select connection
|
||||
const vscodeMssqlApi = await getVscodeMssqlApi();
|
||||
|
||||
let connectionProfile: IConnectionInfo | undefined = undefined;
|
||||
let connectionUri: string = '';
|
||||
let dbs: string[] | undefined = undefined;
|
||||
while (!dbs) {
|
||||
connectionProfile = await vscodeMssqlApi.promptForConnection(true);
|
||||
if (!connectionProfile) {
|
||||
// User cancelled
|
||||
return;
|
||||
}
|
||||
// Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't
|
||||
try {
|
||||
connectionUri = await vscodeMssqlApi.connect(connectionProfile);
|
||||
dbs = await vscodeMssqlApi.listDatabases(connectionUri);
|
||||
} catch (err) {
|
||||
// no-op, the mssql extension handles showing the error to the user. We'll just go
|
||||
// back and prompt the user for a connection again
|
||||
let dbs: string[] = [];
|
||||
let connectionUri: string | undefined;
|
||||
if (promptForConnection) {
|
||||
const vscodeMssqlApi = await getVscodeMssqlApi();
|
||||
while (!dbs) {
|
||||
connectionProfile = await vscodeMssqlApi.promptForConnection(true);
|
||||
if (!connectionProfile) {
|
||||
// User cancelled
|
||||
return;
|
||||
}
|
||||
// Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't
|
||||
try {
|
||||
connectionUri = await vscodeMssqlApi.connect(connectionProfile);
|
||||
dbs = await vscodeMssqlApi.listDatabases(connectionUri);
|
||||
} catch (err) {
|
||||
// no-op, the mssql extension handles showing the error to the user. We'll just go
|
||||
// back and prompt the user for a connection again
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,22 +187,33 @@ export async function launchPublishDatabaseQuickpick(project: Project, projectCo
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Select action to take
|
||||
const action = await vscode.window.showQuickPick(
|
||||
[constants.generateScriptButtonText, constants.publish],
|
||||
{ title: constants.chooseAction, ignoreFocusOut: true });
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. Generate script/publish
|
||||
let settings: IDeploySettings = {
|
||||
databaseName: databaseName,
|
||||
serverName: connectionProfile!.server,
|
||||
connectionUri: connectionUri,
|
||||
serverName: connectionProfile?.server || '',
|
||||
connectionUri: connectionUri || '',
|
||||
sqlCmdVariables: sqlCmdVariables,
|
||||
deploymentOptions: await getDefaultPublishDeploymentOptions(project),
|
||||
profileUsed: !!publishProfile
|
||||
};
|
||||
await projectController.publishOrScriptProject(project, settings, action === constants.publish);
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create flow for Publishing a database using only VS Code-native APIs such as QuickPick
|
||||
*/
|
||||
export async function launchPublishDatabaseQuickpick(project: Project, projectController: ProjectsController): Promise<void> {
|
||||
let settings: IDeploySettings | undefined = await getPublishDatabaseSettings(project);
|
||||
|
||||
if (settings) {
|
||||
// 5. Select action to take
|
||||
const action = await vscode.window.showQuickPick(
|
||||
[constants.generateScriptButtonText, constants.publish],
|
||||
{ title: constants.chooseAction, ignoreFocusOut: true });
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
await projectController.publishOrScriptProject(project, settings, action === constants.publish);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user