CICD是什么?
持续集成
(Continuous Integration,CI) :代码合并构建部署测试都在一起,不断地执行这个过程,并对结果反馈。
持续部署
(Continuous Deployment,CD):部署到测试环境、生产环境
持续交付
(Continuous Delivery,CD):将最终产品发布到生产环境。
相关组件介绍自行了解,来不及解释了。
相关组件
Gitlab-ce15.10.0安装
docker run --detach --hostname IP地址 --publish 443:443 --publish 80:80 --publish 23:22 --name gitlab --restart always --volume /data/gitlab/config:/etc/gitlab --volume /data/gitlab/logs:/var/log/gitlab --volume /data/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:15.10.0-ce.0
- 如何和公司的oauth2集成(下面的接口一个都不能少)
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = false
gitlab_rails['omniauth_providers'] = [
{
name: "oauth2_generic",
label: "Oauth2免登录", # optional label for login button, defaults to "Oauth2 Generic"
app_id: "risen_BGH65nKwqcJy8CXA0xYHOw",
app_secret: "QyUb20QIDi2jJHVOh2XBKco2iCT1Hcpl2RvbjkN9liAxRPz99r21DwqoLv3GgUG1",
args: {
client_options: {
site: "https://ip:13056",
user_info_url: "/auth/public/oauth2/getUserInfo",
authorize_url: "/auth/oauth2/authorize",
token_url: "/auth/oauth2/token"
},
user_response_structure: {
root_path: ["data"],
id_path: ["data"],
attributes: {
name: "name",
email: "email",
nickname: "nickname"
}
},
authorize_params: {
scope: "AUTH"
},
strategy_class: "OmniAuth::Strategies::OAuth2Generic"
}
}
]
- 关闭注册页面 管理中心----> 通用 ----> 注册限制
- oauth2登录需要做账号关联,#<SnakyHash::StringKeyed email=“123@qq.com” id=128057 name=“zs” nickname=“张三”>
- 如果是API创建用户,那么只需要在创建接口和修改接口中新增参数provider,extern_uid
Harbor安装
-
解压
-
cd harbor
-
cp harbor.yml.tmpl harbor.yml
-
./prepare
-
修改以下配置
hostname: 192.168.1.248 #访问harbor的域名,没域名写IP
data_volume: /harbor #数据目录,改不改看你撒
harbor_admin_password: Harbor12345 # 默认admin登陆密码,改不改随你 -
./install.sh
-
安装完成后会下载一堆镜像和运行一堆容器,访问上述的配置的ip和端口即可
Jenkins2.396安装
docker run -dit -p 8080:8080 -p 50000:50000 --restart=on-failure -v /data/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -u root --ulimit nofile=65535:65535 --ulimit nproc=65535:65535 --name jenkins jenkins/jenkins:2.396
- 需要安装插件
- nodejs
- Publish over SSH
- BUILD_TIMESTAMP
- 设置系统环境变量(maven,jdk,nodejs)
Sonarqube9.2.4安装
version: "3"
services:
sonarqube:
image: sonarqube:9.2.4-community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
db:
image: postgres:12
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_data:
driver: local
driver_opts:
o: bind
type: none
device: /data/sonarqube/data
sonarqube_extensions:
driver: local
driver_opts:
o: bind
type: none
device: /data/sonarqube/extensions
sonarqube_logs:
driver: local
driver_opts:
o: bind
type: none
device: /data/sonarqube/logs
postgresql:
driver: local
driver_opts:
o: bind
type: none
device: /data/pgsql/postgresql
postgresql_data:
driver: local
driver_opts:
o: bind
type: none
device: /data/pgsql/data
-
启动命令
docker-compose -f docker-compose.yml up -d
-
初始账号密码:admin/admin
-
安装sonar-scanner(https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.0.2856-linux.zip)
${SONAR_SCANNER_HOME}/bin/sonar-scanner \
-Dsonar.projectKey=${JOB_NAME} \
-Dsonar.host.url=${sonar_url} \
-Dsonar.sources=./src \
-Dsonar.java.binaries=./target/classes \
-Dsonar.language=java \
-Dsonar.login=${sonar_secret} \
-Dsonar.projectVersion=$BUILD_NUMBER \
-Dsonar.exclusions=src/test/**
- 安装插件(注意离线安装插件可以采用目录挂载,容器内外拷贝,数据目录操作/var/lib/docker/volumes/root_sonarqube_extensions/_data/等方式)
- 拷贝命令
docker cp sonar-pdfreport-plugin-4.0.0.jar f035f8895fb9:/opt/sonarqube/extensions/plugins
- 汉化包可安装,可在线,可离线(https://github.com/xuhuisheng/sonar-l10n-zh/releases?page=3)
- findbugs安装,可在线,可离线
- pdm安装,可在线,可离线
- PDF报告导出插件安装,只可离线(https://foruda.gitee.com/attach_file/1668475644156239630/sonar-pdfreport-plugin-4.0.1.jar?token=a61b6aabe0e6a16a66d64d73eb353a32&ts=1689149667&attname=sonar-pdfreport-plugin-4.0.1.jar)注意安装完成需要配置
- 拷贝命令
nexus3安装
docker run -d --restart always --name nexus3 -p 8076:8081 -v /data/nexus:/nexus-data sonatype/nexus3
以maven为例,主要是管理proxy类型,hosted类型,group类型的仓库
group = proxy + hosted
proxy一般配置阿里云这种有三方库的仓库地址
hosted一般配置自己内网发布的依赖制品
- 读写权限配置
- 只读权限配置