azure web应用部署_sonarqube与Azure Web应用程序和SQL集成

azure web应用部署

SonarQube is the standard static code review tool for many languages such as Java and PHP. It can determine the violation of code standards and helps the software development team to abolish bugs.

小号 onarQube是许多语言如Java和PHP标准的静态代码检查工具。 它可以确定是否违反了代码标准,并可以帮助软件开发团队消除错误。

介绍: (Introduction:)

SonarQube can perform as a multi-dimensional analyst and covers various aspects of code quality like duplicate code, potential bugs, coding standards, keeps code complexity low, and increases coverage by units.

SonarQube可以充当多维分析人员 ,涵盖代码质量的各个方面,例如重复代码,潜在的错误,编码标准,降低代码复杂性并增加单位覆盖率。

In this article, I am going to share how you can set up Sonarqube using your own docker image in Azure Web App and Azure SQL server.

在本文中 ,我将分享如何在Azure Web App和Azure SQL服务器中使用自己的Docker映像设置Sonarqube。

Azure Web App has various benefits over traditional VM like it is fully containerised, supports high- availability, and there is less overhead of managing the VM.

与传统VM相比, Azure Web App具有各种优势,例如它是完全容器化的,支持高可用性,并且管理VM的开销更少。

Note: You can use Azure VM instead of Azure web App but I feel it is really painful to manage it, hence I am going with Web App for my case.

注意 :可以使用Azure VM代替Azure Web App,但是管理它确实很痛苦,因此我将使用Web App。

Database: The default SonarQube database is the embedded H2 database, which is provided solely for initial testing. It is neither intended nor supported for production use. You will not be able to upgrade with this database. So it is highly recommended to use any other DB which in our scenario we are using SQL DB as it is cheaper than other DB like Postgres.

数据库:默认的SonarQube数据库是嵌入式H2 数据库 ,仅用于初始测试。 既不打算也不支持将其用于生产用途。 您将无法使用此数据库进行升级 因此,强烈建议使用其他任何数据库,在我们的方案中,我们使用的是SQL DB,因为它比Postgres等其他数据库便宜。

There are other options that might seem tempting but didn’t really work for me.

还有其他一些选项似乎很诱人,但对我而言却并不奏效。

  1. Official SonarQube images(using ‘Docker Hub’ with the ‘sonarqube’ image): These don’t work due to limitations of the App Service, and can’t be guaranteed to work in the future.

    官方的SonarQube图像(将“ Docker Hub”与“ sonarqube”图像结合使用):由于App Service的限制,这些图像不起作用,并且不能保证将来能正常工作。
  2. SonarQube Certified by Bitnami: This only supports PostgreSQL databases which are very expensive than the standard SQL Server.

    由Bitnami认证的SonarQube:仅支持比标准SQL Server昂贵的PostgreSQL数据库。

Let’s begin with the Setup after all this discussion.

在所有这些讨论之后,让我们从安装程序开始。

描述 (Description)

Below are the steps which we are going to follow in order to do the setup.

下面是我们将要进行设置的步骤。

Step1. Create a Docker Image.

第一步创建一个Docker镜像

Note: If you want to use another image of Sonarqube, please make the necessary changes in sonarqube.properties file.

注意 :如果要使用Sonarqube的其他图像,请在sonarqube.properties文件中进行必要的更改。

Create two files ‘dockerfile’ and ‘sonarqube.properties’ as below:

创建两个文件“ dockerfile”和“ sonarqube.properties”,如下所示:

dockerfile:

dockerfile

FROM sonarqube:8.3-communityCOPY sonarqube.properties /opt/sonarqube/conf/sonar.properties

sonarqube.properties :

sonarqube.properties:

sonar.search.javaAdditionalOpts=-Dnode.store.allow_mmapfs=false

Step2: Build and push the image to the Azure Container repository(ACR)/docker hub.

步骤2:生成映像并将其推送到Azure容器存储库(ACR)/ docker hub。

Docker login <<your-azure-repo>>docker build -t <<your-azure-repo>>/sonarqube:v1docker push

Step3: Create a Web App and SQL Database. Use below configurations:

