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 工具,可以根據他的解決方案去整合到目前的自動化整合專案內。
由此圖可以看出來,Commit之後進入了 CI/CD的Pipeline,Sonaraube就是扮演著QUALITY GATE
的角色,確認無誤後再進入原本的Flow。
透過SonarQube的解決方案流程如下:
- SonarLint: 即時在IDE內提供回饋讓你可以在Commit之前就修正這些Issue
- PR analyis: 可以自己 Pull Request analysis 產出分析結果
- Quality gates: 防止有問題的程式碼發佈到正式機。
- Clean as You Code: 可幫助您專注於提交新的、乾淨的生產代碼,因為您知道您現有的代碼會隨著時間的推移而得到改進。
硬體需求
硬體建議:
1. 小團隊或個人:最小需求 2GB RAM,至少保留1GB給應用程式運作
2. 企業:8 Cores,16GB
Prerequisites and overview (sonarqube.org)
執行原理
-
有一個Web Server的介面讓你操作SonarQube
-
搜尋引擎是使用ElasticSearch
-
Compute Engine 負責分析產出報告紀錄在Database裡面
-
DB 紀錄指標跟Issue的程式碼品質與安全性分析
-
DB 紀錄SonarQube 設定檔
-
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建立新個使用者賦予Create
、Update
、Delete
權限
後續閱讀
List
from "200-Areas/210-工程師修煉/SonarQube"
where dg-publish = true
sort file.ctime
參考連結
- https://docs.sonarqube.org/latest/
- Install the server (sonarqube.org)