newtmitch / docker-sonar-scanner

Quick sonar scanner docker image
MIT License
129 stars 88 forks source link

Issues with Kubernetes #38

Open shankarinece opened 4 years ago

shankarinece commented 4 years ago

Hi, Not able to see the sonar-scanner binary while using the image in Kubernetes environment with jnlp slaves. the directory /usr/local/bin/ doesn't have the binary or the link. The Jenkinsfile looks like the one below. pipeline { agent none stages { stage('SQTest') { agent { kubernetes { label 'sample-app' defaultContainer 'jnlp' yamlFile 'cloudprovider.yaml' } } steps { sh "sonar-scanner -Dproject.settings=testInputs/sonar-project.properties" } } } }

The cloudprovider.yaml has the image newtmitch/sonar-scanner:alpine and command['cat']

Any suggestions? Thanks

newtmitch commented 4 years ago

Sorry, I'm not really familiar enough with Jenkins to make suggestions on how to properly run Sonar in K8S with a Jenkins pipeline.

serut commented 3 years ago

Here is some example of Declarative Pipeline without k8s we use. You can see the entrypoint hack that is a little bit pain in the ***, most of Docker images have a docker-entrypoint.sh that does nothing as entrypoint, not the cli itself.

        stage('Sonar') {
            when {
                expression { BRANCH_NAME ==~ /(master|develop.*|feature.*|V-[0-9]+\.[0-9]+)/ }
            }
            agent {
                docker {
                    reuseNode true
                    image 'newtmitch/sonar-scanner:3.3'
                    args '-e CURRENT_WORKSPACE=${WORKSPACE} --entrypoint='
                }
            }
            steps {
                sh 'TAG=$(${CURRENT_WORKSPACE}/jenkins/nginx/getPackageVersion.sh ${CURRENT_WORKSPACE})'
                sh '/usr/local/bin/sonar-scanner \
                    -Dsonar.projectVersion=${TAG} \
                    -Dsonar.branch.name=${BRANCH_NAME} \
                    -Dsonar.projectBaseDir=/${CURRENT_WORKSPACE} \
                    -Dsonar.host.url=http://sonarserver:9000/'
            }
        }

Jenkins runs the agent.docker.image with the cat cli as args to blocks the image when it boots so we absolutly need to remove the entrypoint. Then Jenkins runs each commands inside the container with full control.
As Jenkins is already in a docker, I need to clone the CURRENT_WORKSPACE var but that's just another layer of complexity not related to this issue. The TAG is computed inside the container using some shell to show we can do everything we want

source : https://github.com/RegardsOss/regards-frontend

newtmitch commented 3 years ago

thanks @serut. I just recently refactored the project a bit and moved the Dockerfile away from the ENTRYPOINT approach and instead went back to a purely CMD-based launch. I have seen the docker-entrypoint.sh approach as well and I haven't done that here yet. I ran across another approach that did this by having the entrypoint script deduce the way to start the underlying binary depending on how it was launched, but I haven't gotten to the point of doing that quite yet.

You might take a look at the images I pushed yesterday and see if those are a bit more copacetic to your needs without the entrypoint hack, see if that helps.

@shankarinece if you can try the new images as well, see if this issue goes away for you then.

serut commented 3 years ago

I can't test, if I'm right your image v4 is for a recent Sonar, and the sonar v3 used the previous one. (a Java compatibily if I remember). So I can't test the image v4 new CMD with my existing sonar :(

newtmitch commented 3 years ago

Ahh, I see. I can build an image the most recent version of 3.x with a CMD-based approach if that helps?

serut commented 3 years ago

It would helps me to test it 👍