前言
架构图
机器准备(3台)
-
CI / CD
10.0.4.3
(Drone + Gogs + SonarQube) -
Docker 镜像仓库
10.0.4.22
(Harbor) -
测试环境
10.0.4.50
SonarQube
安装 SonarQube
docker run -d --name sonarqube -p 9000:9000 --net mynetwork --ip 172.18.0.5 --restart=always sonarqube:alpine
安装 中文语言包
安装完成后,点击 restart,重启 SonarQube 服务器
默认账密
账号:admin
密码:admin
Gogs
安装 Gogs
docker run -d --name=gogs --restart=always -p 3000:3000 -p 3001:22 -v /docker/gogs:/data --net mynetwork --ip 172.18.0.2 gogs/gogs
配置 Gogs
克隆仓库
Drone
安装 Drone
docker run \
--volume=/var/lib/drone:/data \
--env=DRONE_AGENTS_ENABLED=true \
--env=DRONE_GOGS_SERVER=http://172.18.0.2:3000 \
--env=DRONE_RPC_SECRET=drone666 \
--env=DRONE_SERVER_HOST=172.18.0.3 \
--env=DRONE_SERVER_PROTO=http \
--env=DRONE_LOGS_TRACE=true \
--env=DRONE_USER_CREATE=username:public,admin:true \
--publish=80:80 \
--publish=443:443 \
--restart=always \
--detach=true \
--name=drone \
--net mynetwork \
--ip 172.18.0.3 \
drone/drone:1
安装 Drone-runner
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DRONE_RPC_PROTO=http \
-e DRONE_RPC_HOST=172.18.0.3 \
-e DRONE_RPC_SECRET=drone666 \
-e DRONE_RUNNER_CAPACITY=2 \
-e DRONE_RUNNER_NAME=${HOSTNAME} \
-e DRONE_LOGS_TRACE=true \
-e DRONE_RUNNER_NETWORKS=mynetwork \
-p 81:3000 \
--restart always \
--name runner \
--net mynetwork \
--ip 172.18.0.4 \
drone/drone-runner-docker:1
登录 Drone
使用 Gogs 账号
同步 Gogs 仓库
激活 Gogs 仓库
该步骤会在 Gogs 仓库中,生成 WebHook
开启 Drone 信任模式
查看 Gogs WebHook
测试 Gogs WebHook
Harbor
安装 docker-compose
yum install docker-compose
安装 Harbor
mkdir ~/software && cd ~/software
wget https://github.com/goharbor/harbor/releases/download/v1.9.3/harbor-offline-installer-v1.9.3.tgz
tar -xvf harbor-offline-installer-v1.9.3.tgz
cd ~/harbor
配置 Harbor
// harbor.yml
hostname: 10.0.4.22
http:
port: 80
启动 Harbor
./install.sh
默认帐密
账号:admin
密码:[ harbor.yml password ]
创建仓库
编辑项目
该环节,以 JavaScript 前端项目为例
初始化项目
yarn init -y
yarn add -D parcel-bundler
配置脚本
// package.json
"scripts": {
"build": "parcel build index.html"
},
创建项目入口
// index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p>888888888</p>
</body>
</html>
创建 drone 配置文件
// .drone.yml
kind: pipeline
name: default
steps:
- name: restore-cache
image: drillster/drone-volume-cache
volumes:
- name: cache
path: /cache
settings:
restore: true
mount:
- ./node_modules
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
SONAR_HOST: http://172.18.0.5:9000
- name: build-frontend
image: node
commands:
- yarn install
- yarn build
- name: rebuild-cache
image: drillster/drone-volume-cache
volumes:
- name: cache
path: /cache
settings:
rebuild: true
mount:
- ./node_modules
- name: upload-docker
image: plugins/docker
settings:
repo: 10.0.4.22/repo_drone/image_drone
registry: 10.0.4.22
username: public
password: Abcdefg123
tags: v1.0.0
insecure: true
debug: true
dockerfile: Dockerfile
- name: ssh run
image: appleboy/drone-ssh
settings:
host: 10.0.4.50
username: root
password: gdhr@123
port: 22
script:
- docker pull 10.0.4.22/repo_drone/image_drone:v1.0.0
- docker run -d -p 1111:80 --restart=always 10.0.4.22/repo_drone/image_drone:v1.0.0
volumes:
- name: cache
host:
path: /tmp/cache_drone
网友评论