代码检测docker-sonarqube

冯冯领队 2019-10-27

gitlab-ce + gitlab-runner + sonarqube,在提交代码时对代码质量进行检测,对不符合要求的代码不允许提交到gitlab

version: '3.1'
services:

  gitlab-ce:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab-ce
    restart: always
    hostname: 'gitlab.localhost.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.31.109'
    ports:
      - '80:80'
      - '443:443'
      - '10022:22'
    volumes:
      - '/root/gitlab-ce/home/config:/etc/gitlab'
      - '/root/gitlab-ce/home/logs:/var/log/gitlab'
      - '/root/gitlab-ce/home/data:/var/opt/gitlab'
    networks:
      - 'default'

  gitlab-runner:
    image: 'gitlab/gitlab-runner:latest'
    container_name: gitlab-runner
    depends_on:
      - 'gitlab-ce'
    restart: always
    volumes:
      - '/root/gitlab-ce/runnerconfig:/etc/gitlab-runner'
      - '/var/run/docker.sock:/var/run/docker.sock'
    networks:
      - 'default'
    links:
      - 'gitlab-ce:gitlab.localhost.com'

  mysql:
    image: mysql:5.7.27
    container_name: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - 3306:3306
    volumes:
      - /root/gitlab-ce/mysql/data:/var/lib/mysql
      - /root/gitlab-ce/mysql/logs:/logs
      - /root/gitlab-ce/mysql/init:/docker-entrypoint-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: 
      MYSQL_USER: test   #创建test用户
      MYSQL_PASSWORD: test  #设置test用户的密码
    networks:
      - 'default'

  sonarqube:
    image: sonarqube:7.7-community
#    image: sonarqube:latest
    container_name: sonarqube
    ports:
      - "9000:9000"
      - "9002:9002"
    volumes:
      - "/root/gitlab-ce/sonarqube/conf:/opt/sonarqube/conf"
      - "/root/gitlab-ce/sonarqube/extensions:/opt/sonarqube/extensions"
      - "/root/gitlab-ce/sonarqube/logs:/opt/sonarqube/logs"
      - "/etc/sysctl.conf:/etc/sysctl.conf"
#     - "/root/gitlab-ce/sonarqube/data:/opt/sonarqube/data"
    environment:
      sonar.jdbc.username: root   #root管理员用户密码
      sonar.jdbc.password:    #创建test用户
      sonar.jdbc.url: "jdbc:mysql://mysql:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false"
    restart: always
    depends_on:
      - mysql
    links:
      - mysql
    networks:
      - 'default'

    sysctls:
      - net.core.somaxconn=1024
    ulimits:
      nproc: 65536
      nofile:
        soft: 65536
        hard: 65536  

networks:
  default:
    driver: 'bridge'

未测试。
参考:
https://yq.aliyun.com/articles/711488?spm=a2c4e.11155435.0.0.16cc2eb4nWOrV4
https://www.ibm.com/developerworks/cn/java/j-lo-sonar/

相关推荐