1

使用 dockerized 声纳扫描仪 4.2 官方图像,我尝试运行声纳扫描仪的示例 Docker 运行操作,我 unable to create user cache: /usr/src/.sonar/cache caused by: Java.nio.file.accessdeniedexception: /usr/src/.sonar 每次都得到。图像上的用户有问题吗?很难相信,因为这是官方的声纳扫描仪Docker 图像

4

3 回答 3

0

我在 OpenShift 下使用配置了声纳扫描仪插件的 Jenkins 容器遇到了同样的问题。

为了修复它,我在 Jenkins 的配置中的 Global Properties 部分下添加了一个环境变量SONAR_USER_HOME,指向。/tmp

在此处输入图像描述

于 2021-12-16T17:50:01.420 回答
0

你有没有将任何东西挂载到 /usr/src -v "/path/to/project:/usr/src"

于 2020-01-08T12:24:57.817 回答
0

在 Linux 上,我必须手动创建文件夹并设置正确的 chmod :

mkdir .sonar .sonar/cache .scannerwork
sudo chmod -R 777 .sonar
sudo chmod -R 777 .scannerwork

为了自动化扫描,我创建了一个docker-compose-sonarqube.yml,其中包含:
- sonarqube 服务器
- sonarqube 数据库
- tha sonarqube 扫描仪

version: '3.7'

services:
  # Sonarqube server : continuous code quality + security
  # User = admin, password = admin
  # The first time, we need to adjust docker parameters for sonarqube. Execute commands in the section 'Docker Host Requirements' from https://hub.docker.com/_/sonarqube/ : sudo sysctl -w vm.max_map_count=262144; sudo sysctl -w fs.file-max=65536; ulimit -n 65536; ulimit -u 4096; docker-compose -f docker-compose-sonarqube.yml up
  sonarqube:
    image: sonarqube:8.3-community
    depends_on:
      - sonarqube-db
    ports:
      - "54380:9000"
    expose:
      - "9000"
    networks:
      - sonarnet
    environment:
      SONAR_JDBC_URL: jdbc:postgresql://sonarqube-db:5432/sonar
      SONAR_JDBC_USERNAME: sonar
      SONAR_JDBC_PASSWORD: sonar
    volumes:
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
      - sonarqube_logs:/opt/sonarqube/logs
      - sonarqube_temp:/opt/sonarqube/temp
  # Sonarqube database
  sonarqube-db:
    image: postgres
    networks:
      - sonarnet
    environment:
      POSTGRES_USER: sonar
      POSTGRES_PASSWORD: sonar
    volumes:
      - postgresql:/var/lib/postgresql
      # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
      - postgresql_data:/var/lib/postgresql/data
  # Sonarqube client (scanner)
  sonarqube-scanner-cli:
    image: sonarsource/sonar-scanner-cli
    depends_on:
      - sonarqube
    networks:
      - sonarnet
    volumes:
      - ./:/usr/src
    environment:
      SONAR_HOST_URL: http://sonarqube:9000

networks:
  sonarnet:
    driver: bridge

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

在sonar-project.properties中设置您的项目源:

# must be unique in a given SonarQube instance
sonar.projectKey=myapp

# --- optional properties ---

# defaults to project key
sonar.projectName=My App
# defaults to 'not provided'
#sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=./symfony/src

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

# Sonarqube server url
sonar.host.url=http://sonarqube:9000

最后运行sonarqube.sh

# Usage : sh sonarqube.sh firefox

sonarcube() {
    sonarqubePort=54380
    sudo date # Ask for the password at the begining
    docker-compose -f docker-compose-sonarqube.yml up --d
    isServerUp=1
    while [ "$isServerUp" != "0" ]; do # Wait for sonarcube server to be up
        echo "Waiting for sonarqube. This may take 1 min ..."
        curl http://localhost:$sonarqubePort -s|grep "window.serverStatus"|grep "UP"
        isServerUp=$?
        sleep 1
    done
    sleep 3
    mkdir .sonar .sonar/cache .scannerwork
    sudo chmod -R 777 .sonar
    sudo chmod -R 777 .scannerwork
    docker-compose -f docker-compose-sonarqube.yml start sonarqube-scanner-cli;
    docker-compose -f docker-compose-sonarqube.yml logs -f sonarqube-scanner-cli;
    firefox http://localhost:54380/dashboard?id=myapp
    echo "View Sonarqube results at http://localhost:$sonarqubePort/dashboard?id=myapp"
}

sonarcube
于 2020-05-30T13:32:06.690 回答