"use strict"; 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 }); const plugins = require("./mod.plugins"); const NpmciEnv = require("../npmci.env"); const npmci_bash_1 = require("../npmci.bash"); const paths = require("../npmci.paths"); const helpers = require("./mod.helpers"); /** * class Dockerfile represents a Dockerfile on disk in npmci */ class Dockerfile { constructor(options) { this.filePath = options.filePath; this.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo; this.version = helpers.dockerFileVersion(plugins.path.parse(options.filePath).base); this.cleanTag = this.repo + ':' + this.version; this.buildTag = this.cleanTag; this.containerName = 'dockerfile-' + this.version; if (options.filePath && options.read) { this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath)); } this.baseImage = helpers.dockerBaseImage(this.content); this.localBaseImageDependent = false; } /** * builds the Dockerfile */ build() { return __awaiter(this, void 0, void 0, function* () { plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag); let buildArgsString = yield helpers.getDockerBuildArgs(); let buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} ${buildArgsString} .`; yield npmci_bash_1.bash(buildCommand); return; }); } /** * pushes the Dockerfile to a registry */ push(dockerRegistryArg, versionSuffix = null) { return __awaiter(this, void 0, void 0, function* () { let pushTag = helpers.getDockerTagString(dockerRegistryArg.registryUrl, this.repo, this.version, versionSuffix); yield npmci_bash_1.bash(`docker tag ${this.buildTag} ${pushTag}`); yield npmci_bash_1.bash(`docker push ${pushTag}`); }); } /** * pulls the Dockerfile from a registry */ pull(registryArg, versionSuffixArg = null) { return __awaiter(this, void 0, void 0, function* () { let pullTag = helpers.getDockerTagString(registryArg.registryUrl, this.repo, this.version, versionSuffixArg); yield npmci_bash_1.bash(`docker pull ${pullTag}`); yield npmci_bash_1.bash(`docker tag ${pullTag} ${this.buildTag}`); }); } /** * tests the Dockerfile; */ test() { 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.bash(`docker run --name npmci_test_container --entrypoint="bash" ${this.buildTag} -c "mkdir /npmci_test"`); yield npmci_bash_1.bash(`docker cp ${testFile} npmci_test_container:/npmci_test/test.sh`); yield npmci_bash_1.bash(`docker commit npmci_test_container npmci_test_image`); yield npmci_bash_1.bash(`docker run --entrypoint="bash" npmci_test_image -x /npmci_test/test.sh`); yield npmci_bash_1.bash(`docker rm npmci_test_container`); yield npmci_bash_1.bash(`docker rmi --force npmci_test_image`); } else { plugins.beautylog.warn('skipping tests for ' + this.cleanTag + ' because no testfile was found!'); } }); } /** * gets the id of a Dockerfile */ getId() { return __awaiter(this, void 0, void 0, function* () { let containerId = yield npmci_bash_1.bash('docker inspect --type=image --format="{{.Id}}" ' + this.buildTag); return containerId; }); } } exports.Dockerfile = Dockerfile; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW9kLmNsYXNzZXMuZG9ja2VyZmlsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3RzL21vZF9kb2NrZXIvbW9kLmNsYXNzZXMuZG9ja2VyZmlsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEseUNBQXlDO0FBQ3pDLHlDQUF5QztBQUN6Qyw4Q0FBcUM7QUFDckMsd0NBQXdDO0FBR3hDLHlDQUF5QztBQUV6Qzs7R0FFRztBQUNIO0lBV0UsWUFBWSxPQUE4RTtRQUN4RixJQUFJLENBQUMsUUFBUSx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