栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > 服务器

Docker Gitlab+Jenkins+Harbor构建持久化平台操作

服务器 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CI/CD概述



CI工作流程设计



Git 代码版本管理系统 只能命令行去管理git

Gitlab 基于git做了图形管理页面,企业使用gitlab做私有的代码管理仓库

Github 公共代码管理仓库

搭建gitlab

搭建gitlab先创建工作目录,因为有些数据需要持久化

[root@www ~]# mkdir -p /gitlab
[root@www ~]# cd /gitlab/
 
docker run -d 
 --name gitlab 
 -p 8443:443 
 -p 9999:80 
 -p 9998:22 
 -v /gitlab/config:/etc/gitlab 
 -v /gitlab/logs:/var/log/gitlab 
 -v /gitlab/data:/var/opt/gitlab 
 -v /etc/localtime:/etc/localtime 
 --restart=always 
 lizhenliang/gitlab-ce-zh:latest

9999是web端口 8443web htpps端口 9998 ssh端口

将容器化的数据持久化到本地宿主机,这个镜像是早期汉化后构建的,默认官方的镜像是英文的,这个是英文的,这个镜像比较大差不多1G,包括数据库和消息队列,里面封装的内容很多。

[root@www gitlab]# docker logs 3396d5ccc518 
  - execute /opt/gitlab/bin/gitlab-ctl start postgresql
+psql_host='/var/opt/gitlab/postgresql'

通过日志可以查看到有哪些组件如postgresql

初次访问的时候可能有点慢,因为组件较多,可能要等待3-5分钟



出现这个页面说明gitlab服务是启动起来了,可能里面其他组件还没启动成功。这里最好给到物理内存4G,如果只有2G是不能正常启动的,差不多八分钟之后如下所示



用户名默认是root这里需要设置新密码,新密码最少8位可以设置为qwerasdf,然后更新完密码就可以使用root用户名 密码qwerasdf去登入



创建一个私有项目java-demo



推送代码到java-demo仓库

在另外一台机器上安装git,将项目的源码包上传

[root@localhost ~]# yum install git -y

[root@localhost ~]# unzip tomcat-java-demo-master.zip

初始化Git目录

[root@localhost ~]# cd tomcat-java-demo-master
[root@localhost tomcat-java-demo-master]# git init
Initialized empty Git repository in /root/tomcat-java-demo-master/.git/

这个git目录就会配置git相关的一些数据,初始化完成以后

[root@localhost tomcat-java-demo-master]# cd .git/
[root@localhost .git]# ls
branches config description HEAD hooks info objects refs

配置git的配置文件

这条命令是将gitlab的地址写到.git/config配置文件当中

[root@localhost tomcat-java-demo-master]# git remote add origin http://192.168.179.100:9999/root/java-demo.git
 
[root@localhost tomcat-java-demo-master]# cat .git/config  可以看到gitlab地址写进去了,待会去提交代码都会去读取该配置文件
[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true
[remote "origin"]
 url = http://192.168.179.100:9999/root/java-demo.git
 fetch = +refs/headsmaster']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '86ebc99d-d3fc-4e6e-b938-db1f5a1f3642', url: 'http://192.168.179.100:9999/root/java-demo.git']]])

拉取编译好之后的war包放到环境镜像里面

现在配置maven的源

Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-war-plugin/3.1.0/maven-war-plugin-3.1.0.jar (91 kB at 5.3 kB/s)

Downloading: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-web/2.0.1.RELEASE/spring-boot-starter-web-2.0.1.RELEASE.pom

在后台输出可以看到这些东西,在编译构建的时候maven的源是默认的网络比较慢,现在要修改源确保拉取速度快一些宿主机上修改,这里面定义了从那个源拉取相应的依赖包

[root@localhost ~]# vim /usr/local/maven/conf/settings.xml 
  
   central
   central
   aliyun maven
   https://maven.aliyun.com/repository/public
  

修改完之后不需要重启容器直重新构建,可以看到构建出来的包

[root@localhost ~]# ls /opt/jenkins_home/workspace/test-pipeline/target/ classes generated-sources ly-simple-tomcat-0.0.1-SNAPSHOT ly-simple-tomcat-0.0.1-SNAPSHOT.war maven-archiver maven-status

Job存放的是数据源信息

[root@localhost ~]# ls /opt/jenkins_home/jobs/

test test-pipeline





如果需要在其他dcker主机上部署可以使用ssh插件的ssh命令或者使用ansible别的机器上启动执行docker命令创建容器





题外话



提供了如果你的harbor提供了Https认证,那么请在你的jenkins这台主机将证书拷贝到相应的目录下面。确保jenkins主机能够登入进docker harbor仓库

[root@localhost ~]# mkdir -p /etc/docker/certs.d/reg.harbor.com
[root@localhost ~]# ls
anaconda-ks.cfg  reg.harbor.com.pem
 
[root@localhost ~]# cp reg.harbor.com.pem /etc/docker/certs.d/reg.harbor.com/reg.harbor.com.crt
 
[root@localhost ~]# cat /etc/hosts
127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain4
::1     localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.179.102 reg.harbor.com
 
[root@localhost ~]# docker login reg.harbor.com
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
 
Login Succeeded

以上这篇Docker Gitlab+Jenkins+Harbor构建持久化平台操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/176637.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号