mirror of
https://github.com/knex/knex.git
synced 2026-01-07 12:37:38 +00:00
* fixes #1833 on postgres * adds @elhigu requested changes * adds test when database is down * adds script for docker support * removes old comment * fixes syntax * fixes more syntax errors * fixes final syntax errors * Docker testing enabled only on linux for now
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
function DockerContainer(docker, name, image, options) {
|
|
this.container = docker.createContainer(name, image, options);
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise}
|
|
*/
|
|
DockerContainer.prototype.start = function () {
|
|
var self = this;
|
|
return self.container.then(function (c) {
|
|
return c.start().then(function () {
|
|
console.log('#~ Started container', c.id);
|
|
return self.waitReady();
|
|
})
|
|
})
|
|
};
|
|
|
|
/**
|
|
* @returns {Promise}
|
|
*/
|
|
DockerContainer.prototype.waitReady = function () {
|
|
return Promise.resolve(this);
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise}
|
|
*/
|
|
DockerContainer.prototype.stop = function () {
|
|
return this.container.then(function (c) {
|
|
return c.stop().then(function () {
|
|
console.log('#~ Stopped container', c.id);
|
|
})
|
|
.catch(function (err) {
|
|
if (err.statusCode !== 304) {
|
|
throw err;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @returns {Promise}
|
|
*/
|
|
DockerContainer.prototype.destroy = function () {
|
|
var self = this;
|
|
return self.stop().then(function () {
|
|
return self.container.then(function (c) {
|
|
return c.remove().then(function () {
|
|
console.log('#~ Removed container', c.id);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = DockerContainer;
|