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

View File

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