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); 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 // 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 // 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 { try {
TelemetryReporter.createActionEvent(TelemetryViews.ProjectController, TelemetryActions.publishToContainer) TelemetryReporter.createActionEvent(TelemetryViews.ProjectController, TelemetryActions.publishToContainer)
.withAdditionalProperties({ dockerBaseImage: dockerImageNameForTelemetry }) .withAdditionalProperties({ dockerBaseImage: dockerImageNameForTelemetry })
.send(); .send();
if (deployProfile && deployProfile.sqlProjectPublishSettings) { void utils.showInfoMessageWithOutputChannel(constants.publishingProjectMessage, this._outputChannel);
let connectionUri: string | undefined; const connectionUri = await this.deployService.deployToContainer(deployProfile, project);
if (deployProfile.dockerSettings) { if (connectionUri) {
void utils.showInfoMessageWithOutputChannel(constants.publishingProjectMessage, this._outputChannel); deployProfile.sqlProjectPublishSettings.connectionUri = connectionUri;
connectionUri = await this.deployService.deployToContainer(deployProfile, project); }
if (connectionUri) {
deployProfile.sqlProjectPublishSettings.connectionUri = connectionUri;
}
}
if (deployProfile.sqlProjectPublishSettings.connectionUri) { if (deployProfile.sqlProjectPublishSettings.connectionUri) {
const publishResult = await this.publishOrScriptProject(project, deployProfile.sqlProjectPublishSettings, true); const publishResult = await this.publishOrScriptProject(project, deployProfile.sqlProjectPublishSettings, true);
if (publishResult && publishResult.success) { if (publishResult && publishResult.success) {
if (deployProfile.dockerSettings) { await this.connectionService.getConnection(deployProfile.dockerSettings, true, deployProfile.dockerSettings.dbName);
await this.connectionService.getConnection(deployProfile.dockerSettings, true, deployProfile.dockerSettings.dbName); void vscode.window.showInformationMessage(constants.publishProjectSucceed);
}
void vscode.window.showInformationMessage(constants.publishProjectSucceed);
} else {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, publishResult?.errorMessage || '', this._outputChannel);
}
} else { } 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) { } catch (error) {
void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, error, this._outputChannel); void utils.showErrorMessageWithOutputChannel(constants.publishToContainerFailed, error, this._outputChannel);
@@ -399,10 +392,12 @@ export class ProjectsController {
} }
if (publishTarget === constants.PublishTargetType.docker) { if (publishTarget === constants.PublishTargetType.docker) {
const deployProfile = await getPublishToDockerSettings(project); const publishToDockerSettings = await getPublishToDockerSettings(project);
if (deployProfile?.sqlProjectPublishSettings && deployProfile?.dockerSettings) { if (!publishToDockerSettings) {
await this.publishToDockerContainer(project, deployProfile); // User cancelled
return;
} }
await this.publishToDockerContainer(project, publishToDockerSettings);
} else if (publishTarget === constants.PublishTargetType.newAzureServer) { } else if (publishTarget === constants.PublishTargetType.newAzureServer) {
try { try {
const settings = await launchCreateAzureServerQuickPick(project, this.azureSqlClient); 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> { export async function getPublishToDockerSettings(project: ISqlProject): Promise<IPublishToDockerSettings | undefined> {
const target = project.getProjectTargetVersion(); const target = project.getProjectTargetVersion();
const name = uiUtils.getPublishServerName(target); const name = uiUtils.getPublishServerName(target);
let localDbSetting: IDockerSettings | undefined;
// Deploy to docker selected // Deploy to docker selected
let portNumber = await vscode.window.showInputBox({ let portNumber = await vscode.window.showInputBox({
title: constants.enterPortNumber(name), title: constants.enterPortNumber(name),
@@ -370,7 +369,7 @@ export async function getPublishToDockerSettings(project: ISqlProject): Promise<
imageName = `${imageName}:${imageTag.label}`; imageName = `${imageName}:${imageTag.label}`;
} }
localDbSetting = { const dockerSettings: IDockerSettings = {
serverName: constants.defaultLocalServerName, serverName: constants.defaultLocalServerName,
userName: constants.defaultLocalServerAdminName, userName: constants.defaultLocalServerAdminName,
dbName: project.projectFileName, dbName: project.projectFileName,
@@ -388,13 +387,13 @@ export async function getPublishToDockerSettings(project: ISqlProject): Promise<
} }
// Server name should be set to localhost // Server name should be set to localhost
deploySettings.serverName = localDbSetting.serverName; deploySettings.serverName = dockerSettings.serverName;
// Get the database name from deploy settings // Get the database name from deploy settings
localDbSetting.dbName = deploySettings.databaseName; dockerSettings.dbName = deploySettings.databaseName;
return { return {
dockerSettings: localDbSetting, dockerSettings,
sqlProjectPublishSettings: deploySettings, sqlProjectPublishSettings: deploySettings,
}; };
} }

View File

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

View File

@@ -316,8 +316,8 @@ declare module 'sqldbproj' {
* Settings for publishing a SQL Project to a docker container * Settings for publishing a SQL Project to a docker container
*/ */
export interface IPublishToDockerSettings { export interface IPublishToDockerSettings {
dockerSettings?: IDockerSettings; dockerSettings: IDockerSettings;
sqlProjectPublishSettings?: ISqlProjectPublishSettings; sqlProjectPublishSettings: ISqlProjectPublishSettings;
} }
export type DeploymentOptions = mssqlDeploymentOptions | vscodeMssqlDeploymentOptions; 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> { it('Should deploy a database to docker container successfully', async function (): Promise<void> {
const testContext = createContext(); const testContext = createContext();
const deployProfile: IPublishToDockerSettings = { const deployProfile: IPublishToDockerSettings = {
sqlProjectPublishSettings: {
databaseName: 'dbName',
serverName: 'serverName',
connectionUri: 'connectionUri'
},
dockerSettings: { dockerSettings: {
dbName: 'test', dbName: 'test',
password: 'PLACEHOLDER', 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> { it('Should fail the deploy if docker is not running', async function (): Promise<void> {
const testContext = createContext(); const testContext = createContext();
const deployProfile: IPublishToDockerSettings = { const deployProfile: IPublishToDockerSettings = {
sqlProjectPublishSettings: {
databaseName: 'dbName',
serverName: 'serverName',
connectionUri: 'connectionUri'
},
dockerSettings: { dockerSettings: {
dbName: 'test', dbName: 'test',
password: 'PLACEHOLDER', password: 'PLACEHOLDER',