Why not running npm test on the docker image generated by skaffold?

148 Views Asked by At

This is the default Jenkinsfile generated by jx

container('nodejs') {
  sh "npm install" #line 2
  sh "CI=true DISPLAY=:99 npm test" #line 3
  sh 'export VERSION=$PREVIEW_VERSION && \
     skaffold build -f skaffold.yaml' #line 4


  sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
}

skaffold build would eventually run docker build and the Dockerfile also has npm install (re-running the same thing as line 2 above)

I understand that npm install at line 2 is to prepare for npm test at line 3. But I am curious why not just run the test on the generated docker file?

container('nodejs') {
  sh 'export VERSION=$PREVIEW_VERSION && \
     skaffold build -f skaffold.yaml'
  sh 'docker run IMAGE_GENERATED_BY_SKAFFOLD npm test'


  sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
}

This way, we don't need to re-execute npm install. Moreover, the environment where npm test were run is exactly similar to the one generated by skaffold.

I am curious, what are the considerations of Jenkins-X team for not doing that?

1

There are 1 best solutions below

0
On

yeah - I guess it depends on the Dockerfile - it could do an npm install or it could just copy the built artefacts into the docker image - in this case though there’s no need to run npm install twice. We should fix up the build pack for npm to avoid the double npm install