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

feat: CNS env variables (#675)

This commit is contained in:
Sérgio Ramos 2017-09-13 20:32:32 +01:00 committed by Wyatt Preul
parent e70d80425a
commit 3b427871cf
8 changed files with 139 additions and 63 deletions

View File

@ -83,51 +83,57 @@ const bootstrap = function ({ docker, rethink }, cb) {
return cb();
}
data.createDatacenter({ region, name: region }, (err, datacenter) => {
data.createDatacenter({
region,
name: region
}, (err, datacenter) => {
if (err) {
return cb(err);
}
Triton.createClient(
{
profile: settings.triton
},
(err, { cloudapi }) => {
Triton.createClient({
profile: settings.triton
}, (err, { cloudapi }) => {
if (err) {
return cb(err);
}
cloudapi.getAccount((err, {
id,
firstName,
lastName,
email,
login
}) => {
if (err) {
return cb(err);
}
cloudapi.getAccount((err, { firstName, lastName, email, login }) => {
data.createUser({
tritonId: id,
firstName,
lastName,
email,
login
}, (err, user) => {
if (err) {
return cb(err);
}
data.createUser(
{ firstName, lastName, email, login },
(err, user) => {
if (err) {
return cb(err);
}
data.createPortal(
{
user,
datacenter
},
(err, portal) => {
if (err) {
return cb(err);
}
console.log('data bootstrapped');
cb();
}
);
data.createPortal({
user,
datacenter
}, (err, portal) => {
if (err) {
return cb(err);
}
);
console.log('data bootstrapped');
cb();
});
});
}
);
});
});
});
});
});

View File

@ -1,6 +1,6 @@
{
"name": "joyent-cp-frontend",
"version": "1.3.2",
"version": "1.4.0",
"license": "MPL-2.0",
"repository": "github:yldio/joyent-portal",
"main": "build/",

View File

@ -5,6 +5,7 @@ import { withRouter } from 'react-router';
import { Redirect } from 'react-router-dom';
import intercept from 'apr-intercept';
import paramCase from 'param-case';
import get from 'lodash.get';
import remove from 'lodash.remove';
import flatten from 'lodash.flatten';
import uniq from 'lodash.uniq';
@ -17,12 +18,15 @@ import DeploymentGroupBySlugQuery from '@graphql/DeploymentGroupBySlug.gql';
import DeploymentGroupCreateMutation from '@graphql/DeploymentGroupCreate.gql';
import DeploymentGroupProvisionMutation from '@graphql/DeploymentGroupProvision.gql';
import DeploymentGroupConfigQuery from '@graphql/DeploymentGroupConfig.gql';
import PortalQuery from '@graphql/Portal.gql';
import { client } from '@state/store';
import { ErrorMessage } from '@components/messaging';
import { Environment, Name, Review, Manifest } from '@components/manifest';
const INTERPOLATE_REGEX = /\$([_a-z][_a-z0-9]*)/gi;
const CNS_PRIVATE = 'TRITON_CNS_SEARCH_DOMAIN_PRIVATE';
const CNS_PUBLIC = 'TRITON_CNS_SEARCH_DOMAIN_PUBLIC';
// TODO: move state to redux. why: because in redux we can cache transactional
// state between refreshes
@ -166,15 +170,22 @@ class DeploymentGroupEditOrCreate extends Component {
return environment;
}
const names = forceArray(manifest.match(INTERPOLATE_REGEX)).map(name =>
name.replace(/^\$/, '')
);
const searchDomain = [
`${CNS_PRIVATE}=${this.props.tritonId}.${this.props
.dataCenter}.cns.joyent.com`,
`${CNS_PUBLIC}=${this.props.tritonId}.${this.props
.dataCenter}.triton.zone`
].join('\n');
const names = forceArray(manifest.match(INTERPOLATE_REGEX))
.map(name => name.replace(/^\$/, ''))
.filter(name => [CNS_PRIVATE, CNS_PUBLIC].indexOf(name) < 0);
const vars = uniq(names)
.map(name => `\n${name}=`)
.join('');
return `# define your interpolatable variables here\n${vars}`;
return `${searchDomain}\n\n# define your interpolatable variables here\n${vars}`;
}
getDefaultFile(name = '') {
@ -317,7 +328,10 @@ class DeploymentGroupEditOrCreate extends Component {
};
this.setState(
{ environment: environment || this.props.environment, loading: true },
{
environment: environment || this.getEnvironmentDefaultValue(),
loading: true
},
getConfig
);
}
@ -480,6 +494,12 @@ class DeploymentGroupEditOrCreate extends Component {
}
export default compose(
graphql(PortalQuery, {
props: ({ data: { portal = {} } }) => ({
dataCenter: get(portal, 'datacenter.region', ''),
tritonId: get(portal, 'user.tritonId', '')
})
}),
graphql(DeploymentGroupCreateMutation, {
props: ({ mutate }) => ({
createDeploymentGroup: variables => mutate({ variables })

View File

@ -2,6 +2,7 @@ query Portal {
portal {
user {
firstName
tritonId
}
datacenter {
id

View File

@ -7,6 +7,7 @@ type Portal {
type User {
id: ID!
tritonId: ID!
firstName: String!
lastName: String!
email: String!

View File

@ -49,36 +49,77 @@ const ifError = function (err) {
console.error(err);
process.exit(1);
}
process.exit(0);
};
const bootstrap = function () {
const bootstrap = function (cb) {
const data = new Data(settings);
const region = process.env.TRITON_DC || 'us-sw-1';
data.connect((err) => {
ifError(err);
if (err) {
return cb(err);
}
data.createDatacenter({ region, name: region }, (err, datacenter) => {
ifError(err);
data.getDatacenters((err, datacenters) => {
if (err) {
return cb(err);
}
Triton.createClient({
profile: settings.triton
}, (err, { cloudapi }) => {
ifError(err);
// Don't continue since data is already bootstrapped
if (datacenters && datacenters.length) {
return cb();
}
cloudapi.getAccount((err, { firstName, lastName, email, login }) => {
ifError(err);
data.createDatacenter({
region,
name: region
}, (err, datacenter) => {
if (err) {
return cb(err);
}
data.createUser({ firstName, lastName, email, login }, (err, user) => {
ifError(err);
Triton.createClient({
profile: settings.triton
}, (err, { cloudapi }) => {
if (err) {
return cb(err);
}
data.createPortal({
user,
datacenter
}, (err, portal) => {
ifError(err);
console.log('data bootstrapped');
process.exit(0);
cloudapi.getAccount((err, {
id,
firstName,
lastName,
email,
login
}) => {
if (err) {
return cb(err);
}
data.createUser({
tritonId: id,
firstName,
lastName,
email,
login
}, (err, user) => {
if (err) {
return cb(err);
}
data.createPortal({
user,
datacenter
}, (err, portal) => {
if (err) {
return cb(err);
}
console.log('data bootstrapped');
cb();
});
});
});
});
@ -87,4 +128,4 @@ const bootstrap = function () {
});
};
bootstrap();
bootstrap(ifError);

View File

@ -201,6 +201,7 @@ exports.toInstance = function (clientInstance) {
exports.fromUser = function (user) {
return {
id: user.id,
tritonId: user.tritonId,
firstName: user.first_name,
lastName: user.last_name,
email: user.email,
@ -211,6 +212,7 @@ exports.fromUser = function (user) {
exports.toUser = function (clientUser) {
return {
id: clientUser.id,
tritonId: clientUser.tritonId,
first_name: clientUser.firstName,
last_name: clientUser.lastName,
email: clientUser.email,

View File

@ -23,7 +23,11 @@ const goodOptions = {
consoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*', error: '*' }]
args: [{
log: '*',
response: '*',
error: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
@ -39,17 +43,18 @@ server.register([
},
{
register: Toppsy,
options: { namespace: 'portal', subsystem: 'api' }
options: {
namespace: 'portal',
subsystem: 'api'
}
}
],
(err) => {
], (err) => {
handlerError(err);
server.start((err) => {
handlerError(err);
console.log(`server started at http://localhost:${server.info.port}`);
});
}
);
});
function handlerError (error) {
if (error) {