SQL Project Deploy to docker container - Adding a UI for user to select docker image tag (#19297)

This commit is contained in:
Leila Lali
2022-05-11 11:29:11 -07:00
committed by GitHub
parent 65ef41d53d
commit e10b1eb5a9
10 changed files with 301 additions and 30 deletions

View File

@@ -5,6 +5,8 @@
import { SqlTargetPlatform } from 'sqldbproj';
import * as constants from '../common/constants';
import * as utils from '../common/utils';
import { HttpClient } from '../common/httpClient';
import { AgreementInfo, DockerImageInfo } from '../models/deploy/deployProfile';
/**
@@ -38,58 +40,117 @@ export function getPublishServerName(target: string): string {
return target === constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure) ? constants.AzureSqlServerName : constants.SqlServerName;
}
/**
* Returns the docker image place holder based on the target version
*/
export function getDockerImagePlaceHolder(target: string): string {
return target === constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure) ?
constants.dockerImagesPlaceHolder(constants.AzureSqlDbLiteDockerImageName) :
constants.dockerImagesPlaceHolder(SqlTargetPlatform.sqlEdge);
}
/**
* Returns the list of image tags for given target
* @param imageInfo docker image info
* @param target project target version
* @returns image tags
*/
export async function getImageTags(imageInfo: DockerImageInfo, target: string): Promise<string[]> {
let imageTags: string[] | undefined = [];
const versionToImageTags: Map<number, string[]> = new Map<number, string[]>();
try {
const imageTagsFromUrl = await HttpClient.getRequest(imageInfo?.tagsUrl, true);
if (imageTagsFromUrl?.tags) {
// Create a map for version and tags and find the max version in the list
let defaultVersion: number = 0;
let maxVersionNumber: number = defaultVersion;
(imageTagsFromUrl.tags as string[]).forEach(imageTag => {
const version = utils.findSqlVersionInImageName(imageTag) || defaultVersion;
let tags = versionToImageTags.has(version) ? versionToImageTags.get(version) : [];
tags = tags ?? [];
tags = tags?.concat(imageTag);
versionToImageTags.set(version, tags);
maxVersionNumber = version && version > maxVersionNumber ? version : maxVersionNumber;
});
// Find the version maps to the target framework and default to max version in the tags
const targetVersion = utils.findSqlVersionInTargetPlatform(constants.getTargetPlatformFromVersion(target)) || maxVersionNumber;
// Get the image tags with no version of the one that matches project platform
versionToImageTags.forEach((tags: string[], version: number) => {
if (version === defaultVersion || version >= targetVersion) {
imageTags = imageTags?.concat(tags);
}
});
imageTags = imageTags ?? [];
imageTags = imageTags.sort((a, b) => a.indexOf(constants.dockerImageDefaultTag) > 0 ? -1 : a.localeCompare(b));
}
} catch (err) {
// Ignore the error. If http request fails, we just use the default tag
console.debug(`Failed to get docker image tags ${err}`);
}
return imageTags;
}
/**
* Returns the list of base images for given target version
* @param target
* @returns list of image info
*/
export function getDockerBaseImages(target: string): DockerImageInfo[] {
if (target === constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure)) {
return [{
name: `${constants.sqlServerDockerRegistry}/${constants.sqlServerDockerRepository}:2019-latest`,
displayName: SqlTargetPlatform.sqlServer2019,
name: `${constants.sqlServerDockerRegistry}/${constants.sqlServerDockerRepository}`,
displayName: constants.AzureSqlDbFullDockerImageName,
agreementInfo: {
link: {
text: constants.eulaAgreementTitle,
url: constants.sqlServerEulaLink,
}
}
},
tagsUrl: `https://${constants.sqlServerDockerRegistry}/v2/${constants.sqlServerDockerRepository}/tags/list`,
defaultTag: constants.dockerImageDefaultTag
}, {
name: `${constants.sqlServerDockerRegistry}/${constants.azureSqlEdgeDockerRepository}:latest`,
displayName: SqlTargetPlatform.sqlEdge,
name: `${constants.sqlServerDockerRegistry}/${constants.azureSqlEdgeDockerRepository}`,
displayName: constants.AzureSqlDbLiteDockerImageName,
agreementInfo: {
link: {
text: constants.edgeEulaAgreementTitle,
url: constants.sqlServerEdgeEulaLink,
}
}
},
tagsUrl: `https://${constants.sqlServerDockerRegistry}/v2/${constants.azureSqlEdgeDockerRepository}/tags/list`,
defaultTag: constants.dockerImageDefaultTag
}];
} else {
return [
{
name: `${constants.sqlServerDockerRegistry}/${constants.sqlServerDockerRepository}:2017-latest`,
displayName: SqlTargetPlatform.sqlServer2017,
name: `${constants.sqlServerDockerRegistry}/${constants.sqlServerDockerRepository}`,
displayName: constants.SqlServerDockerImageName,
agreementInfo: {
link: {
text: constants.eulaAgreementTitle,
url: constants.sqlServerEulaLink,
}
}
},
tagsUrl: `https://${constants.sqlServerDockerRegistry}/v2/${constants.sqlServerDockerRepository}/tags/list`,
defaultTag: constants.dockerImageDefaultTag
},
{
name: `${constants.sqlServerDockerRegistry}/${constants.sqlServerDockerRepository}:2019-latest`,
displayName: SqlTargetPlatform.sqlServer2019,
agreementInfo: {
link: {
text: constants.eulaAgreementTitle,
url: constants.sqlServerEulaLink,
}
}
},
{
name: `${constants.sqlServerDockerRegistry}/${constants.azureSqlEdgeDockerRepository}:latest`,
name: `${constants.sqlServerDockerRegistry}/${constants.azureSqlEdgeDockerRepository}`,
displayName: SqlTargetPlatform.sqlEdge,
agreementInfo: {
link: {
text: constants.edgeEulaAgreementTitle,
url: constants.sqlServerEdgeEulaLink,
}
}
},
tagsUrl: `https://${constants.sqlServerDockerRegistry}/v2/${constants.azureSqlEdgeDockerRepository}/tags/list`,
defaultTag: constants.dockerImageDefaultTag
},
];
}