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通过钩子自动更新到对应服务器
相关推荐
深藏功yu名23 分钟前
Docker+FastAPI+千问API,复刻豆包式流式聊天界面
docker·容器·fastapi
小王要努力上岸31 分钟前
K8S高可用集群安装 (基于Kubeadm+Docker)
docker·容器·kubernetes
骑蜗牛散步40 分钟前
Docker下安装ElasticSearch
大数据·elasticsearch·jenkins
Wy_编程1 小时前
docker仓库
docker·容器·eureka
亚空间仓鼠1 小时前
Docker 容器技术入门与实践 (三):Docker私有仓库
docker·容器·eureka
小陈99cyh1 小时前
安装NVIDIA Container Toolkit,让gpu容器环境跑通
运维·pytorch·docker·nvidia
极小狐1 小时前
PingCode × 极狐GitLab 用AI打通需求到交付全链路,研发管理与工程交付真正一体化
人工智能·gitlab·pingcode
Y学院1 小时前
企业级Dify私有化部署全攻略(Docker Compose生产环境实战)
人工智能·docker·语言模型
12亡灵归来342 小时前
配置Jenkins实现CI/CD流水线
运维·ci/cd·jenkins
草木红2 小时前
Python 中使用 Docker Compose
开发语言·python·docker·flask