95 lines
7.7 KiB
JavaScript
95 lines
7.7 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 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);
|
|
return containerId;
|
|
});
|
|
}
|
|
}
|
|
exports.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