Skip to content

Instantly share code, notes, and snippets.

@dianjuar
Created February 6, 2022 07:16
Show Gist options
  • Save dianjuar/c58bdb6d0a6c752d5acde6b91e27f036 to your computer and use it in GitHub Desktop.
Save dianjuar/c58bdb6d0a6c752d5acde6b91e27f036 to your computer and use it in GitHub Desktop.
Sonarqube dockerized
change_password () {
response=$(curl \
--write-out '%{http_code}' \
--silent \
--output /dev/null \
-u admin:admin \
-X POST \
"http://host.docker.internal:9000/api/users/change_password?login=admin&previousPassword=admin&password=$SONAR_PASSWORD")
if [ "$response" == "204" ]
then
echo "Password changed successfully to $SONAR_PASSWORD"
true
elif [ "$response" == "401" ]
then
echo "Password already changed. Is $SONAR_PASSWORD"
true
else
false
fi
}
try_to_change_pass () {
max_retry=20
counter=0
until change_password
do
sleep 4
[[ $counter -eq $max_retry ]] && echo "Failed trying to reach SonarQube server" && exit 1
echo -e "\nSonarQube server not accesible. Try #$counter"
let "counter+=1"
done
}
try_to_change_pass
version: '3'
services:
sonar_server:
image: sonarqube
ports:
- '9000:9000'
sonar_cli:
image: sonarsource/sonar-scanner-cli
profiles: ['cli']
volumes:
- ./:/usr/src
env_file:
- env_vars
command: /bin/bash -c 'sonar-scanner -Dsonar.host.url=$$SONAR_HOST_URL -Dsonar.login=admin -Dsonar.password=$$SONAR_PASSWORD'
change_sonar_server_password:
image: curlimages/curl
volumes:
- ./change_password.sh:/home/curl_user/change_password.sh
env_file:
- env_vars
command: ash -c "/home/curl_user/change_password.sh"
SONAR_HOST_URL=http://host.docker.internal:9000
SONAR_PASSWORD=12345

To init the server

  • npm run sonar:init-server To run the analysis
  • npm run sonar:analysis

To inspect the analysis, go to http://localhost:9000. The credentials are admin and password 12345

@dianjuar
Copy link
Author

dianjuar commented Feb 6, 2022

An example project that is currently using this configuration -> https://github.com/bikecoders/ngx-deploy-npm/blob/master/docker-compose.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment