Quick Start: SonarQube

how to configure sonarqube with https based on traefik

Quick Start: Sonar

Prerequisite

Traefik on HTTP

OR

Traefik on HTTPS

If HTTP, remove the tls: {} in dynamic configuration

Preparation

configure your host sysctl firstly: /etc/sysctl.conf

1
2
3
# append the following two line key-values to /etc/sysctl.conf
vm.max_map_count = 524288
fs.file-max = 131072

compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
version: Compose specification

services:
    sonarqube:
        image: sonarqube:community
        hostname: sonarqube
        container_name: sonarqube
        depends_on:
            - db
        environment:
            SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
            SONAR_JDBC_USERNAME: sonar
            SONAR_JDBC_PASSWORD: sonar
            # configure ldap server, if no need, remove it
            # HERE LDAP server from the gerrit compose
            SONAR_SECURITY_REALM: LDAP
            LDAP_URL: ldap://ldap
            LDAP_BINDDN: cn=admin,dc=chaos,dc=io
            LDAP_BINDPASSWORD: secret
            LDAP_USER_BASEDN: dc=chaos,dc=io
            LDAP_USER_REQUEST: (&(objectClass=person)(uid={login}))
        volumes:
            - sonarqube_data:/opt/sonarqube/data
            - sonarqube_extensions:/opt/sonarqube/extensions
            - sonarqube_logs:/opt/sonarqube/logs
        ulimits:
            nofile:
                soft: 131072
                hard: 131072
            nproc:
                soft: 8192
                hard: 8192
        expose:
            - 9000
        restart: unless-stopped
        networks:
            - traefik-net
    db:
        image: postgres:14
        hostname: postgresql
        container_name: postgresql
        environment:
            POSTGRES_USER: sonar
            POSTGRES_PASSWORD: sonar
            POSTGRES_DB: sonar
        volumes:
            - postgresql:/var/lib/postgresql
            - postgresql_data:/var/lib/postgresql/data
        restart: unless-stopped
        networks:
            - traefik-net

volumes:
    sonarqube_data:
    sonarqube_extensions:
    sonarqube_logs:
    postgresql:
    postgresql_data:

networks:
    traefik-net:
        external: true

sonar.yml in dir dynamic-conf

You should touch sonar.yml in traefik dir dynamic-conf.

For much more information, please reference the Prerequisite.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
http:
    routers:
        sonarqube:
            rule: "Host(`sonar.x.internal`)"
            service: "sonarqube"
            tls: { }

    services:
        sonarqube:
            loadBalancer:
                servers:
                    -   url: "http://sonarqube:9000"

Config domain parse

1
echo "127.0.0.1 sonar.x.internal\n" >> /etc/hosts

Run

1
2
3
docker compose up -d
# docker compose -p sonar up -d
# docker compose -f ./compose.yml -p sonar up -d

Access: https://sonar.x.internal