User Tools

Site Tools


Action disabled: source
docker-sonarqube

Running Sonarqube + Postgresql in Docker

Create postgres container including mount to /var/lib/postgresql/data (cahnge “/path/to/folder/on/host/” to your preferred path and »>PASSWORD«<):

docker run --restart=always --name sonar-postgres -v /path/to/folder/on/host/:/var/lib/postgresql/data -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=>>>PASSWORD<<< -d postgres

Link Container, make it accessible by other containers:

docker run -it --link sonar-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U sonar'

Create Sonarqube container:

docker run --restart=always --name sonarqube --link sonar-postgres:pgsonar -p 9000:9000 -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=>>>PASSWORD<<< -e SONARQUBE_JDBC_URL=jdbc:postgresql://pgsonar:5432/sonar -d sonarqube

Sonarqube scanner script

sonar_runner.sh
#!/bin/bash
 
REPO_STORE="/var/www/sonarqube/"
 
# OPTIONS FOR EACH REPO: URL|PROJECT_NAME|BRANCH
REPOS[0]="https://github.com/ochorocho/JoRo.KnallImAll.git|JoRo.KnallImAll|master"
REPOS[1]="https://github.com/ochorocho/JoRo.GitHub.git|JoRo.GitHub|master"
 
for REPO in ${REPOS[@]}; do
 
    NOW=$(date)
 
    # SPLIT REPO INFOS
    RP=(`echo $REPO | tr "|" "\n"`)
 
    if [ ! -d "${REPO_STORE}/${RP[1]}" ]; then
        # CLONE REPO
        echo "${NOW} - Clone '${RP[1]}'";
        cd "${REPO_STORE}" && git clone ${RP[0]} ./${RP[1]}
    fi
 
    # CHECKOUT BRANCH
    echo "${NOW} - Checkout Branch '${RP[2]}' on '${RP[1]}'";
    cd "${REPO_STORE}/${RP[1]}" && git pull && git checkout ${RP[2]} 
 
    # TRIGGER SONARQUBE RUNNER
    echo "${NOW} - Start sonarqube Scanner on '${RP[1]}/${RP[2]}'";
    docker run --rm -v ${REPO_STORE}${RP[1]}:/data pierrevincent/sonar-runner -Dsonar.host.url=http://sonarqube.knallimall.org:9000/ -Dsonar.login=>>>YOUR_TOKEN<<<
 
done

Inspired by http://blog.anorakgirl.co.uk/2015/11/super-quick-sonarpostgres-setup-with-docker/

docker-sonarqube.txt · Last modified: 2017/04/14 02:21 by admin