Make publish to docker settings properties required (#19898)

* Make publish to docker settings properties required

* move
This commit is contained in:
Charles Gagnon
2022-06-30 16:21:53 -07:00
committed by GitHub
parent 9fbd3b3864
commit dc006be73e
5 changed files with 35 additions and 35 deletions

View File

@@ -320,35 +320,28 @@ export class ProjectsController {
const project: Project = this.getProjectFromContext(context);
// Removing the path separator from the image base name to be able to add that in the telemetry. With the separator the name is flagged as user path which is not true
// We only need to know the image base parts so it's ok to use a different separator when adding to telemetry
const dockerImageNameForTelemetry = deployProfile.dockerSettings?.dockerBaseImage ? deployProfile.dockerSettings.dockerBaseImage.replace(/\//gi, '_') : '';
const dockerImageNameForTelemetry = deployProfile.dockerSettings.dockerBaseImage.replace(/\//gi, '_');
try {
TelemetryReporter.createActionEvent(TelemetryViews.ProjectController, TelemetryActions.publishToContainer)
.withAdditionalProperties({ dockerBaseImage: dockerImageNameForTelemetry })
.send();
if (deployProfile && deployProfile.sqlProjectPublishSettings) {
let connectionUri: string | undefined;
if (deployProfile.dockerSettings) {
void utils.showInfoMessageWithOutputChannel(constants.publishingProjectMessage, this._outputChannel);
connectionUri = await this.deployService.deployToContainer(deployProfile, project);
if (connectionUri) {
deployProfile.sqlProjectPublishSettings.connectionUri = connectionUri;
}
}
void utils.showInfoMessageWithOutputChannel(constants.publishingProjectMessage, this._outputChannel);
const connectionUri = await this.deployService.deployToContainer(deployProfile, project);
if (connectionUri) {
deployProfile.sqlProjectPublishSettings.connectionUri = connectionUri;
}
if (deployProfile.sqlProjectPublishSettings.connectionUri) {
const publishResult = await this.publishOrScriptProject(project, deployProfile.sqlProjectPublishSettings, true);
if (publishResult && publishResult.success) {
if (deployProfile.dockerSettings) {
await this.connectionService.getConnection(deployProfile.dockerSettings, true, deployProfile.dockerSettings.dbName);
}
void vscode.window.showInformationMessage(constants.publishProjectSucceed);
} else {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, publishResult?.errorMessage || '', this._outputChannel);
}
if (deployProfile.sqlProjectPublishSettings.connectionUri) {
const publishResult = await this.publishOrScriptProject(project, deployProfile.sqlProjectPublishSettings, true);
if (publishResult && publishResult.success) {
await this.connectionService.getConnection(deployProfile.dockerSettings, true, deployProfile.dockerSettings.dbName);
void vscode.window.showInformationMessage(constants.publishProjectSucceed);
} else {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, constants.deployProjectFailedMessage, this._outputChannel);
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, publishResult?.errorMessage || '', this._outputChannel);
}
} else {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, constants.deployProjectFailedMessage, this._outputChannel);
}
} catch (error) {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, error, this._outputChannel);
@@ -399,10 +392,12 @@ export class ProjectsController {
}
if (publishTarget === constants.PublishTargetType.docker) {
const deployProfile = await getPublishToDockerSettings(project);
if (deployProfile?.sqlProjectPublishSettings && deployProfile?.dockerSettings) {
await this.publishToDockerContainer(project, deployProfile);
const publishToDockerSettings = await getPublishToDockerSettings(project);
if (!publishToDockerSettings) {
// User cancelled
return;
}
await this.publishToDockerContainer(project, publishToDockerSettings);
} else if (publishTarget === constants.PublishTargetType.newAzureServer) {
try {
const settings = await launchCreateAzureServerQuickPick(project, this.azureSqlClient);

View File

@@ -278,7 +278,6 @@ export async function launchCreateAzureServerQuickPick(project: Project, azureSq
export async function getPublishToDockerSettings(project: ISqlProject): Promise<IPublishToDockerSettings | undefined> {
const target = project.getProjectTargetVersion();
const name = uiUtils.getPublishServerName(target);
let localDbSetting: IDockerSettings | undefined;
// Deploy to docker selected
let portNumber = await vscode.window.showInputBox({
title: constants.enterPortNumber(name),
@@ -370,7 +369,7 @@ export async function getPublishToDockerSettings(project: ISqlProject): Promise<
imageName = `${imageName}:${imageTag.label}`;
}
localDbSetting = {
const dockerSettings: IDockerSettings = {
serverName: constants.defaultLocalServerName,
userName: constants.defaultLocalServerAdminName,
dbName: project.projectFileName,
@@ -388,13 +387,13 @@ export async function getPublishToDockerSettings(project: ISqlProject): Promise<
}
// Server name should be set to localhost
deploySettings.serverName = localDbSetting.serverName;
deploySettings.serverName = dockerSettings.serverName;
// Get the database name from deploy settings
localDbSetting.dbName = deploySettings.databaseName;
dockerSettings.dbName = deploySettings.databaseName;
return {
dockerSettings: localDbSetting,
dockerSettings,
sqlProjectPublishSettings: deploySettings,
};
}

View File

@@ -92,10 +92,6 @@ export class DeployService {
public async deployToContainer(profile: IPublishToDockerSettings, project: Project): Promise<string | undefined> {
return await this.executeTask(constants.deployDbTaskName, async () => {
if (!profile.dockerSettings) {
return undefined;
}
await this.verifyDocker();
this.logToOutput(constants.dockerImageMessage);
this.logToOutput(profile.dockerSettings.dockerBaseImage);

View File

@@ -316,8 +316,8 @@ declare module 'sqldbproj' {
* Settings for publishing a SQL Project to a docker container
*/
export interface IPublishToDockerSettings {
dockerSettings?: IDockerSettings;
sqlProjectPublishSettings?: ISqlProjectPublishSettings;
dockerSettings: IDockerSettings;
sqlProjectPublishSettings: ISqlProjectPublishSettings;
}
export type DeploymentOptions = mssqlDeploymentOptions | vscodeMssqlDeploymentOptions;

View File

@@ -72,6 +72,11 @@ describe('deploy service', function (): void {
it('Should deploy a database to docker container successfully', async function (): Promise<void> {
const testContext = createContext();
const deployProfile: IPublishToDockerSettings = {
sqlProjectPublishSettings: {
databaseName: 'dbName',
serverName: 'serverName',
connectionUri: 'connectionUri'
},
dockerSettings: {
dbName: 'test',
password: 'PLACEHOLDER',
@@ -102,6 +107,11 @@ describe('deploy service', function (): void {
it('Should fail the deploy if docker is not running', async function (): Promise<void> {
const testContext = createContext();
const deployProfile: IPublishToDockerSettings = {
sqlProjectPublishSettings: {
databaseName: 'dbName',
serverName: 'serverName',
connectionUri: 'connectionUri'
},
dockerSettings: {
dbName: 'test',
password: 'PLACEHOLDER',