Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

San 6078 #2029

wants to merge 13 commits into from

Conversation

damienrunnable
Copy link
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
  ...
return portList
}

ImageService.getImageDataFromJob = function (job) {
Copy link
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
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
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.

Copy link
Member

@podviaznikov podviaznikov left a 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


ImageService.getImageDataFromJob = function (job) {
const log = ImageService.logger.child({
method: 'getImageDataFromJob'
Copy link
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

return portList
}

ImageService.getImageDataFromJob = function (job) {
Copy link
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?

@@ -736,6 +736,10 @@ ContextVersionSchema.statics.updateAndGetSuccessfulBuild = (buildId) => {
}
}

if (imageData) {
Copy link
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.

@@ -0,0 +1,56 @@
/**
* @module lib/models/services/image-service
Copy link
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

*/
'use strict'

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

Choose a reason for hiding this comment

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

update name

return portList
}

ImageService.getImageDataFromJob = function (job) {
Copy link
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.

})
log.info('called')

let rawImageData = keypather.get(job, 'inspectImageData.Config')
Copy link
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.

exposedPorts: joi.array(joi.object({}).unknown()).default([]),
cmd: joi.array(joi.string()).default([]),
entrypoint: joi.array(joi.string()).default([])
}).default({
Copy link
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.

@@ -329,6 +329,36 @@ describe('Context Version Unit Test', function () {
done()
})
})

it('should save a successful build with image data', (done) => {
Copy link
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.

Copy link
Contributor

@anandkumarpatel anandkumarpatel left a 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
Copy link
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
Contributor

Choose a reason for hiding this comment

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

nit: update jsdoc

for (let key of Object.keys(ports)) {
splitPort = key.split('/')

if (splitPort.length === 2) {
Copy link
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

let rawImageData = keypather.get(job, 'inspectImageData.Config')
return {
port: this._parsePorts(keypather.get(rawImageData, 'ExposedPorts')),
cmd: keypather.get(rawImageData, 'Cmd') || [],
Copy link
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
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
Contributor Author

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.

})

sinon.assert.calledOnce(ContextVersion.findByAsync)
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId)
Copy link
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
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
Contributor Author

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.

})

sinon.assert.calledOnce(ContextVersion.findByAsync)
sinon.assert.calledWith(ContextVersion.findByAsync, 'build._id', buildId)
Copy link
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 free to 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