How do we install npm pdf-parse library in jenkins docker container

Viewed 123

While running the Cypress tests on jenkins, I am getting the below error. Our jenkins is integrated with Docker container and devs asked me to install the pdf-parse library in docker container which will solve the issue. How do I install pdf-parse in docker container, which file does that ? Could some one please advise ?

Note: I am unable to see a docker file in my project root directory

11:38:29  Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.
11:38:29  
11:38:29  Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
11:38:29  
11:38:29   Error: Cannot find module 'pdf-parse'

docker file:

FROM cypress/browsers:node12.14.1-chrome85-ff81

COPY package.json .
COPY package-lock.json .
RUN npm install --save-dev cypress
RUN $(npm bin)/cypress verify

# there is a built-in user "node" that comes from the very base Docker Node image
# we are going to recreate this user and give it _same id_ as external user
# that is going to run this container.
ARG USER_ID=501
ARG GROUP_ID=999

# if you want to see all existing groups uncomment the next command
# RUN cat /etc/group

RUN groupadd -g ${GROUP_ID} appuser
# do not log creating new user, otherwise there could be a lot of messages
RUN useradd -r --no-log-init -u ${USER_ID} -g appuser appuser
RUN install -d -m 0755 -o appuser -g appuser /home/appuser

# move test runner binary folder to the non-root's user home directory
RUN mv /root/.cache /home/appuser/.cache

USER appuser

jenkins file:

 pipeline {
      agent {
        docker {
          image 'abcdtest'
          args '--link postgres:postgres  -v /.composer:/.composer'
        }
      }
      options {
        ansiColor('xterm')
      }
      stages {
        stage("print env variables") {
          steps {
            script {
              echo sh(script: 'env|sort', returnStdout: true)
            }
          }
        }
        stage("composer install") {
          steps {
            script {
                
                withCredentials([usernamePassword(credentialsId: 'bitbucket-api', passwordVariable: 'bitbucketPassword', usernameVariable: 'bitbucketUsername')]) {
                    def authProperties = readJSON file: 'auth.json.dist'
                    authProperties['http-basic']['bitbucket.sometest.com']['username'] = bitbucketUsername
                    authProperties['http-basic']['bitbucket.sometest.com']['password'] = bitbucketPassword
                    writeJSON file: 'auth.json', json: authProperties
                }
            }
            sh 'php composer.phar install --prefer-dist --no-progress'
          }
        }
        stage('unit tests') {
          steps {
            lock('ABCD Unit Tests') {
              script {
                try {
                  sh 'mv codeception.yml.dist codeception.yml'
                  sh 'mv tests/unit.suite.yml.jenkins tests/unit.suite.yml'
                  sh 'php vendor/bin/codecept run tests/unit --html'
                }
                catch (err) {
                  echo "unit tests step failed"
                  currentBuild.result = 'FAILURE'
                }
                finally {
                  publishHTML (target: [
                    allowMissing: false,
                    alwaysLinkToLastBuild: false,
                    keepAll: true,
                    reportDir: 'tests/_output/',
                    reportFiles: 'report.html',
                    reportName: "Unit Tests Report"
                  ])
                }
              }
            }
          }
        }
      }
      post {
        success {
          slackSend color: 'good', channel: '#jenkins-abcdtest-ci', message: "*SUCCESSED* - CI passed successfully for *${env.BRANCH_NAME}* (<${env.BUILD_URL}|build ${env.BUILD_NUMBER}>)"
        }
        failure {
          slackSend color: 'danger', channel: '#jenkins-abcdtest-ci', message: "*FAILED* - CI failed for *${env.BRANCH_NAME}* (<${env.BUILD_URL}|build ${env.BUILD_NUMBER}> - <${env.BUILD_URL}console|click here to see the console output>)"
        }
      }
    }
1 Answers

I suppose you use cypress/base:10 as the image to new a container in jenkins. If you don't have dockerfile, you may have to write your own dockerfile extends from cypress/base:10.

Dockerfile:

FROM cypress/base:10
RUN npm install pdf-parse

Then, docker build -t mycypress ., docker push mycypress to push the image to dockerhub(You may need an account) to let your jenkins use your new image to setup container.

NOTE: you will have to find how your project choose image to start your container, with this, you can find suitable way to install pdf-parse. One possible maybe next:

pipeline {
    agent {
        docker { image 'cypress/base:10' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Then, you may change docker { image 'cypress/base:10' } to docker { image 'mycypress' }.

Related