96 lines
7.9 KiB
JavaScript
96 lines
7.9 KiB
JavaScript
"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 buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} .`;
|
|
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 ' + this.buildTag + ' 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 npmci_test_image sh /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);
|
|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