sqlproj publish to container - october release improvements (#17289)

This commit is contained in:
Leila Lali
2021-10-07 12:55:43 -07:00
committed by GitHub
parent 04ee2c5d83
commit f875699cd2
5 changed files with 67 additions and 29 deletions

View File

@@ -111,11 +111,15 @@ export class DeployService {
const dockerFilePath = path.join(mssqlFolderPath, constants.dockerFileName);
const startFilePath = path.join(commandsFolderPath, constants.startCommandName);
this.logToOutput(constants.cleaningDockerImagesMessage);
// Clean up existing docker image
await this.cleanDockerObjects(`docker ps -q -a --filter label=${imageLabel}`, ['docker stop', 'docker rm']);
await this.cleanDockerObjects(`docker images -f label=${imageLabel} -q`, [`docker rmi -f `]);
const containerIds = await this.getCurrentDockerContainer(imageLabel);
if (containerIds && containerIds.length > 0) {
const result = await vscode.window.showWarningMessage(constants.containerAlreadyExistForProject, constants.yesString, constants.noString);
if (result === constants.yesString) {
this.logToOutput(constants.cleaningDockerImagesMessage);
await this.cleanDockerObjects(containerIds, ['docker stop', 'docker rm']);
}
}
this.logToOutput(constants.creatingDeploymentSettingsMessage);
// Create commands
@@ -363,17 +367,22 @@ RUN ["/bin/bash", "/opt/commands/start.sh"]
await fse.writeFile(filePath, content);
}
public async cleanDockerObjects(commandToGetObjects: string, commandsToClean: string[]): Promise<void> {
const currentIds = await utils.executeCommand(commandToGetObjects, this._outputChannel);
if (currentIds) {
const ids = currentIds.split(/\r?\n/);
for (let index = 0; index < ids.length; index++) {
const id = ids[index];
if (id) {
for (let commandId = 0; commandId < commandsToClean.length; commandId++) {
const command = commandsToClean[commandId];
await utils.executeCommand(`${command} ${id}`, this._outputChannel);
}
private async getCurrentIds(commandToRun: string): Promise<string[]> {
const currentIds = await utils.executeCommand(commandToRun, this._outputChannel);
return currentIds ? currentIds.split(/\r?\n/) : [];
}
public async getCurrentDockerContainer(imageLabel: string): Promise<string[]> {
return await this.getCurrentIds(`docker ps -q -a --filter label=${imageLabel}`);
}
public async cleanDockerObjects(ids: string[], commandsToClean: string[]): Promise<void> {
for (let index = 0; index < ids.length; index++) {
const id = ids[index];
if (id) {
for (let commandId = 0; commandId < commandsToClean.length; commandId++) {
const command = commandsToClean[commandId];
await utils.executeCommand(`${command} ${id}`, this._outputChannel);
}
}
}