第三步:创建一个Web App和SQL数据库。 使用以下配置:

  • App Service Plan — Linux B2 or greater

    应用服务计划-Linux B2或更高版本

  • SQL Server + Database — Basic (5 DTU) with 2GB storage is fine

    SQL Server +数据库-具有2GB存储的基本(5 DTU)很好

  • Web App — using a default image for the initial setup.

    Web App —使用默认图像进行初始设置。

Step4: SQL Database creation and Configuration:

步骤4:SQL数据库的创建和配置:

Create a SQL Database with “SQL_Latin1_General_CP1_CS_AS” collation naming “databasename.database.windows.net” with admin username and password.

使用排序规则“ SQL_Latin1_General_CP1_CS_AS”创建一个SQL数据库,并使用管理员用户名和密码命名为“ databasename.database.windows.net ”。

Now login to this new DB with admin credentials and create a login:

现在,使用管理员凭据登录到该新数据库并创建登录名:

Log in to your server’s ‘master’ database using SSMS, and run :

使用SSMS登录到服务器的“主”数据库,然后运行:

CREATE LOGIN sonarqube WITH PASSWORD = ‘StrongPassword’;

Then log in to the database you created (or open the Query Editor in Azure Portal) and run:

然后登录到您创建的数据库(或在Azure Portal中打开查询编辑器)并运行:

ALTER DATABASE sonarqube SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;CREATE USER sonarqube FOR LOGIN SonarQube WITH DEFAULT_SCHEMA = dbo;ALTER ROLE db_owner ADD MEMBER sonarqube;

Step5: Web APP Container Configuration:

步骤5:Web APP容器配置:

Create a Web App where you choose Docker Compose as Container settings and add the below file in it.

创建一个Web应用程序,在其中选择Docker Compose作为Container设置,并在其中添加以下文件。

Docker Compose file:

Docker Compose文件

version: “3.3”services:sonarqube:image: sonar.azurecr.io/sonar:v1ports:- “9000:9000”environment:- SONAR_JDBC_USERNAME=sonarqube- SONAR_JDBC_PASSWORD=StrongPassword

Step6: Restart the Web App and verify the Sonarqube portal through the app URL.

步骤6:重新启动Web应用程序,并通过应用程序URL验证Sonarqube门户。

Step 7: Setup in Sonarqube:

步骤7:在Sonarqube中进行设置:

  1. Login into the Sonarqube portal and create a new project.

    登录到Sonarqube门户并创建一个新项目。
  2. Generate a token from the Security tab.

    从“安全性”选项卡生成令牌。
  3. Go to Azure DevOps and create a Service Connection with the above-created token.

    转到Azure DevOps并使用上面创建的令牌创建服务连接。

Add below four tasks in your Build pipeline:

在构建管道中添加以下四个任务:

  1. Prepare Sonarqube task wherein choose below properties:

    准备Sonarqube任务,其中选择以下属性:

ScannerMode: cliconfigMode: ManualcliProjectKey: ProjectNameInSonarqubeClisources: ‘./’

2. Run the Sonarqube Analysis task and add a property

2. 运行Sonarqube Analysis任务并添加属性

continueOnError: True”

3. Publish Code Coverage Result task using tool Cobertura

3.使用工具Cobertura 发布代码覆盖率结果任务

4. Publish Sonarqube Code

4. 发布Sonarqube代码

5. Now check the Sonarqube Portal and click on the project you created. You should be able to see the analysis as per the below screenshot.

5.现在检查Sonarqube门户,然后单击您创建的项目。 您应该能够按照以下屏幕截图查看分析。

Image for post

结论 (Conclusion)

If everything works for you till here, you can implement the same in multiple build pipelines. This article was a quick introduction to walk through a simple setup. There are many facets of SonarQube that we did not cover here, you may want to look into the documentation on the official Sonarqube page to explore other options as per your requirements.

如果到现在为止一切正常,您可以在多个构建管道中实现相同的功能。 本文是快速入门,介绍了简单的设置。 SonarQube的许多方面我们在这里都没有涉及,您可能需要查看Sonarqube官方页面上的文档,以根据需要探索其他选项。

翻译自: https://medium.com/globant/sonarqube-integration-with-azure-web-app-and-sql-37eb468162b6

azure web应用部署

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值