diff --git a/common-npm-packages/build-scripts/util.js b/common-npm-packages/build-scripts/util.js index 464f3b43..91ca7abe 100644 --- a/common-npm-packages/build-scripts/util.js +++ b/common-npm-packages/build-scripts/util.js @@ -61,7 +61,7 @@ exports.cd = cd; * mkdir unix command via shelljs * @param {String} options - Command options * @param {String} source - Source folder path - * @param {String} dest - Destination folder path + * @param {String} [dest] - Destination folder path */ const cp = function (options, source, dest) { if (dest) { diff --git a/common-npm-packages/docker-common/containerconnection.ts b/common-npm-packages/docker-common/containerconnection.ts index cf5fbc9e..f320cde3 100644 --- a/common-npm-packages/docker-common/containerconnection.ts +++ b/common-npm-packages/docker-common/containerconnection.ts @@ -1,31 +1,31 @@ -"use strict"; - -import * as del from "del"; import * as fs from "fs"; +import * as os from "os"; import * as path from "path"; import * as url from "url"; + import * as tl from "azure-pipelines-task-lib/task"; import * as tr from "azure-pipelines-task-lib/toolrunner"; +import * as del from "del"; + import * as imageUtils from "./containerimageutils"; import AuthenticationToken from "./registryauthenticationprovider/registryauthenticationtoken" import * as fileutils from "./fileutils"; -import * as os from "os"; tl.setResourcePath(path.join(__dirname, 'module.json'), true); export default class ContainerConnection { private dockerPath: string; - protected hostUrl: string; - protected certsDir: string; - private caPath: string; - private certPath: string; - private keyPath: string; - private registryAuth: { [key: string]: string }; - private configurationDirPath: string; - private oldDockerConfigContent: string; + protected hostUrl: string = ""; + protected certsDir: string = ""; + private caPath: string = ""; + private certPath: string = ""; + private keyPath: string = ""; + private registryAuth: { [key: string]: string } = {}; + private configurationDirPath: string = ""; + private oldDockerConfigContent: string | null | undefined; constructor(isDockerRequired: boolean = true) { - this.dockerPath = tl.which("docker", isDockerRequired); + this.dockerPath = tl.which("docker", isDockerRequired); } public createCommand(): tr.ToolRunner { @@ -41,7 +41,7 @@ export default class ContainerConnection { } public execCommand(command: tr.ToolRunner, options?: tr.IExecOptions) { - let errlines = []; + let errlines: string[] = []; let dockerHostVar = tl.getVariable("DOCKER_HOST"); if (dockerHostVar) { @@ -51,7 +51,7 @@ export default class ContainerConnection { command.on("errline", line => { errlines.push(line); }); - + const hideDockerExecTaskLogIssueErrorOutput = tl.getPipelineFeature("hideDockerExecTaskLogIssueErrorOutput"); return command.exec(options).fail(error => { @@ -102,7 +102,7 @@ export default class ContainerConnection { if (enforceDockerNamingConvention) { imageName = imageUtils.generateValidImageName(imageName); } - + imageNames.push(imageName); }); } @@ -113,7 +113,7 @@ export default class ContainerConnection { if (enforceDockerNamingConvention) { imageName = imageUtils.generateValidImageName(imageName); } - + imageNames.push(imageName); } } @@ -136,7 +136,7 @@ export default class ContainerConnection { } } } - + public setDockerConfigEnvVariable() { if (this.configurationDirPath && fs.existsSync(this.configurationDirPath)) { tl.setVariable("DOCKER_CONFIG", this.configurationDirPath); @@ -146,13 +146,13 @@ export default class ContainerConnection { throw new Error(tl.loc('DockerRegistryNotFound')); } } - + public unsetDockerConfigEnvVariable() { var dockerConfigPath = tl.getVariable("DOCKER_CONFIG"); if (dockerConfigPath) { this.unsetEnvironmentVariable(); del.sync(dockerConfigPath, {force: true}); - } + } } private logout() { @@ -169,12 +169,12 @@ export default class ContainerConnection { tl.debug(tl.loc('RestoringOldLoginAuth', registry)); this.writeDockerConfigJson(this.oldDockerConfigContent, existingConfigurationFile); } - else { + else { let existingConfigJson = this.getDockerConfigJson(existingConfigurationFile); if (existingConfigJson && existingConfigJson.auths && existingConfigJson.auths[registry]) { if (Object.keys(existingConfigJson.auths).length > 1) { // if the config contains other auths, then delete only the auth entry for the registry - tl.debug(tl.loc('FoundLoginsForOtherRegistries', registry)); + tl.debug(tl.loc('FoundLoginsForOtherRegistries', registry)); delete existingConfigJson.auths[registry]; let dockerConfigContent = JSON.stringify(existingConfigJson); tl.debug(tl.loc('DeletingAuthDataFromDockerConfig', registry, dockerConfigContent)); @@ -198,7 +198,7 @@ export default class ContainerConnection { tl.debug(tl.loc('CouldNotFindDockerConfig', this.configurationDirPath)); this.unsetEnvironmentVariable(); } - } + } // unset the docker config env variable, and delete the docker config file (if present) else { tl.debug(tl.loc('LoggingOutWithNoRegistrySpecified')); @@ -212,21 +212,21 @@ export default class ContainerConnection { tl.debug(tl.loc('DeletingDockerConfigDirectory', dockerConfigDirPath)); del.sync(dockerConfigDirPath, {force: true}); } - + this.unsetEnvironmentVariable(); } private unsetEnvironmentVariable(): void { - tl.setVariable("DOCKER_CONFIG", ""); + tl.setVariable("DOCKER_CONFIG", ""); } - private isLogoutRequired(command: string): boolean { + private isLogoutRequired(command?: string): boolean { return command === "logout" || (this.registryAuth && !!this.registryAuth["registry"]); } private openHostEndPoint(hostEndpoint?: string): void { if (hostEndpoint) { - this.hostUrl = tl.getEndpointUrl(hostEndpoint, false); + this.hostUrl = tl.getEndpointUrl(hostEndpoint, false)!; if (this.hostUrl.charAt(this.hostUrl.length - 1) == "/") { this.hostUrl = this.hostUrl.substring(0, this.hostUrl.length - 1); } @@ -236,7 +236,7 @@ export default class ContainerConnection { fs.mkdirSync(this.certsDir); } - var authDetails = tl.getEndpointAuthorization(hostEndpoint, false).parameters; + var authDetails = tl.getEndpointAuthorization(hostEndpoint, false)!.parameters; this.caPath = path.join(this.certsDir, "ca.pem"); fs.writeFileSync(this.caPath, authDetails["cacert"]); @@ -248,10 +248,10 @@ export default class ContainerConnection { fs.writeFileSync(this.keyPath, authDetails["key"]); } } - - protected openRegistryEndpoint(authenticationToken?: AuthenticationToken, multipleLoginSupported?: boolean, doNotAddAuthToConfig?: boolean): void { + + protected openRegistryEndpoint(authenticationToken?: AuthenticationToken, multipleLoginSupported?: boolean, doNotAddAuthToConfig?: boolean): void { this.oldDockerConfigContent = null; - if (authenticationToken) { + if (authenticationToken) { this.registryAuth = {}; this.registryAuth["username"] = authenticationToken.getUsername(); @@ -268,7 +268,7 @@ export default class ContainerConnection { if (existingConfigJson && existingConfigJson.auths) { let newAuth = authenticationToken.getDockerAuth(); let newAuthJson = JSON.parse(newAuth); - // Think of json object as a dictionary and authJson looks like + // Think of json object as a dictionary and authJson looks like // "auths": { // "aj.azurecr.io": { // "auth": "***", @@ -278,9 +278,9 @@ export default class ContainerConnection { // key will be aj.azurecr.io // for (let registryName in newAuthJson) { - - // If auth is already present for the same registry, then cache it so that we can - // preserve it back on logout. + + // If auth is already present for the same registry, then cache it so that we can + // preserve it back on logout. if (existingConfigJson.auths[registryName]) { this.oldDockerConfigContent = JSON.stringify(existingConfigJson); tl.debug(tl.loc('OldDockerConfigContent', this.oldDockerConfigContent)); @@ -297,14 +297,14 @@ export default class ContainerConnection { else { var json = authenticationToken.getDockerConfig(); this.writeDockerConfigJson(json); - } + } } } } - private getExistingDockerConfigFilePath(): string { - this.configurationDirPath = tl.getVariable("DOCKER_CONFIG"); - let configurationFilePath = this.configurationDirPath ? path.join(this.configurationDirPath, "config.json") : ""; + private getExistingDockerConfigFilePath(): string | null { + this.configurationDirPath = tl.getVariable("DOCKER_CONFIG")!; + let configurationFilePath = this.configurationDirPath ? path.join(this.configurationDirPath, "config.json") : ""; if (this.configurationDirPath && this.isPathInTempDirectory(configurationFilePath) && fs.existsSync(configurationFilePath)) { return configurationFilePath; } @@ -331,9 +331,9 @@ export default class ContainerConnection { if (!configurationFilePath){ this.configurationDirPath = this.getDockerConfigDirPath(); process.env["DOCKER_CONFIG"] = this.configurationDirPath; - configurationFilePath = path.join(this.configurationDirPath, "config.json"); + configurationFilePath = path.join(this.configurationDirPath, "config.json"); } - + tl.debug(tl.loc('WritingDockerConfigToTempFile', configurationFilePath, dockerConfigContent)); if(fileutils.writeFileSync(configurationFilePath, dockerConfigContent) == 0) { tl.error(tl.loc('NoDataWrittenOnFile', configurationFilePath)); @@ -345,7 +345,7 @@ export default class ContainerConnection { var configDir = path.join(this.getTempDirectory(), "DockerConfig_"+Date.now()); this.ensureDirExists(configDir); return configDir; - } + } private ensureDirExists(dirPath : string) : void { @@ -361,9 +361,9 @@ export default class ContainerConnection { } private getRegistryUrlsFromDockerConfig(): string[] { - let regUrls: string[] = []; + let regUrls: string[] = []; let existingConfigurationFile = this.getExistingDockerConfigFilePath(); - if (existingConfigurationFile) { + if (existingConfigurationFile) { let existingConfigJson = this.getDockerConfigJson(existingConfigurationFile); if (existingConfigJson && existingConfigJson.auths) { regUrls = Object.keys(existingConfigJson.auths); @@ -379,9 +379,9 @@ export default class ContainerConnection { return regUrls; } - private isPathInTempDirectory(path): boolean { + private isPathInTempDirectory(path: string): boolean { let tempDir = this.getTempDirectory(); - let result = path && path.startsWith(tempDir); + let result = !!path && path.startsWith(tempDir); if (!result) { tl.debug(tl.loc('PathIsNotInTempDirectory', path, tempDir)); } @@ -396,7 +396,7 @@ export default class ContainerConnection { let regUrl = url.parse(registry); let hostname = !regUrl.slashes ? regUrl.href : regUrl.host; // For docker hub, repository name is the qualified image name. Prepend hostname if the registry is not docker hub. - if (hostname.toLowerCase() !== "index.docker.io") { + if (hostname!.toLowerCase() !== "index.docker.io") { imageName = hostname + "/" + repository; } } diff --git a/common-npm-packages/docker-common/containerimageutils.ts b/common-npm-packages/docker-common/containerimageutils.ts index 5c8a681e..b3d24885 100644 --- a/common-npm-packages/docker-common/containerimageutils.ts +++ b/common-npm-packages/docker-common/containerimageutils.ts @@ -36,10 +36,10 @@ export function getBaseImageNameFromDockerFile(dockerFilePath: string): string { tl.debug(`Failed to get the base image name of Dockerfile : ${dockerFilePath}`); } - return baseImageName + return baseImageName!; } -export function getBaseImageName(dockerFileContent: string): string { +export function getBaseImageName(dockerFileContent: string): string | null { // This method takes into consideration multi-stage dockerfiles, it tries to find the final // base image for the container. // ex: @@ -50,7 +50,7 @@ export function getBaseImageName(dockerFileContent: string): string { // // FROM base // RUN echo 'test2' - // + // // This code is going to return ubuntu:16.04 try { @@ -74,15 +74,15 @@ export function getBaseImageName(dockerFileContent: string): string { var alias = nameComponents[1].trim(); if (aliasToImageNameMapping.has(prospectImageName)) { - aliasToImageNameMapping.set(alias, aliasToImageNameMapping.get(prospectImageName)); + aliasToImageNameMapping.set(alias, aliasToImageNameMapping.get(prospectImageName)!); } else { aliasToImageNameMapping.set(alias, prospectImageName); } - baseImage = aliasToImageNameMapping.get(alias); + baseImage = aliasToImageNameMapping.get(alias)!; } else { baseImage = aliasToImageNameMapping.has(prospectImageName) - ? aliasToImageNameMapping.get(prospectImageName) + ? aliasToImageNameMapping.get(prospectImageName)! : prospectImageName; } } @@ -91,12 +91,13 @@ export function getBaseImageName(dockerFileContent: string): string { ? null : sanityzeBaseImage(baseImage); } catch (error) { + // @ts-ignore tl.debug(`An error ocurred getting the base image name. ${error.message}`); return null; } } -function sanityzeBaseImage(baseImage: string): string { +function sanityzeBaseImage(baseImage: string): string | null{ if (!baseImage){ return null; } @@ -117,7 +118,6 @@ export function getResourceName(image: string, digest: string) { var registry = match[1]; var namespace = match[2]; var repository = match[3]; - var tag = match[4]; if (!namespace && registry && !/[:.]/.test(registry)) { namespace = registry @@ -135,7 +135,7 @@ export function getResourceName(image: string, digest: string) { return "https://" + registry + namespace + repository + "@sha256:" + digest; } -export function getImageDigest(connection: ContainerConnection, imageName: string,): string { +export function getImageDigest(connection: ContainerConnection, imageName: string): string | null { try { pullImage(connection, imageName); let inspectObj = inspectImage(connection, imageName); @@ -158,6 +158,7 @@ export function getImageDigest(connection: ContainerConnection, imageName: strin return repoDigests[0].split("@")[1]; } catch (error) { + // @ts-ignore tl.debug(`An exception was thrown getting the image digest for ${imageName}, the error was ${error.message}`) return null; } @@ -174,7 +175,7 @@ function pullImage(connection: ContainerConnection, imageName: string) { } } -function inspectImage(connection: ContainerConnection, imageName): any { +function inspectImage(connection: ContainerConnection, imageName: string): any { try { let inspectCommand = connection.createCommand(); inspectCommand.arg("inspect"); @@ -195,6 +196,7 @@ function inspectImage(connection: ContainerConnection, imageName): any { return inspectObj[0]; } catch (error) { + // @ts-ignore tl.debug(`An error ocurred running the inspect command: ${error.message}`); return null; } @@ -203,7 +205,7 @@ function inspectImage(connection: ContainerConnection, imageName): any { export function shareBuiltImageId(builtImageId: string) { const IMAGE_SEPARATOR_CHAR: string = ";"; const ENV_VARIABLE_MAX_SIZE = 32766; - let builtImages: string = tl.getVariable("DOCKER_TASK_BUILT_IMAGES"); + let builtImages: string = tl.getVariable("DOCKER_TASK_BUILT_IMAGES")!; if (builtImages && builtImages != "") { const newImageId = `${IMAGE_SEPARATOR_CHAR}${builtImages}`; @@ -224,7 +226,7 @@ export function shareBuiltImageId(builtImageId: string) { export function getImageIdFromBuildOutput(output: string): string { const standardParser = (text: string): string => { - let parsedOutput: string[] = text.match(new RegExp("Successfully built ([0-9a-f]{12})", 'g')); + let parsedOutput: RegExpMatchArray | null = text.match(new RegExp("Successfully built ([0-9a-f]{12})", 'g')); return !parsedOutput || parsedOutput.length == 0 ? "" @@ -232,7 +234,7 @@ export function getImageIdFromBuildOutput(output: string): string { }; const buildKitParser = (text: string): string => { - let parsedOutput: string[] = text.match(new RegExp("writing image sha256:([0-9a-f]{64})", 'gi')); + let parsedOutput: RegExpMatchArray | null = text.match(new RegExp("writing image sha256:([0-9a-f]{64})", 'gi')); return !parsedOutput || parsedOutput.length == 0 ? "" @@ -248,12 +250,13 @@ export function getImageIdFromBuildOutput(output: string): string { } } } catch (error) { + // @ts-ignore tl.debug(`An error occurred getting the image id from the docker ouput: ${error.message}`) } return ""; } -export function getBaseImageDetialsFromDockerFIle(dockerFileContentPath: string, connection?: ContainerConnection):baseImageDetails { +export function getBaseImageDetialsFromDockerFIle(dockerFileContentPath: string, connection?: ContainerConnection): BaseImageDetails | null { // This method checks if there is FROM image@sha256:digest present in Dockerfile // if matched it returns digest // if not, it returns null @@ -266,7 +269,7 @@ export function getBaseImageDetialsFromDockerFIle(dockerFileContentPath: string, var lines = dockerFileContent.split(/[\r?\n]/); var aliasToImageNameMapping: Map = new Map(); var baseImage = ""; - const baseImageDetails = { name: "", digest: "" }; + const baseImageDetails: BaseImageDetails = { name: "", digest: "" }; for (var i = 0; i < lines.length; i++) { const currentLine = lines[i].trim(); @@ -281,19 +284,19 @@ export function getBaseImageDetialsFromDockerFIle(dockerFileContentPath: string, var alias = nameComponents[1].trim(); if (aliasToImageNameMapping.has(prospectImageName)) { - aliasToImageNameMapping.set(alias, aliasToImageNameMapping.get(prospectImageName)); + aliasToImageNameMapping.set(alias, aliasToImageNameMapping.get(prospectImageName)!); } else { aliasToImageNameMapping.set(alias, prospectImageName); } - baseImage = aliasToImageNameMapping.get(alias); + baseImage = aliasToImageNameMapping.get(alias)!; } else { baseImage = aliasToImageNameMapping.has(prospectImageName) - ? aliasToImageNameMapping.get(prospectImageName) + ? aliasToImageNameMapping.get(prospectImageName)! : prospectImageName; } } - baseImageDetails.name = baseImage.includes("$") ? null : sanityzeBaseImage(baseImage);// In this case the base image has an argument and we don't know what its real value is + baseImageDetails.name = baseImage.includes("$") ? null : sanityzeBaseImage(baseImage);// In this case the base image has an argument and we don't know what its real value is if (!connection) { tl.debug("Image digest couldn't be extracted because no connection was found."); @@ -312,11 +315,13 @@ export function getBaseImageDetialsFromDockerFIle(dockerFileContentPath: string, } return baseImageDetails; } catch (error) { + // @ts-ignore tl.debug(`An error ocurred getting the base image details. ${error.message}`); return null; } } -export class baseImageDetails{ - name: string; - digest: string ; -} \ No newline at end of file + +export type BaseImageDetails = { + name: string | null; + digest: string | null; +} diff --git a/common-npm-packages/docker-common/dockercommandutils.ts b/common-npm-packages/docker-common/dockercommandutils.ts index 1e9474c7..6e699bc6 100644 --- a/common-npm-packages/docker-common/dockercommandutils.ts +++ b/common-npm-packages/docker-common/dockercommandutils.ts @@ -1,11 +1,10 @@ -"use strict"; +import * as path from "path"; +import * as crypto from "crypto"; import * as tl from "azure-pipelines-task-lib/task"; import * as Q from "q"; + import ContainerConnection from "./containerconnection"; -import * as pipelineUtils from "./pipelineutils"; -import * as path from "path"; -import * as crypto from "crypto"; const matchPatternForSize = new RegExp(/[\d\.]+/); const orgUrl = tl.getVariable('System.TeamFoundationCollectionUri'); @@ -14,7 +13,7 @@ const hostType = tl.getVariable("System.HostType"); const isBuild = hostType && hostType.toLowerCase() === buildString; const matchPatternForDigest = new RegExp(/sha256\:(.+)/); -export function build(connection: ContainerConnection, dockerFile: string, commandArguments: string, labelArguments: string[], tagArguments: string[], onCommandOut: (output) => any): any { +export function build(connection: ContainerConnection, dockerFile: string, commandArguments: string, labelArguments: string[], tagArguments: string[], onCommandOut: (output: string) => any): any { var command = connection.createCommand(); command.arg("build"); @@ -49,7 +48,7 @@ export function build(connection: ContainerConnection, dockerFile: string, comma }); } -export function command(connection: ContainerConnection, dockerCommand: string, commandArguments: string, onCommandOut: (output) => any): any { +export function command(connection: ContainerConnection, dockerCommand: string, commandArguments: string, onCommandOut: (output: string) => any): any { let command = connection.createCommand(); command.arg(dockerCommand); command.line(commandArguments); @@ -66,7 +65,7 @@ export function command(connection: ContainerConnection, dockerCommand: string, }); } -export function push(connection: ContainerConnection, image: string, commandArguments: string, onCommandOut: (image, output) => any): any { +export function push(connection: ContainerConnection, image: string, commandArguments: string, onCommandOut: (image: string, output: string) => any): any { var command = connection.createCommand(); command.arg("push"); command.arg(image); @@ -84,7 +83,7 @@ export function push(connection: ContainerConnection, image: string, commandArgu }); } -export function start(connection: ContainerConnection, container: string, commandArguments: string, onCommandOut: (container, output) => any): any { +export function start(connection: ContainerConnection, container: string, commandArguments: string, onCommandOut: (container: string, output: string) => any): any { var command = connection.createCommand(); command.arg("start"); command.arg(container); @@ -102,7 +101,7 @@ export function start(connection: ContainerConnection, container: string, comman }); } -export function stop(connection: ContainerConnection, container: string, commandArguments: string, onCommandOut: (container, output) => any): any { +export function stop(connection: ContainerConnection, container: string, commandArguments: string, onCommandOut: (container: string, output: string) => any): any { var command = connection.createCommand(); command.arg("stop"); command.arg(container); @@ -129,10 +128,10 @@ export function getCreatorEmail(): string { const buildReason = tl.getVariable("Build.Reason"); let userEmail: string = ""; if (isBuild && (!buildReason || buildReason.toLowerCase() !== schedule)) { - userEmail = tl.getVariable("Build.RequestedForEmail"); + userEmail = tl.getVariable("Build.RequestedForEmail")!; } else { - userEmail = tl.getVariable("Release.RequestedForEmail"); + userEmail = tl.getVariable("Release.RequestedForEmail")!; } return userEmail; @@ -141,10 +140,10 @@ export function getCreatorEmail(): string { export function getPipelineLogsUrl(): string { let pipelineUrl = ""; if (isBuild) { - pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_build/results?buildId=" + tl.getVariable("Build.BuildId"); + pipelineUrl = orgUrl + tl.getVariable("System.TeamProject")! + "/_build/results?buildId=" + tl.getVariable("Build.BuildId"); } else { - pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_releaseProgress?releaseId=" + tl.getVariable("Release.ReleaseId"); + pipelineUrl = orgUrl + tl.getVariable("System.TeamProject")! + "/_releaseProgress?releaseId=" + tl.getVariable("Release.ReleaseId"); } return pipelineUrl; @@ -172,7 +171,7 @@ export function getBuildAndPushArguments(dockerFile: string, labelArguments: str } export function getBuildContext(dockerFile: string): string { - let buildContext = tl.getPathInput("buildContext"); + let buildContext = tl.getPathInput("buildContext")!; if (useDefaultBuildContext(buildContext)) { buildContext = path.dirname(dockerFile); } @@ -181,7 +180,7 @@ export function getBuildContext(dockerFile: string): string { } export function useDefaultBuildContext(buildContext: string): boolean { - let defaultWorkingDir = tl.getVariable("SYSTEM_DEFAULTWORKINGDIRECTORY"); + let defaultWorkingDir = tl.getVariable("SYSTEM_DEFAULTWORKINGDIRECTORY")!; let defaultPath = path.join(defaultWorkingDir, "**"); return buildContext === defaultPath; } @@ -190,17 +189,17 @@ export function getPipelineUrl(): string { let pipelineUrl = ""; const pipelineId = tl.getVariable("System.DefinitionId"); if (isBuild) { - pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_build?definitionId=" + pipelineId; + pipelineUrl = orgUrl + tl.getVariable("System.TeamProject")! + "/_build?definitionId=" + pipelineId; } else { - pipelineUrl = orgUrl + tl.getVariable("System.TeamProject") + "/_release?definitionId=" + pipelineId; + pipelineUrl = orgUrl + tl.getVariable("System.TeamProject")! + "/_release?definitionId=" + pipelineId; } return pipelineUrl; } -export function getLayers(history: string): { [key: string]: string }[] { - var layers = []; +export function getLayers(history: string): { [key: string]: string }[] | null { + var layers: { [key: string]: string }[] = []; if (!history) { return null; } @@ -216,7 +215,7 @@ export function getLayers(history: string): { [key: string]: string }[] { return layers.reverse(); } -export function getImageFingerPrintV1Name(history: string): string { +export function getImageFingerPrintV1Name(history: string): string | null { let v1Name = ""; if (!history) { return null; @@ -341,7 +340,7 @@ export async function getHistory(connection: ContainerConnection, image: string) catch (e) { // Swallow any exceptions encountered in executing command // such as --format flag not supported in old docker cli versions - output = null; + output = ""; defer.resolve(); tl.warning("Not publishing to image meta data store as get history failed with error " + e); } @@ -373,7 +372,7 @@ export async function getImageRootfsLayers(connection: ContainerConnection, imag } catch (e) { // Swallow any exceptions encountered in executing command - output = null; + output = ""; defer.resolve(); tl.warning("get image inspect failed with error " + e); } @@ -430,5 +429,5 @@ function generateV2Name(input: string): string { function isBuildKitBuild(): boolean { const isBuildKitBuildValue = tl.getVariable("DOCKER_BUILDKIT"); - return isBuildKitBuildValue && Number(isBuildKitBuildValue) == 1; + return !!isBuildKitBuildValue && Number(isBuildKitBuildValue) == 1; } \ No newline at end of file diff --git a/common-npm-packages/docker-common/fileutils.ts b/common-npm-packages/docker-common/fileutils.ts index 26832347..6d05690d 100644 --- a/common-npm-packages/docker-common/fileutils.ts +++ b/common-npm-packages/docker-common/fileutils.ts @@ -1,10 +1,7 @@ -"use strict"; +import * as fs from 'fs'; +import * as path from 'path'; -import * as del from "del"; -import * as fs from "fs"; -import * as path from "path"; -import * as url from "url"; -import * as tl from "azure-pipelines-task-lib/task"; +import * as tl from 'azure-pipelines-task-lib/task'; tl.setResourcePath(path.join(__dirname, 'module.json'), true); @@ -29,7 +26,7 @@ export function writeFileSync(filePath: string, data: string): number { export function findDockerFile(dockerfilepath: string) : string { if (dockerfilepath.indexOf('*') >= 0 || dockerfilepath.indexOf('?') >= 0) { tl.debug(tl.loc('ContainerPatternFound')); - let workingDirectory = tl.getVariable('System.DefaultWorkingDirectory'); + let workingDirectory = tl.getVariable('System.DefaultWorkingDirectory')!; let allFiles = tl.find(workingDirectory); let matchingResultsFiles = tl.match(allFiles, dockerfilepath, workingDirectory, { matchBase: true }); diff --git a/common-npm-packages/docker-common/make.js b/common-npm-packages/docker-common/make.js index 004e7a50..2e76008e 100644 --- a/common-npm-packages/docker-common/make.js +++ b/common-npm-packages/docker-common/make.js @@ -1,13 +1,25 @@ -var path = require('path'); -var util = require('../build-scripts/util'); +const { join } = require('path'); +const { readConfigFile, sys } = require('typescript'); -var buildPath = './_build' +const { cp, mkdirP, rmRF } = require('azure-pipelines-task-lib'); -util.rm('-rf', buildPath) -util.run(path.join(__dirname, 'node_modules/.bin/tsc') + ' --outDir ' + buildPath); +const buildPath = readConfigFile("tsconfig.json", sys.readFile).config.compilerOptions.outDir; -util.cp(path.join(__dirname, 'package.json'), buildPath); -util.cp(path.join(__dirname, 'package-lock.json'), buildPath); -util.cp(path.join(__dirname, 'module.json'), buildPath); -util.cp('-r', 'node_modules', buildPath); -util.cp('-r', 'Strings', buildPath); +function prebuild() { + rmRF(buildPath, { recursive: true, force: true }); +} + +function postbuild() { + mkdirP(join(__dirname, "./_build")); + cp(join(__dirname, 'package.json'), join(buildPath, 'package.json')); + cp(join(__dirname, 'package-lock.json'), join(buildPath, 'package-lock.json')); + cp(join(__dirname, 'module.json'), join(buildPath, 'module.json')); + cp(join(__dirname, 'node_modules'), join(__dirname, buildPath, 'node_modules'), '-rf'); + cp(join(__dirname, 'Strings'), join(__dirname, buildPath, 'Strings'), '-rf'); +} + +if (process.argv.includes('--prebuild')) { + prebuild(); +} else if (process.argv.includes('--postbuild')) { + postbuild(); +} diff --git a/common-npm-packages/docker-common/package-lock.json b/common-npm-packages/docker-common/package-lock.json index 447d8a6e..e351bd58 100644 --- a/common-npm-packages/docker-common/package-lock.json +++ b/common-npm-packages/docker-common/package-lock.json @@ -1,24 +1,25 @@ { "name": "azure-pipelines-tasks-docker-common", - "version": "2.256.2", + "version": "2.260.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "azure-pipelines-tasks-docker-common", - "version": "2.256.2", + "version": "2.260.0", "license": "MIT", "dependencies": { - "@types/mocha": "^5.2.7", - "@types/node": "^10.17.0", - "@types/q": "1.5.4", - "@types/uuid": "^8.3.0", "azure-pipelines-task-lib": "^4.13.0", "azure-pipelines-tasks-azure-arm-rest": "^3.242.2", "del": "2.2.0", "q": "1.4.1" }, "devDependencies": { + "@types/del": "^2.2.33", + "@types/mocha": "^5.2.7", + "@types/node": "^10.17.0", + "@types/q": "1.5.4", + "@types/uuid": "^8.3.0", "typescript": "4.0.2" } }, @@ -31,6 +32,27 @@ "node": ">=0.8.0" } }, + "node_modules/@types/del": { + "version": "2.2.33", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/del/-/del-2.2.33.tgz", + "integrity": "sha1-P76KHD0A6F6WdOSQo0frQZsQA6E=", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/glob": "*" + } + }, + "node_modules/@types/glob": { + "version": "8.1.0", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha1-tj5wFVORsFhNzkTn6iUZC7w48vw=", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, "node_modules/@types/jsonwebtoken": { "version": "8.5.9", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/jsonwebtoken/-/jsonwebtoken-8.5.9.tgz", @@ -40,6 +62,13 @@ "@types/node": "*" } }, + "node_modules/@types/minimatch": { + "version": "5.1.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha1-B1CLRXl8uB7D8nMBGwVM0HVe3co=", + "dev": true, + "license": "MIT" + }, "node_modules/@types/mocha": { "version": "5.2.7", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/mocha/-/mocha-5.2.7.tgz", @@ -62,6 +91,7 @@ "version": "8.3.4", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/uuid/-/uuid-8.3.4.tgz", "integrity": "sha1-vYakNhffBZR4fTi3NfVcgFvs8bw=", + "dev": true, "license": "MIT" }, "node_modules/adm-zip": { @@ -201,9 +231,9 @@ "license": "MIT" }, "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", + "version": "1.1.12", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha1-q5tFRGblqMw6GHvqrVgEEqnFuEM=", "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", @@ -1286,6 +1316,25 @@ "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@azure/msal-common/-/msal-common-13.3.1.tgz", "integrity": "sha1-ASRlv5QNEjddxHOHt1TM+da5IYA=" }, + "@types/del": { + "version": "2.2.33", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/del/-/del-2.2.33.tgz", + "integrity": "sha1-P76KHD0A6F6WdOSQo0frQZsQA6E=", + "dev": true, + "requires": { + "@types/glob": "*" + } + }, + "@types/glob": { + "version": "8.1.0", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/glob/-/glob-8.1.0.tgz", + "integrity": "sha1-tj5wFVORsFhNzkTn6iUZC7w48vw=", + "dev": true, + "requires": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, "@types/jsonwebtoken": { "version": "8.5.9", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/jsonwebtoken/-/jsonwebtoken-8.5.9.tgz", @@ -1294,6 +1343,12 @@ "@types/node": "*" } }, + "@types/minimatch": { + "version": "5.1.2", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha1-B1CLRXl8uB7D8nMBGwVM0HVe3co=", + "dev": true + }, "@types/mocha": { "version": "5.2.7", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/mocha/-/mocha-5.2.7.tgz", @@ -1312,7 +1367,8 @@ "@types/uuid": { "version": "8.3.4", "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/@types/uuid/-/uuid-8.3.4.tgz", - "integrity": "sha1-vYakNhffBZR4fTi3NfVcgFvs8bw=" + "integrity": "sha1-vYakNhffBZR4fTi3NfVcgFvs8bw=", + "dev": true }, "adm-zip": { "version": "0.5.15", @@ -1415,9 +1471,9 @@ "integrity": "sha1-6D46fj8wCzTLnYf2FfoMvzV2kO4=" }, "brace-expansion": { - "version": "1.1.11", - "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", + "version": "1.1.12", + "resolved": "https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha1-q5tFRGblqMw6GHvqrVgEEqnFuEM=", "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" diff --git a/common-npm-packages/docker-common/package.json b/common-npm-packages/docker-common/package.json index 73f6ebb1..6c9b49a5 100644 --- a/common-npm-packages/docker-common/package.json +++ b/common-npm-packages/docker-common/package.json @@ -1,6 +1,6 @@ { "name": "azure-pipelines-tasks-docker-common", - "version": "2.256.2", + "version": "2.260.0", "description": "Common Library for Azure Rest Calls", "repository": { "type": "git", @@ -14,19 +14,22 @@ }, "homepage": "https://github.com/Microsoft/azure-pipelines-tasks-common-packages#readme", "dependencies": { - "@types/mocha": "^5.2.7", - "@types/node": "^10.17.0", - "@types/q": "1.5.4", - "@types/uuid": "^8.3.0", "azure-pipelines-task-lib": "^4.13.0", "azure-pipelines-tasks-azure-arm-rest": "^3.242.2", "del": "2.2.0", "q": "1.4.1" }, "devDependencies": { + "@types/del": "^2.2.33", + "@types/mocha": "^5.2.7", + "@types/node": "^10.17.0", + "@types/q": "1.5.4", + "@types/uuid": "^8.3.0", "typescript": "4.0.2" }, "scripts": { - "build": "cd ../build-scripts && npm install && cd ../docker-common && node make.js" + "prebuild": "node make.js --prebuild", + "build": "npx tsc --project tsconfig.json", + "postbuild": "node make.js --postbuild" } } diff --git a/common-npm-packages/docker-common/pipelineutils.ts b/common-npm-packages/docker-common/pipelineutils.ts index e4ac844b..3b0e0ff0 100644 --- a/common-npm-packages/docker-common/pipelineutils.ts +++ b/common-npm-packages/docker-common/pipelineutils.ts @@ -61,7 +61,7 @@ function addBaseImageLabels(connection: ContainerConnection, labels: string[], d if (digestImageFromFileEnabled) { // using getBaseImageDetialsFromDockerFIle method to fetch both image and imagedigest - const baseImage = containerUtils.getBaseImageDetialsFromDockerFIle(dockerFilePath, connection); + const baseImage = containerUtils.getBaseImageDetialsFromDockerFIle(dockerFilePath, connection)!; if (!baseImage.name) { return; } @@ -97,14 +97,14 @@ function addBaseImageLabels(connection: ContainerConnection, labels: string[], d } } -function getReverseDNSName(): string { +function getReverseDNSName(): string | null { // Hostname part of URL used as prefix for labels. // it is safe to use url.parse on SYSTEM_TEAMFOUNDATIONCOLLECTIONURI here. var teamFoundationCollectionURI = tl.getVariable("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"); if (teamFoundationCollectionURI) { var parsedUrl = URL.parse(teamFoundationCollectionURI); if (parsedUrl) { - var hostName = parsedUrl.hostname.split(".").reverse().join("."); + var hostName = parsedUrl.hostname!.split(".").reverse().join("."); tl.debug(`Reverse DNS name ${hostName}`); return hostName; } @@ -123,7 +123,7 @@ export function getDefaultLabels(addPipelineData?: boolean, addBaseImageData?: b let hostName = getReverseDNSName(); if (hostName) { addCommonLabels(hostName, labels, addPipelineData); - let hostType = tl.getVariable("SYSTEM_HOSTTYPE"); + let hostType = tl.getVariable("SYSTEM_HOSTTYPE")!; if (hostType.toLowerCase() === "build") { addBuildLabels(hostName, labels, addPipelineData); } @@ -134,8 +134,9 @@ export function getDefaultLabels(addPipelineData?: boolean, addBaseImageData?: b if (addBaseImageData) { try { - addBaseImageLabels(connection, labels, dockerFilePath) + addBaseImageLabels(connection!, labels, dockerFilePath!) } catch (error) { + // @ts-ignore tl.debug(`An error ocurred getting the base image lables ${error.message}`); } } diff --git a/common-npm-packages/docker-common/registryauthenticationprovider/acrauthenticationtokenprovider.ts b/common-npm-packages/docker-common/registryauthenticationprovider/acrauthenticationtokenprovider.ts index c2902417..f040ba69 100644 --- a/common-npm-packages/docker-common/registryauthenticationprovider/acrauthenticationtokenprovider.ts +++ b/common-npm-packages/docker-common/registryauthenticationprovider/acrauthenticationtokenprovider.ts @@ -1,24 +1,18 @@ -"use strict"; - -import { ApplicationTokenCredentials } from "azure-pipelines-tasks-azure-arm-rest/azure-arm-common"; -import { AzureRMEndpoint } from "azure-pipelines-tasks-azure-arm-rest/azure-arm-endpoint"; -import * as webClient from "azure-pipelines-tasks-azure-arm-rest/webClient"; -import * as tl from "azure-pipelines-task-lib/task"; +import * as tl from 'azure-pipelines-task-lib/task'; +import { ApplicationTokenCredentials } from 'azure-pipelines-tasks-azure-arm-rest/azure-arm-common'; +import { AzureRMEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azure-arm-endpoint'; +import * as webClient from 'azure-pipelines-tasks-azure-arm-rest/webClient'; import Q = require('q'); -import AuthenticationTokenProvider from "./authenticationtokenprovider"; -import RegistryAuthenticationToken from "./registryauthenticationtoken"; +import AuthenticationTokenProvider from './authenticationtokenprovider'; +import RegistryAuthenticationToken from './registryauthenticationtoken'; export default class ACRAuthenticationTokenProvider extends AuthenticationTokenProvider{ - // URL to registry like jitekuma-microsoft.azurecr.io - private registryURL: string; + private registryURL: string | undefined; // name of the azure subscription endpoint like RMDev - private endpointName: string; - - // ACR fragment like /subscriptions/c00d16c7-6c1f-4c03-9be1-6934a4c49682/resourcegroups/jitekuma-RG/providers/Microsoft.ContainerRegistry/registries/jitekuma - private acrFragmentUrl: string; + private endpointName: string | undefined; constructor(endpointName?: string, registerNameValue?: string) { super(); @@ -28,7 +22,6 @@ export default class ACRAuthenticationTokenProvider extends AuthenticationTokenP tl.debug("Reading the acr registry in old versions"); var obj = JSON.parse(registerNameValue); this.registryURL = obj.loginServer; - this.acrFragmentUrl = obj.id; } catch(e) { tl.debug("Reading the acr registry in kubernetesV1"); @@ -39,11 +32,11 @@ export default class ACRAuthenticationTokenProvider extends AuthenticationTokenP } } - public getAuthenticationToken(): RegistryAuthenticationToken { + public getAuthenticationToken(): RegistryAuthenticationToken | null { if (this.registryURL && this.endpointName) { return new RegistryAuthenticationToken( - tl.getEndpointAuthorizationParameter(this.endpointName, 'serviceprincipalid', true), - tl.getEndpointAuthorizationParameter(this.endpointName, 'serviceprincipalkey', true), + tl.getEndpointAuthorizationParameter(this.endpointName, 'serviceprincipalid', true)!, + tl.getEndpointAuthorizationParameter(this.endpointName, 'serviceprincipalkey', true)!, this.registryURL, "ServicePrincipal@AzureRM", this.getXMetaSourceClient()); @@ -52,17 +45,17 @@ export default class ACRAuthenticationTokenProvider extends AuthenticationTokenP } public async getToken(): Promise { - let authType: string; + let authType: string | null | undefined; try { tl.debug("Attempting to get endpoint authorization scheme..."); - authType = tl.getEndpointAuthorizationScheme(this.endpointName, false); + authType = tl.getEndpointAuthorizationScheme(this.endpointName!, false); } catch (error) { tl.debug("Failed to get endpoint authorization scheme.") } if (!authType) { try { tl.debug("Attempting to get endpoint authorization scheme as an authorization parameter..."); - authType = tl.getEndpointAuthorizationParameter(this.endpointName, "scheme", false); + authType = tl.getEndpointAuthorizationParameter(this.endpointName!, "scheme", false); } catch (error) { tl.debug("Failed to get endpoint authorization scheme as an authorization parameter. Will default authorization scheme to ServicePrincipal."); authType = "ServicePrincipal"; @@ -74,18 +67,18 @@ export default class ACRAuthenticationTokenProvider extends AuthenticationTokenP return await this._getMSIAuthenticationToken(0, 0); } else if (authType === 'WorkloadIdentityFederation') { - const endpoint = await new AzureRMEndpoint(this.endpointName).getEndpoint(); + const endpoint = await new AzureRMEndpoint(this.endpointName!).getEndpoint(); const aadToken = await endpoint.applicationTokenCredentials.getToken(); - let acrToken = await ACRAuthenticationTokenProvider._getACRToken(aadToken, this.endpointName, this.registryURL, 0, 0); + let acrToken = await ACRAuthenticationTokenProvider._getACRToken(aadToken, this.endpointName!, this.registryURL!, 0, 0); return new RegistryAuthenticationToken( "00000000-0000-0000-0000-000000000000", acrToken, - this.registryURL, + this.registryURL!, "WorkloadIdentityFederation@AzureRM", this.getXMetaSourceClient()); } else { - return this.getAuthenticationToken(); + return this.getAuthenticationToken()!; } } diff --git a/common-npm-packages/docker-common/registryauthenticationprovider/authenticationtokenprovider.ts b/common-npm-packages/docker-common/registryauthenticationprovider/authenticationtokenprovider.ts index ddc742e6..ffcb47db 100644 --- a/common-npm-packages/docker-common/registryauthenticationprovider/authenticationtokenprovider.ts +++ b/common-npm-packages/docker-common/registryauthenticationprovider/authenticationtokenprovider.ts @@ -1,17 +1,14 @@ -"use strict"; +import * as tl from 'azure-pipelines-task-lib/task'; -import * as tl from "azure-pipelines-task-lib/task"; -import * as url from "url"; - -import RegistryAuthenticationToken from "./registryauthenticationtoken" +import RegistryAuthenticationToken from './registryauthenticationtoken' export abstract class AuthenticationTokenProvider { // get registry login creds - public abstract getAuthenticationToken(): RegistryAuthenticationToken + public abstract getAuthenticationToken(): RegistryAuthenticationToken | null; protected getXMetaSourceClient(): string { - var serverType = tl.getVariable('System.ServerType'); - return (serverType && serverType.toLowerCase() === "hosted") ? "VSTS" : "TFS"; + var serverType = tl.getVariable('System.ServerType'); + return (serverType && serverType.toLowerCase() === 'hosted') ? 'VSTS' : 'TFS'; } } diff --git a/common-npm-packages/docker-common/registryauthenticationprovider/genericauthenticationtokenprovider.ts b/common-npm-packages/docker-common/registryauthenticationprovider/genericauthenticationtokenprovider.ts index 28e4d363..3ffb8fff 100644 --- a/common-npm-packages/docker-common/registryauthenticationprovider/genericauthenticationtokenprovider.ts +++ b/common-npm-packages/docker-common/registryauthenticationprovider/genericauthenticationtokenprovider.ts @@ -1,27 +1,24 @@ -"use strict"; +import * as tl from 'azure-pipelines-task-lib/task'; -import RegistryAuthenticationToken from "./registryauthenticationtoken" -import AuthenticationTokenProvider from "./authenticationtokenprovider" -import * as tl from "azure-pipelines-task-lib/task"; +import RegistryAuthenticationToken from './registryauthenticationtoken'; +import AuthenticationTokenProvider from './authenticationtokenprovider'; -export default class GenericAuthenticationTokenProvider extends AuthenticationTokenProvider{ +export default class GenericAuthenticationTokenProvider extends AuthenticationTokenProvider { + private registryAuth: { [key: string]: string } = {}; - private registryAuth: { [key: string]: string }; - constructor(endpointName?: string) { super(); - + if(endpointName) { - this.registryAuth = tl.getEndpointAuthorization(endpointName, false).parameters; + this.registryAuth = tl.getEndpointAuthorization(endpointName, false)!.parameters; } } - - public getAuthenticationToken(): RegistryAuthenticationToken { - - if(this.registryAuth) { + + public getAuthenticationToken(): RegistryAuthenticationToken | null { + if (this.registryAuth) { return new RegistryAuthenticationToken(this.registryAuth["username"], this.registryAuth["password"], this.registryAuth["registry"], this.registryAuth["email"], this.getXMetaSourceClient()); } - + return null; } } \ No newline at end of file diff --git a/common-npm-packages/docker-common/registryauthenticationprovider/registryauthenticationtoken.ts b/common-npm-packages/docker-common/registryauthenticationprovider/registryauthenticationtoken.ts index 3a02f813..72002598 100644 --- a/common-npm-packages/docker-common/registryauthenticationprovider/registryauthenticationtoken.ts +++ b/common-npm-packages/docker-common/registryauthenticationprovider/registryauthenticationtoken.ts @@ -1,7 +1,7 @@ -"use strict"; +const util = require('util'); import * as tl from "azure-pipelines-task-lib/task"; -const util = require('util'); + import ACRAuthenticationTokenProvider from "./acrauthenticationtokenprovider" import GenericAuthenticationTokenProvider from "./genericauthenticationtokenprovider"; @@ -55,12 +55,12 @@ export default class RegistryServerAuthenticationToken { } } -export async function getDockerRegistryEndpointAuthenticationToken(endpointId: string): Promise { +export async function getDockerRegistryEndpointAuthenticationToken(endpointId: string): Promise { var registryType = tl.getEndpointDataParameter(endpointId, "registrytype", true); - let authToken: RegistryServerAuthenticationToken; + let authToken: RegistryServerAuthenticationToken | null; if (registryType === "ACR") { - const loginServer = tl.getEndpointAuthorizationParameter(endpointId, "loginServer", false).toLowerCase(); + const loginServer = tl.getEndpointAuthorizationParameter(endpointId, "loginServer", false)!.toLowerCase(); let acrAuthenticationTokenProvider: ACRAuthenticationTokenProvider = new ACRAuthenticationTokenProvider(endpointId, loginServer); authToken = await acrAuthenticationTokenProvider.getToken(); } diff --git a/common-npm-packages/docker-common/sourceutils.ts b/common-npm-packages/docker-common/sourceutils.ts index 56fadda3..c4ce93da 100644 --- a/common-npm-packages/docker-common/sourceutils.ts +++ b/common-npm-packages/docker-common/sourceutils.ts @@ -1,10 +1,9 @@ -"use strict"; - import * as tl from "azure-pipelines-task-lib/task"; + import * as gitUtils from "./gitutils"; export function getSourceTags(): string[] { - var tags: string[]; + var tags: string[] = []; var sourceProvider = tl.getVariable("Build.Repository.Provider"); if (!sourceProvider) { @@ -34,5 +33,5 @@ export function getSourceTags(): string[] { break; } - return tags || []; + return tags; } diff --git a/common-npm-packages/docker-common/tsconfig.json b/common-npm-packages/docker-common/tsconfig.json index e11a18b8..beda9cea 100644 --- a/common-npm-packages/docker-common/tsconfig.json +++ b/common-npm-packages/docker-common/tsconfig.json @@ -3,10 +3,30 @@ "module": "commonjs", "target": "es6", "declaration": true, - "noImplicitAny": false, - "sourceMap": false + "sourceMap": false, + "outDir": "./_build", + "allowJs": true, + "checkJs": true, + "noEmit": false, + "noEmitOnError": false, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "allowUnusedLabels": true, + "allowUnreachableCode": true, + "skipLibCheck": true }, - "exclude": [ - "node_modules" + "include": [ + "./**.ts" ] } \ No newline at end of file