7f1d731dc6
* refactor: config() from mutation to query * refactor(cp-frontend): remove unused dependency * feat(portal-watch): expose getContainers() and compose tags * fix(portal-watch): assert services by name AND hash * feat(portal-data): expose importable and import APIs * fix(portal-data): add missing dependencies * feat(portal-api): expose import/importable * feat(cp-gql-schema): add import/importable * feat(cp-frontend): import existing project * style(portal-watch): lint * style(portal-data): lint * chore: update lockfile
78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const Schema = require('joyent-cp-gql-schema');
|
|
const Graphi = require('graphi');
|
|
const Piloted = require('piloted');
|
|
const PortalData = require('portal-data');
|
|
const PortalWatch = require('portal-watch');
|
|
const Pack = require('../package.json');
|
|
const Resolvers = require('./resolvers');
|
|
|
|
|
|
const internals = {};
|
|
|
|
|
|
module.exports = function (server, options, next) {
|
|
const docker = Piloted.service('docker-compose-api');
|
|
if (docker) {
|
|
options.data.dockerComposeHost = `tcp://${docker.address}:${docker.port}`;
|
|
}
|
|
|
|
const data = new PortalData(options.data);
|
|
const watcher = new PortalWatch(Object.assign(options.watch, {
|
|
data
|
|
}));
|
|
|
|
// watcher <-> watcher
|
|
// portal depends on watcher and vice-versa
|
|
// I'm sure there is a better way to organize this domains
|
|
// but this works for now
|
|
data.setWatcher(watcher);
|
|
|
|
data.on('error', (err) => {
|
|
server.log(['error'], err);
|
|
});
|
|
|
|
data.connect((err) => {
|
|
if (err) {
|
|
return next(err);
|
|
}
|
|
|
|
server.bind(data);
|
|
|
|
Piloted.on('refresh', internals.refresh(data));
|
|
watcher.poll();
|
|
|
|
server.register([
|
|
{
|
|
register: Graphi,
|
|
options: {
|
|
schema: Schema,
|
|
resolvers: Resolvers(data)
|
|
}
|
|
}
|
|
]);
|
|
|
|
next();
|
|
});
|
|
};
|
|
|
|
module.exports.attributes = {
|
|
name: Pack.name,
|
|
version: Pack.version,
|
|
once: true,
|
|
multiple: false
|
|
};
|
|
|
|
|
|
internals.refresh = function (data) {
|
|
return () => {
|
|
const docker = Piloted.service('docker-compose-api');
|
|
if (!docker) {
|
|
return;
|
|
}
|
|
|
|
data.reconnectCompose(`tcp://${docker.address}:${docker.port}`);
|
|
};
|
|
};
|