1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +02:00

chore: update docker files

This commit is contained in:
Sérgio Ramos 2017-07-17 15:45:14 +01:00
parent ee5a071bd9
commit 3ddc156c18
2 changed files with 110 additions and 75 deletions

View File

@ -4,8 +4,8 @@ const Triton = require('triton');
const Url = require('url');
const Path = require('path');
const Fs = require('fs');
const Data = require('portal-api/lib/data');
const Data = require('./lib/data');
const {
DOCKER_HOST,
@ -15,9 +15,7 @@ const {
SDC_KEY_ID
} = process.env;
const DOCKER_HOST_URL = DOCKER_HOST ?
Url.parse(DOCKER_HOST) :
{};
const DOCKER_HOST_URL = DOCKER_HOST ? Url.parse(DOCKER_HOST) : {};
const settings = {
db: {
@ -27,15 +25,15 @@ const settings = {
protocol: 'https',
host: DOCKER_HOST_URL.hostname,
port: DOCKER_HOST_URL.port,
ca: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'ca.pem')) :
undefined,
cert: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'cert.pem')) :
undefined,
key: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'key.pem')) :
undefined
ca: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'ca.pem'))
: undefined,
cert: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'cert.pem'))
: undefined,
key: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'key.pem'))
: undefined
},
triton: {
url: SDC_URL,
@ -55,34 +53,43 @@ const bootstrap = function () {
const data = new Data(settings);
const region = process.env.TRITON_DC || 'us-sw-1';
data.connect((err) => {
data.connect(err => {
ifError(err);
data.createDatacenter({ region, name: region }, (err, datacenter) => {
ifError(err);
Triton.createClient({
Triton.createClient(
{
profile: settings.triton
}, (err, { cloudapi }) => {
},
(err, { cloudapi }) => {
ifError(err);
cloudapi.getAccount((err, { firstName, lastName, email, login }) => {
ifError(err);
data.createUser({ firstName, lastName, email, login }, (err, user) => {
data.createUser(
{ firstName, lastName, email, login },
(err, user) => {
ifError(err);
data.createPortal({
data.createPortal(
{
user,
datacenter
}, (err, portal) => {
},
(err, portal) => {
ifError(err);
console.log('data bootstrapped');
process.exit(0);
}
);
}
);
});
});
});
});
}
);
});
});
};

View File

@ -1,44 +1,61 @@
'use strict';
const Fs = require('fs');
const Path = require('path');
const Brule = require('brule');
const Good = require('good');
const Hapi = require('hapi');
const HapiSwagger = require('hapi-swagger');
const Inert = require('inert');
const Toppsy = require('toppsy');
const Vision = require('vision');
const Pack = require('./package');
const Portal = require('portal-api');
const Portal = require('./lib');
const Path = require('path');
const Fs = require('fs');
const Url = require('url');
const server = new Hapi.Server();
server.connection({ port: process.env.PORT || 3000 });
server.connection({ port: 3000 });
const swaggerOptions = {
info: {
title: 'Portal API Documentation',
version: Pack.version
}
};
const {
DOCKER_HOST,
DOCKER_CERT_PATH,
DOCKER_CLIENT_TIMEOUT,
SDC_URL,
SDC_ACCOUNT,
SDC_KEY_ID
} = process.env;
const DOCKER_HOST_URL = DOCKER_HOST ? Url.parse(DOCKER_HOST) : {};
const portalOptions = {
data: {
db: {
host: process.env.RETHINK_HOST || 'localhost'
},
docker: {
host: DOCKER_HOST,
ca: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'ca.pem')) :
undefined,
cert: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'cert.pem')) :
undefined,
key: DOCKER_CERT_PATH ?
Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'key.pem')) :
undefined,
timeout: DOCKER_CLIENT_TIMEOUT
protocol: 'https',
host: DOCKER_HOST_URL.hostname,
port: DOCKER_HOST_URL.port,
ca: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'ca.pem'))
: undefined,
cert: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'cert.pem'))
: undefined,
key: DOCKER_CERT_PATH
? Fs.readFileSync(Path.join(DOCKER_CERT_PATH, 'key.pem'))
: undefined
},
triton: {
url: SDC_URL,
account: SDC_ACCOUNT,
keyId: SDC_KEY_ID
}
},
watch: {
@ -53,18 +70,25 @@ const goodOptions = {
interval: 1000
},
reporters: {
consoleReporter: [{
consoleReporter: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*', error: '*' }]
}, {
},
{
module: 'good-console'
}, 'stdout']
},
'stdout'
]
}
};
server.register([
server.register(
[
Brule,
Inert,
Vision,
{
register: Good,
options: goodOptions
@ -73,14 +97,18 @@ server.register([
register: Portal,
options: portalOptions
},
{
register: HapiSwagger,
options: swaggerOptions
},
{
register: Toppsy,
options: { namespace: 'portal', subsystem: 'api' }
}
],
(err) => {
err => {
handlerError(err);
server.start((err) => {
server.start(err => {
handlerError(err);
console.log(`server started at http://localhost:${server.info.port}`);
});