Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Sonar Scanner Not Found In docker container #59

Closed
stand-for-hope opened this issue Jan 12, 2019 · 9 comments
Closed

Sonar Scanner Not Found In docker container #59

stand-for-hope opened this issue Jan 12, 2019 · 9 comments

Comments

@stand-for-hope
Copy link

Hello, recently we tried to use this library to integrate sonar scanner in our application we faced this problem:

  1. We specify "sonarqube-scanner": "^2.1.2" in our package.json file
  2. We run "npm install" in our Dockerfile and this the log infomation:
    image
  3. We go inside the container and follow the path specified "/root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java" we found out that "java" is actually there, and we are so confused why it says it's not found just as the error logs shows above
    Can someone helps us point out the actual reason on this and possible solution to solve this issue? Would be much appreciated for any information:). Thanks.
@bellingard
Copy link
Owner

Have you checked the permissions on the "java" file? What gives you the following command:

ls -al /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/ | grep java

@peh
Copy link

peh commented Feb 14, 2019

I can reproduce that. Manually linking a java binary, that is installed by system tools, just works.

bash-4.4# cd /opt/app
bash-4.4# yarn coverage
yarn run v1.12.3
$ jest && sonar-scanner
 PASS  src/app/__tests__/index.test.js
  ✓ adds 1 + 2 to equal 3 (5ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        9.245s
Ran all test suites.
[09:55:55] Starting SonarQube analysis...
[09:55:55] Checking if executable exists: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
[09:55:55] Could not find executable in "/root/.sonar/native-sonar-scanner".
[09:55:55] Proceed with download of the platform binaries for SonarQube Scanner...
[09:55:55] Creating /root/.sonar/native-sonar-scanner
[09:55:55] Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.2.0.1227-linux.zip
[09:55:55] (executable will be saved in cache folder: /root/.sonar/native-sonar-scanner)
[====================] 100% 0.0s
/root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner: exec: line 66: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java: not found
[09:56:12] ERROR: impossible to download and extract binary: Command failed: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
[09:56:12]        SonarQube Scanner binaries probably don't exist for your OS (linux).
[09:56:12]        In such situation, the best solution is to install the standard SonarQube Scanner (requires a JVM).
[09:56:12]        Check it out at https://redirect.sonarsource.com/doc/install-configure-scanner.html
Done in 41.60s.

bash-4.4# ls -al /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/ | grep java
-rwxr-xr-x 1 root root 7734 Dec 13  2016 java

bash-4.4# /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java
bash: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java: No such file or directory

bash-4.4# rm /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java

bash-4.4# ln -s /usr/bin/java /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/jre/bin/java

bash-4.4# yarn coverage
yarn run v1.12.3
$ jest && sonar-scanner
 PASS  src/app/__tests__/index.test.js
  ✓ adds 1 + 2 to equal 3 (5ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        7.829s
Ran all test suites.
[09:57:30] Starting SonarQube analysis...
[09:57:30] Checking if executable exists: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
[09:57:30] Platform binaries for SonarQube scanner found. Using it.
INFO: Scanner configuration file: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: /opt/app/sonar-project.properties
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_181 Oracle Corporation (64-bit)
INFO: Linux 4.9.93-linuxkit-aufs amd64
INFO: User cache: /root/.sonar/cache
INFO: SonarQube server 7.4.0
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Publish mode
INFO: Load global settings
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 4.188s
INFO: Final Memory: 7M/93M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
child_process.js:632
    throw err;
    ^

Error: Command failed: /root/.sonar/native-sonar-scanner/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner
    at checkExecSyncError (child_process.js:611:11)
    at execFileSync (child_process.js:629:13)
    at sqScannerCommand (/opt/app/node_modules/sonarqube-scanner/dist/index.js:29:5)
    at getSonarQubeScannerExecutable (/opt/app/node_modules/sonarqube-scanner/dist/sonarqube-scanner-executable.js:85:5)
    at scanCLI (/opt/app/node_modules/sonarqube-scanner/dist/index.js:28:3)
    at Object.<anonymous> (/opt/app/node_modules/sonarqube-scanner/dist/bin/sonar-scanner:9:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
bash-4.4#

(I know that the second one is failing because of missing auth, but at this point we know that the java process is running already so this is fine)

@bellingard
Copy link
Owner

Thanks for your comment @peh. It's just unfortunate that such a workaround is required to have it working out of the box. I don't know Docker enough to understand why this fails in the first place, and if someone with a good knowledge could help to sort this out, that'd be awesome.

@peh
Copy link

peh commented Feb 14, 2019

It could actually be a problem with the scanner. I'll investigate that

@peh
Copy link

peh commented Feb 14, 2019

Okay. Investigation found that this is actually a problem of "Alpine". Not really a problem but it's simply not compatible as it's musl based and doesn't support glibc
You need to manually install it

@bellingard
Copy link
Owner

Thanks a lot for the investigation @peh! I will add this to the FAQ.

@peh
Copy link

peh commented Feb 14, 2019

actually an even easier solution is after running sonar-scanner once:

sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' "/root/.sonar/native-sonar-scanner/$(ls -1tr /root/.sonar/native-sonar-scanner/ | head -1)/bin/sonar-scanner"

in all following scanner runs it works as the system java is used.

@fabb fabb mentioned this issue Apr 26, 2021
@mendesbarreto
Copy link

mendesbarreto commented Apr 28, 2021

Okay. Investigation found that this is actually a problem of "Alpine". Not really a problem but it's simply not compatible as it's musl based and doesn't support glibc
You need to manually install it

The link is broken, could you replace it? please =) . I really need this one

@renanvizza-prontmed
Copy link

Okay. Investigation found that this is actually a problem of "Alpine". Not really a problem but it's simply not compatible as it's musl based and doesn't support glibc
You need to manually install it

The link is broken, could you replace it? please =) . I really need this one

https://laptrinhx.com/docker-for-mac-alpine-glibc-issues-802275018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants