Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create local SonarQube service and tooling? #28

Open
hkirsman opened this issue May 4, 2024 · 1 comment
Open

Create local SonarQube service and tooling? #28

hkirsman opened this issue May 4, 2024 · 1 comment

Comments

@hkirsman
Copy link
Collaborator

hkirsman commented May 4, 2024

Example:

.ddev/docker-compose.sonarqube.yaml

# Host requirements:
# sysctl -w vm.max_map_count=524288
# sysctl -w fs.file-max=131072
# ulimit -n 131072
# ulimit -u 8192
services:
  # Based on:
  # https://www.docker.com/blog/how-to-use-the-postgres-docker-official-image/
  # https://github.com/ICTU/sonar
  postgres:
    container_name: ddev-${DDEV_SITENAME}-postgres
    image: postgres:15
    restart: "always"
    cpus: 0.5
    mem_limit: 4096M
    mem_reservation: 1024M
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
    # @todo How to create password for "postgres" user?
    user: postgres
    environment:
      POSTGRES_DB: database
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_HOST_AUTH_METHOD: scram-sha-256
      POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256
    ports:
      - 5432:5432
    expose:
      - "5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval    : 1s
      timeout: 5s
      retries: 10

  sonarqube:
    container_name: ddev-${DDEV_SITENAME}-sonarqube
    image: sonarqube:10.4-community
    entrypoint: [ /opt/sonarqube/docker/entrypoint.sh ]
    init: true
    # working_dir: "/root"
    # volumes:
    # - sonarqube_data:/opt/sonarqube/data
    # - sonarqube_extensions:/opt/sonarqube/extensions
    # - sonarqube_logs:/opt/sonarqube/logs
    # Not sure if best: https://community.sonarsource.com/t/sonarqube-sometimes-cant-connect-to-postgres-docker-setup/41628
    restart: "unless-stopped"
    cpus: 0.5
    mem_limit: 4096M
    mem_reservation: 1024M
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
    ports:
      - 9000:9000
     #- "0.0.0.0:9000:9000"
    # expose:
    #   - "9000"
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://postgres:5432/database
      - SONAR_JDBC_USERNAME=postgres
      - SONAR_JDBC_PASSWORD=postgres
      - HTTP_EXPOSE=80:9000
      - VIRTUAL_HOST=sonar.${DDEV_HOSTNAME}
      # @todo Binding to all ip's but doesn't seem to work.
      #- SONAR_WEB_HOST=0.0.0.0
      #- DOMAIN=${DDEV_HOSTNAME}
      #- SONAR_HOST_URL=http://${DDEV_HOSTNAME}
    depends_on:
      - postgres

volumes:
  pgdata:
    name: pgdata

Tooling/command run run scan:
.ddev/commands/web/sonar-scanner.sh

#!/usr/bin/env bash

## Description: Run SonarQube scanner locally.
## Usage: sonar-scanner
## Example: "ddev sonar-scanner"

export SONAR_SCANNER_VERSION=5.0.1.3006
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$SONAR_SCANNER_HOME/bin:$PATH
export SONAR_SCANNER_OPTS="-server"

export SONAR_TOKEN=sqp_5156f0dc5c5197b1f2e501d6ea573827b9b59856

sonar-scanner \
  -Dsonar.projectKey=tua \
  -Dsonar.sources=. \
  -Dsonar.host.url=http://sonarqube:9000

@hkirsman
Copy link
Collaborator Author

hkirsman commented May 4, 2024

It should probably be separate DDEV service when using locally, not separate install with each site. It's pretty heavy software needing postgresql, also there seems to be ElastiSearch running in the background. It takes a while to get this all up and running.

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

No branches or pull requests

1 participant