相对于采用公共的镜像仓库,使用私有镜像仓库,可以部署在内网中,利用内网的安全防护如防火墙等,更安全更高效,方便内部控制。
Harbor 是一个企业级可以应用于生产环境的镜像仓库。Harbor 是由VMware的中国区研发中心创建的,主力开发都是中国人,很多国内公司都在使用。
优点
-
高效的docker文件分层传输,提供高效的镜像上传下载
-
提供镜像安全性扫描,漏洞扫描功能
-
提供易于操作的用户web界面
-
企业级的安全认证方式(多种)
-
主力开发人员是中国人,方便交流
安装
安装很简单,可以参考官方文档,这里就不在叙述了
https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
与Drone CI 集成
通过Harbor界面创建一个test名字的项目,tag想要上传的镜像,然后push镜像:
docker tag hello-world xx.xx.xx.xx:5000/test/hello-world
docker push xx.xx.xx.xx:5000/test/hello-world
drone.yml
kind: pipeline
name: default
steps:
- name: build
image: xxxxxxx:5000/test/hello-world
commands:
- bundle
image_pull_secrets:
- dockerconfigjson
通过drone web ui 界面添加 Secrets
name: dockerconfigjson
value:
{
"auths": {
"xxxx.com:5000": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
}
}
auth 文件里内容实际是用户名密码串简单的base64形式,可以简单的通过l类似下边的命令获取。
echo -n 'admin:Harbor12345' | base64
YWRtaW46SGFyYm9yMTIzNDU=
(例子中用户名密码是Harbor默认值)
当Harbor没有配置ssh,drone主机上docker需要配置insecure-registries,
在/etc/docker/daemon.json文件中增加下列内容
{
"insecure-registries": ["xxx.com:5000"]
}
(mac下需要在ui界面中设置)
如果你的当Harbor没有配置ssh,用plugins/docker插件一定要记得设置insecure: true
steps:
- name: docker
image: plugins/docker
settings:
registry: xxxx
repo: xxxx:5000/test/hello-world
username: admin
password: Harbor12345
insecure: true
debug: true
想要了解registry基本原理可以从drone与那代码中的测试文件
plugin/registry/static_test.go入手
公众号
王司技术谈
![](https://img.haomeiwen.com/i11689946/176180a7c0db83ce.jpg)
网友评论