| 
									
										
										
										
											2016-06-04 23:20:39 +02:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | 
					
						
							|  |  |  |     return new (P || (P = Promise))(function (resolve, reject) { | 
					
						
							|  |  |  |         function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | 
					
						
							|  |  |  |         function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | 
					
						
							|  |  |  |         function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | 
					
						
							|  |  |  |         step((generator = generator.apply(thisArg, _arguments || [])).next()); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | Object.defineProperty(exports, "__esModule", { value: true }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  | const plugins = require("./npmci.plugins"); | 
					
						
							|  |  |  | const paths = require("./npmci.paths"); | 
					
						
							|  |  |  | const NpmciEnv = require("./npmci.env"); | 
					
						
							|  |  |  | const npmci_bash_1 = require("./npmci.bash"); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * builds a cwd of Dockerfiles by triggering a promisechain | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.build = () => __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |     yield exports.readDockerfiles() | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |         .then(exports.sortDockerfiles) | 
					
						
							|  |  |  |         .then(exports.mapDockerfiles) | 
					
						
							| 
									
										
										
										
											2016-06-05 16:43:27 +02:00
										 |  |  |         .then(exports.buildDockerfiles) | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         .then(exports.pushDockerfiles); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * creates instance of class Dockerfile for all Dockerfiles in cwd | 
					
						
							|  |  |  |  * @returns Promise<Dockerfile[]> | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.readDockerfiles = () => __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |     let fileTree = yield plugins.smartfile.fs.listFileTree(paths.cwd, './Dockerfile*'); | 
					
						
							|  |  |  |     // create the Dockerfile array
 | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let readDockerfilesArray = []; | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     for (let dockerfilePath of fileTree) { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |         let myDockerfile = new Dockerfile({ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |             filePath: dockerfilePath, | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |             read: true | 
					
						
							| 
									
										
										
										
											2016-06-05 05:16:14 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  |         readDockerfilesArray.push(myDockerfile); | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     return readDockerfilesArray; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * sorts Dockerfiles into a dependency chain | 
					
						
							|  |  |  |  * @param sortableArrayArg an array of instances of class Dockerfile | 
					
						
							|  |  |  |  * @returns Promise<Dockerfile[]> | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.sortDockerfiles = (sortableArrayArg) => { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let done = plugins.q.defer(); | 
					
						
							|  |  |  |     let sortedArray = []; | 
					
						
							|  |  |  |     let cleanTagsOriginal = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray); | 
					
						
							|  |  |  |     let sorterFunctionCounter = 0; | 
					
						
							|  |  |  |     let sorterFunction = function () { | 
					
						
							|  |  |  |         sortableArrayArg.forEach((dockerfileArg) => { | 
					
						
							|  |  |  |             let cleanTags = exports.cleanTagsArrayFunction(sortableArrayArg, sortedArray); | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |             if (cleanTags.indexOf(dockerfileArg.baseImage) === -1 && sortedArray.indexOf(dockerfileArg) === -1) { | 
					
						
							| 
									
										
										
										
											2016-06-05 11:08:20 +02:00
										 |  |  |                 sortedArray.push(dockerfileArg); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-06-07 06:05:13 +02:00
										 |  |  |             ; | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |             if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) { | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |                 dockerfileArg.localBaseImageDependent = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             ; | 
					
						
							| 
									
										
										
										
											2016-06-05 06:20:05 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         if (sortableArrayArg.length === sortedArray.length) { | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  |             done.resolve(sortedArray); | 
					
						
							| 
									
										
										
										
											2016-06-05 06:20:05 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-06-05 13:50:45 +02:00
										 |  |  |         else if (sorterFunctionCounter < 10) { | 
					
						
							| 
									
										
										
										
											2016-06-05 11:08:20 +02:00
										 |  |  |             sorterFunctionCounter++; | 
					
						
							|  |  |  |             sorterFunction(); | 
					
						
							| 
									
										
										
										
											2016-06-05 06:20:05 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-06-05 11:08:20 +02:00
										 |  |  |         ; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     sorterFunction(); | 
					
						
							| 
									
										
										
										
											2016-06-05 06:20:05 +02:00
										 |  |  |     return done.promise; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * maps local Dockerfiles dependencies to the correspoding Dockerfile class instances | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.mapDockerfiles = (sortedArray) => __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     sortedArray.forEach((dockerfileArg) => { | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |         if (dockerfileArg.localBaseImageDependent) { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |             sortedArray.forEach((dockfile2) => { | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |                 if (dockfile2.cleanTag === dockerfileArg.baseImage) { | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |                     dockerfileArg.localBaseDockerfile = dockfile2; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         ; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     return sortedArray; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * builds the correspoding real docker image for each Dockerfile class instance | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.buildDockerfiles = (sortedArrayArg) => __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     for (let dockerfileArg of sortedArrayArg) { | 
					
						
							|  |  |  |         yield dockerfileArg.build(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     return sortedArrayArg; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * pushes the real Dockerfile images to a Docker registry | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.pushDockerfiles = (sortedArrayArg) => __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     for (let dockerfileArg of sortedArrayArg) { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         yield dockerfileArg.push(NpmciEnv.buildStage); | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     return sortedArrayArg; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * pulls corresponding real Docker images for instances of Dockerfile from a registry. | 
					
						
							|  |  |  |  * This is needed if building, testing, and publishing of Docker images is carried out in seperate CI stages. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.pullDockerfileImages = (sortableArrayArg, registryArg = 'registry.gitlab.com') => __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     for (let dockerfileArg of sortableArrayArg) { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         yield dockerfileArg.pull(registryArg); | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     return sortableArrayArg; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * tests all Dockerfiles in by calling class Dockerfile.test(); | 
					
						
							|  |  |  |  * @param sortedArrayArg Dockerfile[] that contains all Dockerfiles in cwd | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.testDockerfiles = (sortedArrayArg) => __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     for (let dockerfileArg of sortedArrayArg) { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         yield dockerfileArg.test(); | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |     return sortedArrayArg; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * class Dockerfile represents a Dockerfile on disk in npmci | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  | class Dockerfile { | 
					
						
							|  |  |  |     constructor(options) { | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |         this.filePath = options.filePath; | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         this.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo; | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  |         this.version = exports.dockerFileVersion(plugins.path.parse(options.filePath).base); | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         this.cleanTag = this.repo + ':' + this.version; | 
					
						
							| 
									
										
										
										
											2016-06-07 19:41:14 +02:00
										 |  |  |         this.buildTag = this.cleanTag; | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |         this.gitlabTestTag = exports.dockerTag('registry.gitlab.com', this.repo, this.version, 'test'); | 
					
						
							|  |  |  |         this.gitlabReleaseTag = exports.dockerTag('registry.gitlab.com', this.repo, this.version); | 
					
						
							| 
									
										
										
										
											2016-06-07 19:41:14 +02:00
										 |  |  |         this.releaseTag = exports.dockerTag(NpmciEnv.dockerRegistry, this.repo, this.version); | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         this.containerName = 'dockerfile-' + this.version; | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |         if (options.filePath && options.read) { | 
					
						
							| 
									
										
										
										
											2016-06-23 22:22:03 +02:00
										 |  |  |             this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath)); | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         ; | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  |         this.baseImage = exports.dockerBaseImage(this.content); | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |         this.localBaseImageDependent = false; | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * builds the Dockerfile | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     build() { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         return __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |             plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag); | 
					
						
							|  |  |  |             yield npmci_bash_1.bashBare('docker build -t ' + this.buildTag + ' -f ' + this.filePath + ' .'); | 
					
						
							|  |  |  |             NpmciEnv.dockerFilesBuilt.push(this); | 
					
						
							| 
									
										
										
										
											2017-03-11 02:27:48 +01:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * pushes the Dockerfile to a registry | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     push(stageArg) { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         return __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |             switch (stageArg) { | 
					
						
							|  |  |  |                 case 'release': | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |                     yield npmci_bash_1.bashBare(`docker tag ${this.buildTag} ${this.releaseTag}`); | 
					
						
							|  |  |  |                     yield npmci_bash_1.bashBare(`docker push ${this.releaseTag}`); | 
					
						
							|  |  |  |                     // if release registry is different from gitlab
 | 
					
						
							|  |  |  |                     if (NpmciEnv.dockerRegistry !== 'registry.gitlab.com') { | 
					
						
							|  |  |  |                         yield npmci_bash_1.bashBare(`docker tag ${this.buildTag} ${this.gitlabReleaseTag}`); | 
					
						
							|  |  |  |                         yield npmci_bash_1.bashBare(`docker push ${this.gitlabReleaseTag}`); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |                     break; | 
					
						
							|  |  |  |                 case 'test': | 
					
						
							|  |  |  |                 default: | 
					
						
							| 
									
										
										
										
											2017-04-02 23:56:15 +02:00
										 |  |  |                     yield npmci_bash_1.bashBare(`docker tag ${this.buildTag} ${this.gitlabTestTag}`); | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |                     yield npmci_bash_1.bashBare(`docker push ${this.gitlabTestTag}`); | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |                     break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |     ; | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * pulls the Dockerfile from a registry | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     pull(registryArg) { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         return __awaiter(this, void 0, void 0, function* () { | 
					
						
							| 
									
										
										
										
											2017-04-02 22:56:40 +02:00
										 |  |  |             let pullTag = this.gitlabTestTag; | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |             yield npmci_bash_1.bashBare('docker pull ' + pullTag); | 
					
						
							|  |  |  |             yield npmci_bash_1.bashBare('docker tag ' + pullTag + ' ' + this.buildTag); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-07 03:59:47 +02:00
										 |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * tests the Dockerfile; | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     test() { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         return __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |             let testFile = plugins.path.join(paths.NpmciTestDir, 'test_' + this.version + '.sh'); | 
					
						
							|  |  |  |             let testFileExists = plugins.smartfile.fs.fileExistsSync(testFile); | 
					
						
							|  |  |  |             if (testFileExists) { | 
					
						
							|  |  |  |                 // run tests
 | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker run --name npmci_test_container ' + this.buildTag + ' mkdir /npmci_test'); | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker cp ' + testFile + ' npmci_test_container:/npmci_test/test.sh'); | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker commit npmci_test_container npmci_test_image'); | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker run npmci_test_image sh /npmci_test/test.sh'); | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker rm npmci_test_container'); | 
					
						
							|  |  |  |                 yield npmci_bash_1.bashBare('docker rmi --force npmci_test_image'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 plugins.beautylog.warn('skipping tests for ' + this.cleanTag + ' because no testfile was found!'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-07 03:59:47 +02:00
										 |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * gets the id of a Dockerfile | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     getId() { | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |         return __awaiter(this, void 0, void 0, function* () { | 
					
						
							|  |  |  |             let containerId = yield npmci_bash_1.bashBare('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag); | 
					
						
							|  |  |  |             return containerId; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-07 03:59:47 +02:00
										 |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  | exports.Dockerfile = Dockerfile; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  |  * returns a version for a docker file | 
					
						
							|  |  |  |  * @execution SYNC | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-11 01:10:37 +01:00
										 |  |  | exports.dockerFileVersion = (dockerfileNameArg) => { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let versionString; | 
					
						
							|  |  |  |     let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/; | 
					
						
							|  |  |  |     let regexResultArray = versionRegex.exec(dockerfileNameArg); | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |     if (regexResultArray && regexResultArray.length === 2) { | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |         versionString = regexResultArray[1]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         versionString = 'latest'; | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     return versionString; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-05 13:01:45 +02:00
										 |  |  | exports.dockerBaseImage = function (dockerfileContentArg) { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/; | 
					
						
							|  |  |  |     let regexResultArray = baseImageRegex.exec(dockerfileContentArg); | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     return regexResultArray[1]; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-07 19:41:14 +02:00
										 |  |  | exports.dockerTag = function (registryArg, repoArg, versionArg, suffixArg) { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let tagString; | 
					
						
							|  |  |  |     let registry = registryArg; | 
					
						
							|  |  |  |     let repo = repoArg; | 
					
						
							|  |  |  |     let version = versionArg; | 
					
						
							| 
									
										
										
										
											2016-06-07 19:41:14 +02:00
										 |  |  |     if (suffixArg) { | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         version = versionArg + '_' + suffixArg; | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-07 19:41:14 +02:00
										 |  |  |     ; | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |     tagString = registry + '/' + repo + ':' + version; | 
					
						
							| 
									
										
										
										
											2016-06-05 04:48:39 +02:00
										 |  |  |     return tagString; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-04 17:56:56 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  | exports.cleanTagsArrayFunction = function (dockerfileArrayArg, trackingArrayArg) { | 
					
						
							| 
									
										
										
										
											2016-07-18 16:56:53 +02:00
										 |  |  |     let cleanTagsArray = []; | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |     dockerfileArrayArg.forEach(function (dockerfileArg) { | 
					
						
							| 
									
										
										
										
											2016-11-24 23:21:40 +01:00
										 |  |  |         if (trackingArrayArg.indexOf(dockerfileArg) === -1) { | 
					
						
							| 
									
										
										
										
											2016-06-05 14:27:56 +02:00
										 |  |  |             cleanTagsArray.push(dockerfileArg.cleanTag); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     return cleanTagsArray; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-04-02 23:56:15 +02:00
										 |  |  | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtY2kuYnVpbGQuZG9ja2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtY2kuYnVpbGQuZG9ja2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSwyQ0FBMEM7QUFDMUMsdUNBQXNDO0FBQ3RDLHdDQUF1QztBQUN2Qyw2Q0FBdUM7QUFFdkM7O0dBRUc7QUFDUSxRQUFBLEtBQUssR0FBRztJQUNqQixNQUFNLHVCQUFlLEVBQUU7U0FDcEIsSUFBSSxDQUFDLHVCQUFlLENBQUM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