codecharta
codecharta copied to clipboard
Analysis Docker container can't reach Sonar container for scanning via `sonar-scanner`
Bug
Expected Behavior
GIVEN our docker-compose setup
WHEN using the analysis container to analyse code with sonar-scanner
THEN it should be able to communicate with the sonar instance provided by our docker-compose on localhost:9000
Actual Behavior
It can't reach the destination.
Screenshots
nonroot-docker-user@82fd9dc17b9d:/$ /usr/local/bin/sonar-scanner
INFO: Scanner configuration file: /usr/local/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Linux 6.5.0-28-generic amd64
INFO: User cache: /home/nonroot-docker-user/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 0.219s
INFO: Final Memory: 3M/54M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 7 more
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
Steps to Reproduce the Problem
-
docker compose pull && docker compose up --detach
-
docker run -it codecharta/codecharta-analysis bash
-
/usr/local/bin/sonar-scanner
Specifications
- CodeCharta Version: unreleased (and probably previous versions)
- OS: tested on ubuntu 22
Due to a syntax error in our analysis
Dockerfile
the current release does not include thesonar-scanner
iirc. This is fixed in #3571 To reproduce this error without the releasedDockerfile
you can (as soon at this PR is merged on main) $ docker compose build && docker compose up --detach