Skip to content

San 6078 - #2029

Open
damienrunnable wants to merge 13 commits into
masterfrom
SAN-6078
Open

San 6078#2029
damienrunnable wants to merge 13 commits into
masterfrom
SAN-6078

Conversation

@damienrunnable

Copy link
Copy Markdown
Contributor

Saving the image data on the context version.

* 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
...
Comment threadlib/models/services/image-service.js Outdated
return portList
}

ImageService.getImageDataFromJob = function (job) {

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor

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.

@podviaznikovpodviaznikov left a comment

Copy link
Copy Markdown
Member

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

Comment threadlib/models/services/image-service.js Outdated

ImageService.getImageDataFromJob = function (job) {
const log = ImageService.logger.child({
method: 'getImageDataFromJob'

Copy link
Copy Markdown
Member

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

Comment threadlib/models/services/image-service.js Outdated
return portList
}

ImageService.getImageDataFromJob = function (job) {

Copy link
Copy Markdown
Member

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?

Comment threadlib/models/mongo/context-version.js Outdated
}
}

if (imageData) {

Copy link
Copy Markdown
Contributor

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.

Comment threadlib/models/services/image-service.js Outdated
@@ -0,0 +1,56 @@
/**
* @module lib/models/services/image-service

Copy link
Copy Markdown
Contributor

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

Comment threadlib/models/services/image-service.js Outdated
*/
'use strict'

require('loadenv')('models/services/infracode-version-service')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update name

Comment threadlib/models/services/image-service.js Outdated
return portList
}

ImageService.getImageDataFromJob = function (job) {

Copy link
Copy Markdown
Contributor

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.

Comment threadlib/models/services/image-service.js Outdated
})
log.info('called')

let rawImageData = keypather.get(job, 'inspectImageData.Config')

Copy link
Copy Markdown
Contributor

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.

Comment threadlib/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({

Copy link
Copy Markdown
Contributor

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.

})
})

it('should save a successful build with image data', (done) => {

Copy link
Copy Markdown
Contributor

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.

@anandkumarpatelanandkumarpatel left a comment

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: update jsdoc

Comment threadlib/workers/build.container.died.js Outdated
for (let key of Object.keys(ports)) {
splitPort = key.split('/')

if (splitPort.length === 2) {

Copy link
Copy Markdown
Contributor

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

Comment threadlib/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') || [],

Copy link
Copy Markdown
Contributor

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,

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threadunit/models/mongo/context-version.js Outdated
})

sinon.assert.calledOnce(ContextVersion.findByAsync)
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId)

Copy link
Copy Markdown
Member

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,

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threadunit/models/mongo/context-version.js Outdated
})

sinon.assert.calledOnce(ContextVersion.findByAsync)
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId)

Copy link
Copy Markdown
Member

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

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@damienrunnable@podviaznikov@anandkumarpatel