最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Docker安裝SonarQube的詳細(xì)教程

 更新時(shí)間:2021年10月11日 15:49:46   作者:naumy  
這篇文章主要介紹了Docker安裝SonarQube的教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Docker安裝SonarQube的教程如下所示:

1.拉取鏡像

1.1拉取相關(guān)鏡像并運(yùn)行

1.1.1拉取相關(guān)鏡像

# 拉取sonarqube鏡像
$ docker pull sonarqube:9.1.0-community (推薦使用) /  $ docker pull sonarqube:7.6-community
# 拉取postgres鏡像
$ docker pull postgres:9.6.23

1.1.2運(yùn)行鏡像

# 運(yùn)行postgres數(shù)據(jù)庫(kù)
$ docker run --name postgresqldb --restart=always -p 5432:5432 \
-e POSTGRES_USER=root \
-e POSTGRES_PASSWORD=123456  \
-d postgres:9.6.23

# 進(jìn)入postgres容器,創(chuàng)建用戶名和密碼
$ docker exec -it postgresqldb bash

# 登錄數(shù)據(jù)庫(kù)
psql -U root -W
# 創(chuàng)建用戶名和密碼
create user sonar with password 'sonar';
create database sonar owner sonar;
grant all privileges on database sonar to sonar;

# 不連接postgres數(shù)據(jù)庫(kù)運(yùn)行命令(不推薦)
docker run --name sonarqube --restart=always -p 9000:9000 -d naumy/hitrend-sonarqube:v1.0

# 運(yùn)行sonarqube容器
docker run -d --name sonarqube --restart=always \
-p 9000:9000  \
-e sonar.jdbc.username=sonar \
-e sonar.jdbc.password=sonar \
-e sonar.jdbc.url=jdbc:postgresql://139.198.176.140:5432/sonar \
sonarqube:9.1.0-community

接著訪問(wèn):http://localhost:9000/ 就可以了,默認(rèn)管理員用戶和密碼為:admin/admin。

image-20211008222658468

嵌入式數(shù)據(jù)庫(kù)應(yīng)僅用于評(píng)估目的、嵌入式數(shù)據(jù)庫(kù)無(wú)法擴(kuò)展,不支持升級(jí)到SonarQube的較新版本,也不支持將數(shù)據(jù)從中遷移到其他數(shù)據(jù)庫(kù)引擎。

1.2保存并提交已修改的鏡像

# 保存已經(jīng)修的鏡像
docker commit -a "naumy"  -m "安裝中文插件" 19f1cc24dc98 hitrend-sonarqube:v1.0
# 把舊鏡像的名字,改成倉(cāng)庫(kù)要求的新版名字
docker tag hitrend-sonarqube:v1.0 naumy/hitrend-sonarqube:v1.0
# 登錄到docker hub
docker login       
# 推送
docker push naumy/hitrend-sonarqube:v1.0

image-20211005120955961

2.安裝成功

image-20211003205325696 

3.插件安裝

3.1安裝Chinese插件

SonarQube提供了強(qiáng)大的插件管理功能,以中文語(yǔ)言包為示例,講解如何安裝插件:

登錄成功后,選擇Administration-Marketplace-Plugins,在搜索框輸入Chinese就可以選擇安裝了。

image-20211003205550266

當(dāng)狀態(tài)顯示為Install Pending時(shí),說(shuō)明插件安裝完成,點(diǎn)擊Restart Server即可生效。

之后,就顯示為中文了。

同時(shí)安裝findbug插件

image-20211003205917633

4.docker安裝gitlab

4.1.Gitlab鏡像拉取

# gitlab-ce為穩(wěn)定版本,后面不填寫版本則默認(rèn)pull最新latest版本
$ docker pull gitlab/gitlab-ce

4.2運(yùn)行g(shù)itlab鏡像

$ docker run -d  -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce

# -d:后臺(tái)運(yùn)行
# -p:將容器內(nèi)部端口向外映射
# --name:命名容器名稱
# -v:將容器內(nèi)數(shù)據(jù)文件夾或者日志、配置等文件夾掛載到宿主機(jī)指定目錄

按上面的方式,gitlab容器運(yùn)行沒(méi)問(wèn)題,但在gitlab上創(chuàng)建項(xiàng)目的時(shí)候,生成項(xiàng)目的URL訪問(wèn)地址是按容器的hostname來(lái)生成的,也就是容器的id。

