SonarQube

SonarQube

自動Code Review 工具

目前團隊都是使用人工方式進行程式碼檢核,因為是推行的初期不希望給予太多的限制與壓力,所以在執行過程沒有嚴格地盯著大家去進行這項作業。再加上目前是採取專案負責人得概念去進行Code Review,主要著重點在架構是否脫離當初架構與商業邏輯是否符合預期,對於團隊的技術能力不依的狀況下,每個標準自然也就不同,長期以往擔心的是品質低落、顧慮同事情誼之類姑且放過的心態造成心理負擔,如果有個公正的工具來提示大家擺脫尷尬狀況也可維持一定的程式碼水平。

以下是官方的文字說明,我只是根據自己的理解去擷取終點

SonarQube is a self-managed, automatic code review tool that systematically helps you deliver clean code. As a core element of our Sonar solution, SonarQube integrates into your existing workflow and detects issues in your code to help you perform continuous code inspections of your projects. The tool analyses 30+ different programming languages and integrates into your CI pipeline and DevOps platform to ensure that your code meets high-quality standards.
``
可自行架設。系統自動化的Code Review 工具,可以根據他的解決方案去整合到目前的自動化整合專案內。

200-Areas/210-工程師修煉/SonarQube/resource/SonarQube.png
由此圖可以看出來,Commit之後進入了 CI/CD的Pipeline,Sonaraube就是扮演著QUALITY GATE的角色,確認無誤後再進入原本的Flow。

透過SonarQube的解決方案流程如下:

硬體需求

硬體建議:
1. 小團隊或個人:最小需求 2GB RAM,至少保留1GB給應用程式運作
2. 企業:8 Cores,16GB

Prerequisites and overview (sonarqube.org)

200-Areas/210-工程師修煉/SonarQube/resource/SonarQube-1.png

執行原理

  1. 有一個Web Server的介面讓你操作SonarQube

  2. 搜尋引擎是使用ElasticSearch

  3. Compute Engine 負責分析產出報告紀錄在Database裡面

  4. DB 紀錄指標跟Issue的程式碼品質與安全性分析

  5. DB 紀錄SonarQube 設定檔

  6. Scanner 一台或多台去建立或持續整合專案分析

    可以看出有三種角色Scanner 、 SonarQube Server 、 DB

SonarQuber Server : SonarScanner for .NET (sonarqube.org)
Scanner for .NET:SonarScanner for .NET (sonarqube.org)

DB支援:MSSQL、Oracle、PostgreSql

為了效能起見 SonarQube 與 DB不要放在同一個伺服器,但需要在同一個網段,而且SonarQube Server 應該是專用伺服器。
也需要替SonarQube建立新個使用者賦予CreateUpdateDelete 權限

後續閱讀

List
from "200-Areas/210-工程師修煉/SonarQube"
where dg-publish = true
sort file.ctime

參考連結