标签:dmi with 如何 url start 添加 aliyun build aci
写在前面:一、测试前提条件
主机名 | 公网IP | 内网IP | ROLE | PORT |
---|---|---|---|---|
node1 | 39.104.88.120 | 172.16.0.93 | gitlab | 80 |
node2 | 39.104.93.96 | 172.16.0.94 | drone,jenkins | 80,8080 |
node3 | 39.104.70.51 | 172.16.0.98 | harbor | 80 |
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
2) 添加软件源
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3) 更新并安装Docker-CE
sudo yum makecache fast
yum -y install docker-ce-18.09.9-3.el7
4) 启动Docker
systemctl start docker && systemctl enable docker
5) 配置Docker调优参数
tee /etc/docker/daemon.json << EOF
{
"oom-score-adjust": -1000,
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
},
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 10,
"registry-mirrors": ["https://yefnfc9c.mirror.aliyuncs.com"],
"insecure-registries" : ["0.0.0.0/0"],
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
6) 重启docker生效
systemctl restart docker
二、测试
2.部署说明
2.1. 部署gitlab
docker run --detach --hostname 39.104.88.120 --publish 443:443 --publish 80:80 --publish 1022:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:12.10.3-ce.0
注:39.104.88.120为本机实际节点外网IP
2.2. 部署Harbor
2.2.1. 安装docker-compose
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
2.2.2. 下载harbor
https://github.com/goharbor/harbor/releases/download/v1.10.2/harbor-online-installer-v1.10.2.tgz
2.2.3. 解压后配置harbo.yaml
hostname: 172.31.48.86 //修改为实际节点内网IP
屏蔽https配置部分
2.2.4. 安装Harbor
./install.sh --with-clair
2.2.5. 安装结果检查
docker-compose ps //正常回显如下
2.3. 部署Drone
2.3.1. 部署drone主应用
如何取得
DRONE_GITLAB_CLIENT_ID
DRONE_GITLAB_CLIENT_SECRET
? 登录gitlab并配置gitlab外部认证
? 应用回调接口申请
注:本测试采用docker run 部署drone,所以Url为:http://39.104.93.96/login,按自身部署drone环境修改Url。
? 取得ApplicationID和secret
ApplicationID对应DRONE_GITLAB_CLIENT_ID
secret对应DRONE_GITLAB_CLIENT_SECRET
------------------------------------------------------------------------------------------------------------分割线
docker run --volume=/var/run/docker.sock:/var/run/docker.sock --volume=/var/lib/drone:/data --env=DRONE_LOGS_DEBUG=true --env=DRONE_GIT_ALWAYS_AUTH=false --env=DRONE_GITLAB_SERVER=http://39.104.88.120 --env=DRONE_GITLAB_CLIENT_ID=d6272993ac02c3bb4069d73bf0ff8dabeaff47c0739ae27d1a23e8b80e33faa5 --env=DRONE_GITLAB_CLIENT_SECRET=01f454fe0a55256a974d420b8ca023df6efc80b33d8a917dd16138b152b73253 --env=DRONE_RPC_SECRET=12345678 --env=DRONE_RUNNER_CAPACITY=3 --env=DRONE_SERVER_HOST=39.104.93.96 --env=DRONE_SERVER_PROTO=http --env=DRONE_TLS_AUTOCERT=false --publish=80:80 --publish=443:443 --restart=always --detach=true --name=drone drone/drone:1
参数说明:
2.3.2. 部署Drone-runner
docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e DRONE_RPC_PROTO=http -e DRONE_RPC_HOST=172.16.0.94 -e DRONE_RPC_SECRET=12345678 -e DRONE_RUNNER_CAPACITY=3 -e DRONE_RUNNER_NAME=${HOSTNAME} -p 3000:3000 --restart always --name runner drone/drone-runner-docker:1
参数说明:
Drone-runner检查
3.配置说明
3.1. 配置harbor
3.1.1. 增加项目:go-server
注:admin/Harbor12345
3.2. 配置gitlab
3.2.1. 增加项目:go-server
3.2.2. 项目go-server中创建相关文件
1) 增加主应用代码文件:server.go
package main
import (
"fmt"
"log"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}
func main() {
http.HandleFunc("/", hello)
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}
2) 创建Dockerfile,会被.drone.yml调用
FROM golang
WORKDIR /go
ADD server /go
CMD ["./server"]
3) 创建.drone.yml文件,此文件作用是按文件内容将任务传送至drone应用,进行CI动作。
注:此文件在配置drone完成后创建
kind: pipeline
type: docker
name: build
steps:
- name: build-code
image: golang:alpine
pull: if-not-exists # always never
commands:
- go build server.go
- name: build-image
image: plugins/docker
settings:
repo: 172.16.0.98/go-server/go-server
registry: 172.16.0.98
use_cache: true
username:
from_secret: registry_username
password:
from_secret: registry_password
tags: ${DRONE_BUILD_NUMBER}
insecure: true
mirror: https://yefnfc9c.mirror.aliyuncs.com/
trigger:
branch:
- master
event:
- push
3.3. 配置drone
3.3.1. 提示gitlab页确认后跳转drone
3.3.2. 点击已同步项目go-server
3.3.3. 点击已同步项目go-server后找到SETTINGS
3.3.4. SETTINGS设置Harbor登录信息
注:此处valuse值对应.drone.yml中常量值,下图标红处。key值为harbor用户及密码。
username:
from_secret: registry_username
password:
from_secret: registry_password
注:完成后创建.drone.yml文件,接3.2.2 .drone.yml内容。
4.测试效果说明
4.1. drone效果
4.2. harbor效果
4.3. 再次触发build
修改gitlab中go-server代码,就会再次出发build。
标签:dmi with 如何 url start 添加 aliyun build aci
原文地址:https://blog.51cto.com/tonegu/2497290