作為gitlab服務(wù)器,我們需要一個(gè)固定的URL訪問(wèn)地址,于是需要配置gitlab.rb(宿主機(jī)路徑:/home/gitlab/config/gitlab.rb)。

# gitlab.rb文件內(nèi)容默認(rèn)全是注釋
$ vim /home/gitlab/config/gitlab.rb
# 配置http協(xié)議所使用的訪問(wèn)地址,不加端口號(hào)默認(rèn)為80
external_url 'http://192.168.199.231'

# 配置ssh協(xié)議所使用的訪問(wèn)地址和端口
gitlab_rails['gitlab_ssh_host'] = '192.168.199.231'
gitlab_rails['gitlab_shell_ssh_port'] = 222 # 此端口是run時(shí)22端口映射的222端口
:wq #保存配置文件并退出

image-20211006212109889

# 重啟gitlab容器
$ docker restart gitlab

此時(shí)項(xiàng)目的倉(cāng)庫(kù)地址就變了。如果ssh端口地址不是默認(rèn)的22,就會(huì)加上ssh:// 協(xié)議頭
打開瀏覽器輸入ip地址(因?yàn)槲业膅itlab端口為80,所以瀏覽器url不用輸入端口號(hào),如果端口號(hào)不是80,則打開為:ip:端口號(hào))

4.3設(shè)置root用戶名和密碼

進(jìn)入目錄 /home/gitlab/config/initial_root_password,查看密碼

xwCsS7lMYx+8x3o6KIBw+Ia6Lg3VqvtHLzxzYfPNtxk=

或者進(jìn)入gitlab容器后修改密碼。

root@ba96cb6a1f47:/# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]
 GitLab:       14.3.2 (92acfb1b8a9) FOSS
 GitLab Shell: 13.21.1
 PostgreSQL:   12.7
--------------------------------------------------------------------------------

irb(main):005:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):006:0> user.password=12345678
=> 12345678
irb(main):007:0> user.password_confirmation=12345678
=> 12345678
irb(main):008:0> user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 4fc2d685-2fd6-41d9-893e-2dabc7c3b366) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007fc6c59b5b48 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):009:0> quit

image-20211006113044081

運(yùn)行后的效果圖

4.4保存鏡像并推送dockerhub

# 保存已經(jīng)修的鏡像
docker commit -a "naumy"  -m "初始化gitlab" ba96cb6a1f47 gitlab:v1.0
docker commit -a "naumy"  -m "sonarqube:7.6-community " e70c6cbe2e0b sonarqube-7.6-community:v1.0
docker tag sonarqube-7.6-community:v1.0 naumy/sonarqube-7.6-community:v1.0
docker push naumy/sonarqube-7.6-community:v1.0
# 把舊鏡像的名字,改成倉(cāng)庫(kù)要求的新版名字
docker tag gitlab:v1.0 naumy/gitlab:v1.0
# 登錄到docker hub
docker login       
# 推送
docker push naumy/gitlab:v1.0

5.碰到的問(wèn)題

5.1虛擬內(nèi)存不夠

啟動(dòng)容器后過(guò)了十幾秒。容器自動(dòng)退出。

Error: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

運(yùn)行容器后,容器馬上退出。

# 使用命令查看運(yùn)行日志
docker logs 容器名稱/容器ID

image-20211005110639500

在/etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

image-20211005110922585

執(zhí)行/sbin/sysctl -p立即生效

image-20211005111046958

6.整合Sonar和gitlab

6.1安裝Gitlab-runner

6.1.1獲取gitlab-Token

進(jìn)入gitlab后,選擇runner,進(jìn)行相應(yīng)的Token獲取。

image-20211008170417198

6.1.2安裝gitlab-runner

# 拉取鏡像
docker pull gitlab/gitlab-runner:v13.2.4

# 創(chuàng)建容器映射目錄
mkdir -p /dwz/docker-volume/gitlab-runner/config

# 創(chuàng)建容器并運(yùn)行
docker run -d --name gitlab-runner \
--restart always \
-v /dwz/docker-volume/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:v13.2.4

進(jìn)入gitlab-runner容器后,配置相應(yīng)的參數(shù)設(shè)置:

docker exec -it gitlab-runner gitlab-runner register -n \
--url http://139.198.166.208 \
--registration-token 9zEbBYXSyqJqpNb9QSNh \
--executor docker \
--description "Docker Runner" \
--docker-image "sonarsource/sonar-scanner-cli:latest" \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock

