-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
San 6078 #2029
base: master
Are you sure you want to change the base?
San 6078 #2029
Conversation
* master: (134 commits) Replacing the npm tokens 12.5.1 update model Added catch to prevent keymaker from preventing build process 12.5.0 Revert "Revert "San 6200 add ssh keys"" Remove session user from call Revert "San 6200 add ssh keys" Add a migrate-and-start command Use saveAsync() fix seedVersions for callback remove unused func param add migration stuff into readme fix migrate up again 12.4.3 add migrate-up to start 12.4.2 Added newlines and added comments Still messed up which functions went where Changing invalid mount type. r to ro ...
lib/models/services/image-service.js
Outdated
return portList | ||
} | ||
|
||
ImageService.getImageDataFromJob = function (job) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this method name can be changed. You are not getting image data from any job, you are getting from a particular one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe we don't even need to put it in the service. Can we keep it in to the worker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind keeping this separate since the worker is already bloated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Few minor questions
lib/models/services/image-service.js
Outdated
|
||
ImageService.getImageDataFromJob = function (job) { | ||
const log = ImageService.logger.child({ | ||
method: 'getImageDataFromJob' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add job to log data
lib/models/services/image-service.js
Outdated
return portList | ||
} | ||
|
||
ImageService.getImageDataFromJob = function (job) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe we don't even need to put it in the service. Can we keep it in to the worker?
lib/models/mongo/context-version.js
Outdated
@@ -736,6 +736,10 @@ ContextVersionSchema.statics.updateAndGetSuccessfulBuild = (buildId) => { | |||
} | |||
} | |||
|
|||
if (imageData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a case where we don't get image data? we should always have it here.
lib/models/services/image-service.js
Outdated
@@ -0,0 +1,56 @@ | |||
/** | |||
* @module lib/models/services/image-service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename to docker image service
lib/models/services/image-service.js
Outdated
*/ | ||
'use strict' | ||
|
||
require('loadenv')('models/services/infracode-version-service') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update name
lib/models/services/image-service.js
Outdated
return portList | ||
} | ||
|
||
ImageService.getImageDataFromJob = function (job) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind keeping this separate since the worker is already bloated.
lib/models/services/image-service.js
Outdated
}) | ||
log.info('called') | ||
|
||
let rawImageData = keypather.get(job, 'inspectImageData.Config') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should always exist at this point.
lib/workers/build.container.died.js
Outdated
exposedPorts: joi.array(joi.object({}).unknown()).default([]), | ||
cmd: joi.array(joi.string()).default([]), | ||
entrypoint: joi.array(joi.string()).default([]) | ||
}).default({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm I am not sure about defaulting here. If you then remove all the logic you have checking for null cases.
unit/models/mongo/context-version.js
Outdated
@@ -329,6 +329,36 @@ describe('Context Version Unit Test', function () { | |||
done() | |||
}) | |||
}) | |||
|
|||
it('should save a successful build with image data', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also need unit test for empty / null ports, cmd entryPoint keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there!
@@ -337,11 +337,11 @@ BuildService._buildBuild = function (build, buildInfo, sessionUser) { | |||
* @param {String} buildId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit update jsdoc
@@ -721,7 +721,7 @@ ContextVersionSchema.statics.updateAndGetFailedBuild = (buildId, errorMessage) = | |||
* @param {string} buildId - build id associated with context version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: update jsdoc
lib/workers/build.container.died.js
Outdated
for (let key of Object.keys(ports)) { | ||
splitPort = key.split('/') | ||
|
||
if (splitPort.length === 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not needed. we will always have 2 here
lib/workers/build.container.died.js
Outdated
let rawImageData = keypather.get(job, 'inspectImageData.Config') | ||
return { | ||
port: this._parsePorts(keypather.get(rawImageData, 'ExposedPorts')), | ||
cmd: keypather.get(rawImageData, 'Cmd') || [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove || []
since you default them in the joi.. BUT also double check defaulting in Joi works, not sure we pass the joi data the job here.
|
||
ContextVersion.updateAndGetSuccessfulBuild(buildId, imageData).asCallback(() => { | ||
sinon.assert.calledOnce(ContextVersion.updateByAsync) | ||
sinon.assert.calledWith(ContextVersion.updateByAsync, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible use sinon.assert.calledWithExactly
- which is more strict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to switch it below but this one causes issues.
unit/models/mongo/context-version.js
Outdated
}) | ||
|
||
sinon.assert.calledOnce(ContextVersion.findByAsync) | ||
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible use sinon.assert.calledWithExactly
- which is more strict
|
||
ContextVersion.updateAndGetSuccessfulBuild(buildId, imageData).asCallback(() => { | ||
sinon.assert.calledOnce(ContextVersion.updateByAsync) | ||
sinon.assert.calledWith(ContextVersion.updateByAsync, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible use sinon.assert.calledWithExactly
- which is more strict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to switch it below but this one causes issues.
unit/models/mongo/context-version.js
Outdated
}) | ||
|
||
sinon.assert.calledOnce(ContextVersion.findByAsync) | ||
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible use sinon.assert.calledWithExactly
- which is more strict
Saving the image data on the context version.