Skip to content

Commit

Permalink
Merge branch 'master' into SAN-6468-ssh-key-bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan219 authored Jun 30, 2017
2 parents b57648e + 58b9700 commit d91b213
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 40 deletions.
22 changes: 15 additions & 7 deletions lib/models/services/cluster-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module.exports = class ClusterConfigService {
clusterCreateId,
repoFullName,
triggeredAction: data.triggeredAction,
shouldNotAutoFork: data.shouldNotAutoFork,
mainInstanceServiceName
}
return ClusterConfigService.createFromRunnableConfig(
Expand Down Expand Up @@ -793,7 +794,7 @@ module.exports = class ClusterConfigService {
inputInstanceOpts.name
)
}
const shouldNotAutofork = keypather.get(parsedInstanceData, 'metadata.name') !== buildOpts.mainInstanceServiceName
const shouldNotAutofork = !(keypather.get(parsedInstanceData, 'metadata.name') === buildOpts.mainInstanceServiceName && !buildOpts.shouldNotAutoFork)
const defaultInstanceOpts = {
// short name is service name
shortName: serviceName,
Expand All @@ -803,7 +804,7 @@ module.exports = class ClusterConfigService {
ipWhitelist: {
enabled: false
},
shouldNotAutofork: shouldNotAutofork,
shouldNotAutofork,
isolated: buildOpts.isolated,
isTesting: testingOpts.isTesting,
isTestReporter: testingOpts.isTestReporter
Expand Down Expand Up @@ -1568,8 +1569,12 @@ module.exports = class ClusterConfigService {
instance, githubPushInfo
})
log.info('called')
return ClusterConfigService.fetchConfigByInstanceId(instance._id)
.then(clusterConfig => {
return Promise.props({
aic: AutoIsolationService.fetchAutoIsolationForInstance(instance._id),
clusterConfig: ClusterConfigService.fetchConfigByInstanceId(instance._id)
})
.then(results => {
const clusterConfig = results.clusterConfig
const currentPaths = clusterConfig.files.map(pluck('path'))
// We found a cluster, so fetch the current one, and see if it changed
return UserService.getByBpId(githubPushInfo.bpUserId)
Expand All @@ -1590,7 +1595,9 @@ module.exports = class ClusterConfigService {
currentPaths
}, 'new compose files')
const diffedShas = difference(newShas, currentShas)
if (diffedShas.length === 0) {
const aic = results.aic
// We want branches to act like they've changed, so they make their own ICC and AIC
if (diffedShas.length === 0 && instance._id.toString() === aic.instance.toString()) {
throw new InputClusterConfig.NotChangedError({
newShas,
currentShas
Expand All @@ -1614,8 +1621,9 @@ module.exports = class ClusterConfigService {
/**
* If you need to do an updateCluster job, use this method. It checks if the compose file has changed
* before creating the job.
* @param {Instance} instance - instance to be updated
* @param {Object} githubPushInfo - parsed githook data
* @param {Instance} instance - instance to be updated
* @param {Object} githubPushInfo - parsed githook data
* @param {String} githubPushInfo.bpUserId - BigPoppa user id
*
* @resolves {undefined}
*
Expand Down
38 changes: 29 additions & 9 deletions lib/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const postSchema = joi.object({
isTesting: joi.boolean().optional(),
testReporters: joi.array().optional(),
githubId: joi.number().optional(),
parentInputClusterConfigId: joi.string().allow('').optional()
parentInputClusterConfigId: joi.string().allow('').optional(),
shouldNotAutoFork: joi.boolean().optional()
}).unknown().required()

const multiPostSchema = joi.object({
Expand Down Expand Up @@ -61,6 +62,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) {
const parentInputClusterConfigId = keypather.get(body, 'parentInputClusterConfigId')
const isTesting = keypather.get(body, 'isTesting')
const testReporters = keypather.get(body, 'testReporters')
const shouldNotAutoFork = keypather.get(body, 'shouldNotAutoFork')
return {
mainInstanceServiceName,
clusterCreateId: uuid(),
Expand All @@ -73,6 +75,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) {
isTesting: isTesting || false,
testReporters: testReporters || [],
clusterName,
shouldNotAutoFork,
parentInputClusterConfigId: parentInputClusterConfigId || ''
}
}
Expand Down Expand Up @@ -119,7 +122,15 @@ const postRoute = function (req, res, next) {
*
* @param {SessionUser} sessionUser - this user
* @param {Object} body - cluster create options
* @resolves {Number} The number of cluster create jobs created
*
* @resolves {Object} results
* {Object[]} results.builds - Clusters created from the owning repo
* {String} results.builds.service - Service name
* {String} results.builds.hash - Random Hash generated for this cluster
* {Object[]} results.externals - Clusters created from github links
* {String} results.externals.service - Service name
* {String} results.externals.hash - Random Hash generated for this cluster
* {Number} results.total - Total number of clusters to be generated
*/
const multiClusterCreate = function (sessionUser, body) {
// First, we need to fetch the file(s), and get all of the mains
Expand All @@ -140,19 +151,28 @@ const multiClusterCreate = function (sessionUser, body) {
// Now that we have the main instances, we need to create clusters for each one.
return Promise.props({
builds: Promise.map(serviceKeys.builds, (buildKey) => {
body.name = generateHashClusterName()
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, buildKey))
const hash = generateHashClusterName()
body.name = hash
return Promise.try(() => {
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, buildKey))
})
.return({ service: buildKey, hash })
}),
externals: Promise.map(serviceKeys.externals, (externalKey) => {
body.name = generateHashClusterName()
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey))
const hash = generateHashClusterName()
body.name = hash
return Promise.try(() => {
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey))
})
.return({ service: externalKey, hash })
})
})
})
.then((results) => {
.tap((results) => {
const buildKeys = results.builds
const externals = results.externals
return buildKeys.length + externals.length
results.total = buildKeys.length + externals.length
log.info(`Created ${results.total} clusters`, { results })
})
}

Expand Down Expand Up @@ -209,7 +229,7 @@ function multiCreateRoute (req, res, next) {

return multiClusterCreate(sessionUser, body)
.then((results) => {
const message = `${results} cluster.create jobs enqueued`
const message = `${results.total} cluster.create jobs enqueued`
return { json: { message, created: results }, status: 202 }
})
.asCallback(responseHandler.bind(null, res, next))
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/instances/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ module.exports.forkInstance = function (req) {
commit: req.body.sha,
user: {
id: req.sessionUser.accounts.github.id
}
},
bpUserId: keypather.get(req.sessionUser, 'bigPoppaUser.id')
}
log.info({
githubPushInfo: githubPushInfo
Expand Down
4 changes: 3 additions & 1 deletion lib/workers/cluster.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports.jobSchema = joi.object({
clusterName: joi.string().required(),
clusterCreateId: joi.string(),
parentInputClusterConfigId: joi.string().allow(''),
testReporters: joi.array()
testReporters: joi.array(),
shouldNotAutoFork: joi.boolean().required()
}).unknown().required()

/**
Expand All @@ -50,6 +51,7 @@ module.exports.task = (job) => {
'clusterCreateId',
'testReporters',
'parentInputClusterConfigId',
'shouldNotAutoFork',
'mainInstanceServiceName'
]
const opts = pick(job, props)
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "api",
"description": "Runnable API Server",
"version": "12.10.2",
"version": "12.10.5",
"repository": {
"type": "git",
"url": "http://github.com/CodeNow/api.git"
Expand Down
Loading

0 comments on commit d91b213

Please sign in to comment.