再次加載gitlab頁(yè)面,出現(xiàn)runner配置項(xiàng)。

image-20211008170819704

6.2設(shè)置sonarqube的用戶名和密碼

設(shè)置當(dāng)前的sonarqube的用戶面和密碼為admin和123456

6.3進(jìn)行項(xiàng)目分析(手動(dòng)添加項(xiàng)目)

image-20211006200645346

是否需要集成自己喜歡的CI,使用gitlab進(jìn)行持續(xù)集成和持續(xù)部署。

image-20211009183044360

第一步 選擇需要檢測(cè)項(xiàng)目代碼類型:

image-20211009183751728

新建配置文件sonar-project.properties:

sonar.projectKey=gitlab-sonorqube
sonar.qualitygate.wait=true
sonar.language=py

image-20211009183240599

第二步:添加環(huán)境變量

image-20211009183832036

image-20211006202645805

令牌密鑰:b23fe46d142fcfb052b05d5b3fd6fc823df0b682

按照要求添加相應(yīng)的環(huán)境變量:

image-20211009163010867

6.4進(jìn)行CI/CD(sonar與gitlab)

6.4.1版本為sonarqube-7.6-community

創(chuàng)建一個(gè)gitlab項(xiàng)目,實(shí)驗(yàn)使用的項(xiàng)目為python項(xiàng)目。

image-20211008171646440

.gitlab-ci.yml文件內(nèi)容為

# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    - echo "Compiling the code..."
    - echo "Compile complete."

unit-test-job:   # This job runs in the test stage.
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - echo "Running unit tests... This will take about 60 seconds."
    - sleep 60
    - echo "Code coverage is 90%"

lint-test-job:   # This job also runs in the test stage.
  stage: test    # It can run at the same time as unit-test-job (in parallel).
  script:
    - echo "Linting code... This will take about 10 seconds."
    - sleep 10
    - echo "No lint issues found."

deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."
    
image: 
  name: sonarsource/sonar-scanner-cli:latest
  entrypoint: [""]

sonarqube-check:
  script: 
    - sonar-scanner -X  -Dsonar.projectKey=gitlab-sonorqube -Dsonar.host.url=http://139.198.176.140:9000 -Dsonar.login=cbd26f998beeb61d7a991e0282efc430b020d9f1 -Dsonar.login=admin -Dsonar.password=admin -Dsonar.language=py  -Dsonar.java.binaries=build/  -Dsonar.projectVersion=1.0 -Dsonar.sources=. 
  allow_failure: true
  only:
    - main # or the name of your main branch

提交代碼后,可以獲取到相應(yīng)的測(cè)試信息。

https://sm.ms/image/ykYPlDgZVvuhzsq

6.4.2版本為sonarqube-9.1-community

.gitlab-ci.yml文件內(nèi)容為

sonarqube-check:
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner -X  -Dsonar.projectKey=gitlab-sonorqube -Dsonar.host.url=http://139.198.176.140:9000 -Dsonar.login=7f9e3408ac11e0699e2f8afdb21a662cc8ab2698 -Dsonar.login=admin -Dsonar.password=123456 -Dsonar.language=py  -Dsonar.java.binaries=build/  -Dsonar.projectVersion=1.0 -Dsonar.sources=. 
  allow_failure: true
  only:
    - main # or the name of your main branch

提交代碼后gitlab會(huì)自動(dòng)進(jìn)行CI/CD:

image-20211009174921078

點(diǎn)入進(jìn)去后查看相應(yīng)的狀態(tài)和內(nèi)容是否符合需求:

image-20211009174902725

運(yùn)行完成后,將看到對(duì)應(yīng)的測(cè)試分析結(jié)果:

image-20211009163521482

6.5在整合過(guò)程中碰到的問(wèn)題

配置文件寫錯(cuò):

使用的python代碼,所以后續(xù)將使用py作為語(yǔ)言選擇。

image-20211009190159197

image-20211009190324553

7.總結(jié)

當(dāng)前使用的工具有:

sonarqube:9.1.0-community 、gitlab/gitlab-runner:v13.2.4 、postgres:9.6.23 、gitlab/gitlab-ce、sonarsource/sonar-scanner-cli:latest

image-20211009163631709

開發(fā)人員提交代碼到gitlab倉(cāng)庫(kù)后,觸發(fā)master分支自動(dòng)合并任務(wù),并進(jìn)行代碼掃描(可改成其他測(cè)試分支),掃面結(jié)果返回到sonarqube平臺(tái)。

