Docker+jenkins+gitlab实现持续集成

1.安装环境

服务器ip 虚拟机版本
192.168.5.132 centos7.6
192.168.5.152 centos7.6

2. 安装docker

复制代码
安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息,要确保centos7能上外网
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新并安装docker

yum makecache fast

yum -y install docker-ce

启动docker

service docker start

3. 安装docker-compose

复制代码
curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

4. 安装jenkins

复制代码
编写yaml文件

vim jenkins.yaml

version: '3.1'
services:
  jenkins:
    image: jenkins/jenkins:2.361.3
    volumes:
      - /data/jenkins/:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
    ports:
      - "8080:8080"
    expose:
      - "8080"
      - "50000"
    privileged: true
    user: root
    restart: always
    container_name: jenkins
    environment:
      JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'

启动容器

docker-compose -f jenkins.yaml up -d

jenkins访问地址

http://192.168.5.137:8080/

5. 安装gitlab

复制代码
编写yaml文件

vim gitlab.yaml

version: '3.1'
services:
  gitlab:
    image: 'gitlab/gitlab-ee:latest'
    restart: always
    hostname: 'gitlab'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.5.152:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2224
    ports:
      - '8929:8929'
      - '2224:22'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'

启动容器

docker-compose -f gitlab.yaml up -d

gitlab访问地址

http://192.168.5.152:8929/


查看gitlab初始密码

docker exec -it gitlab_gitlab_1 grep 'Password:' /etc/gitlab/initial_root_password

6. 配置两台服务器免密

复制代码
jenkins服务器操作

ssh-keygen -t rsa

ssh-copy-id 192.168.5.152


gitlab服务器操作

ssh-keygen -t rsa

ssh-copy-id 192.168.5.137

7. 配置jenkins

安装必要插件
GitLab、Generic Webhook Trigger、Git Parameter、Publish Over SSH,安装完插件重启系统
配置密钥
复制代码
cat /root/.ssh/id_rsa
将里面的密钥填的此处


新建任务






7. 配置gitlab







9.测试构建

修改仓库文件内容,触发钩子
可以看到文件更新之后,jenkins通过钩子自动更新到对应服务器
相关推荐
小白的码BUG之路12 分钟前
Docker -- 构建nginx镜像,启动vue项目
vue.js·nginx·docker
guo_wen_qiang14 分钟前
docker安装常见软件集合
运维·docker·容器
程序员清风11 小时前
Docker、Nginx 与 Kubernetes 部署 AI 后端服务
nginx·docker·kubernetes
谢亮_vipxieliang12 小时前
镜像安全:扫描、签名与软件供应链
安全·docker
天衍四九-13 小时前
Docker容器实战系列(八):Docker生产最佳实践与避坑指南,系列终章
运维·docker·容器
Zhou14113615 小时前
Docker_03_DockerCompose多容器编排
运维·docker·容器
啊哈一半醒17 小时前
Docker 底层知识:从 Namespace 到 UnionFS
运维·docker·容器
fruge19 小时前
飞牛OS部署Flare导航页:Docker Compose、YAML书签配置与cpolar公网访问
运维·docker·容器
Zhou14113620 小时前
Docker_02_Dockerfile与存储网络
网络·docker·容器
Zhou1411361 天前
CICD_01_持续集成与Jenkins入门
运维·ci/cd·jenkins