image-20211009175746382

到此這篇關(guān)于Docker安裝SonarQube的文章就介紹到這了,更多相關(guān)Docker安裝SonarQube內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Docker中運(yùn)行PostgreSQL并推薦幾款連接工具

    Docker中運(yùn)行PostgreSQL并推薦幾款連接工具

    PostgreSQL支持大部分的SQL標(biāo)準(zhǔn)并且提供了很多其他現(xiàn)代特性,如復(fù)雜查詢、外鍵、觸發(fā)器、視圖、事務(wù)完整性、多版本并發(fā)控制等,今天給大家介紹Docker中運(yùn)行PostgreSQL并推薦幾款連接工具,需要的朋友參考下吧
    2021-06-06
  • docker添加多網(wǎng)卡的方法

    docker添加多網(wǎng)卡的方法

    本篇文章主要介紹了docker添加多網(wǎng)卡的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • docker自定義網(wǎng)橋docker0及docker的開啟,關(guān)閉,重啟命令操作

    docker自定義網(wǎng)橋docker0及docker的開啟,關(guān)閉,重啟命令操作

    這篇文章主要介紹了docker自定義網(wǎng)橋docker0及docker的開啟,關(guān)閉,重啟命令操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • docker-compose 詳解及示例代碼

    docker-compose 詳解及示例代碼

    這篇文章主要介紹了docker-compose 詳解的相關(guān)資料,并附簡(jiǎn)單實(shí)例,需要的朋友可以參考下
    2016-10-10
  • docker容器非root用戶提權(quán)的問(wèn)題解決

    docker容器非root用戶提權(quán)的問(wèn)題解決

    本文主要介紹了docker容器非root用戶提權(quán)的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Docker使用run命令部署Nginx的完整指南

    Docker使用run命令部署Nginx的完整指南

    容器化技術(shù)正在徹底改變現(xiàn)代應(yīng)用的部署方式,而 Docker 作為這一領(lǐng)域的先驅(qū),為開發(fā)者提供了快速構(gòu)建、交付和運(yùn)行應(yīng)用的能力,下面小編就為大家介紹一下Docker如何通過(guò)run命令部署Nginx吧
    2025-03-03
  • Docker安裝pypiserver私服的方法步驟

    Docker安裝pypiserver私服的方法步驟

    本文主要介紹了Docker安裝pypiserver私服的方法步驟,通過(guò)Docker安裝,可以方便地創(chuàng)建私有包倉(cāng)庫(kù),具有一定的參考價(jià)值,感興趣的可以了解一下
    2025-03-03
  • Docker安裝MongoDB的過(guò)程(mongo.latest)

    Docker安裝MongoDB的過(guò)程(mongo.latest)

    MongoDB是一種高性能、靈活的數(shù)據(jù)庫(kù),特別適合處理大量非結(jié)構(gòu)化數(shù)據(jù),它采用文檔數(shù)據(jù)模型,支持復(fù)雜的數(shù)據(jù)結(jié)構(gòu),提供類似面向?qū)ο蟮牟樵冋Z(yǔ)言,本文給大家介紹Docker安裝MongoDB的過(guò)程(mongo.latest),感興趣的朋友一起看看吧
    2024-11-11
  • docker-compose安裝yml文件配置方式

    docker-compose安裝yml文件配置方式

    這篇文章主要介紹了docker-compose安裝,yml文件配置,離線安裝及在線安裝的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • docker中的volume和bind?mount區(qū)別講解

    docker中的volume和bind?mount區(qū)別講解

    這篇文章主要介紹了docker的volume和bind?mount區(qū)別,介紹了volume?相對(duì)于bind?mount的優(yōu)點(diǎn)及volume操作,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08

最新評(píng)論

勃利县| 凌海市| 信丰县| 体育| 科技| 香格里拉县| 抚松县| 株洲市| 尼木县| 中江县| 庐江县| 岢岚县| 库尔勒市| 连山| 盈江县| 来凤县| 阳泉市| 彝良县| 周宁县| 林西县| 铜梁县| 开化县| 皋兰县| 衡山县| 巍山| 方城县| 高雄县| 洛宁县| 阿拉善右旗| 兰州市| 赤城县| 安吉县| 沐川县| 略阳县| 高安市| 白玉县| 邢台县| 武清区| 广昌县| 栖霞市| 日照市|