欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用Docker+Gitlab+Harbor+Jenkins+DockerCompose搭建CICD开发环境

程序员文章站 2022-05-14 20:39:04
...

一. 安装

1. 安装Docker

  1. 安装最新版本的docker
    curl -fsSL https://get.docker.com/ | sh
  2. 重启docker
    systemctl restart docker
  3. 设置docker开机启动
    systemctl enable docker

2. 安装DockerCompose

  1. 下载docker-compose的二进制版本
    sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. 开启可执行权限
    sudo chmod +x /usr/local/bin/docker-compose
  3. 查看版本号,检测是否安装成功
    docker-compose --version

3. 安装Harbor

  1. 下载安装包
    wget https://storage.googleapis.com/harbor-releases/release-1.10.0/harbor-offline-installer-v1.10.0.tgz
  2. 解压
    tar -zxvf ./harbor-offline-installer-v1.10.0.tgz
  3. 修改配置
    vim harbor/harbor.yml
    修改hostname为Harbor管理网站的访问IP或域名
    注释https配置,禁用https
  4. 安装
    harbor/install.sh
  5. 访问
    在浏览器输入配置的hostname和端口进行访问,初始账号密码为admin 和 Harbor12345

4. 安装Gitlab

  1. 使用docker-compose 进行安装
version: '3'
services:
    web:
      image: 'twang2218/gitlab-ce-zh'
      restart: always
      hostname: 'gitlab.example.com'
      environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://gitlab.example.com'
          gitlab_rails['gitlab_shell_ssh_port'] = 2222
          unicorn['port'] = 8888
          nginx['listen_port'] = 80
      ports:
        - '8088:80'
        - '2443:443'
        - '2222:22'
      volumes:
        - ./config:/etc/gitlab
        - ./data:/var/opt/gitlab
        - ./logs:/var/log/gitlab

hostname和external_url配置为访问的域名

5. 安装Jenkins

  1. 使用docker-compose 进行安装
version : '2'
services :
    jenkins:
        image : jenkinsci/blueocean
        user : root
        ports :
        - "8088:8080"
        volumes:
        - "./jenkins/jenkins_home:/var/jenkins_home:rw"
        - "/var/run/docker.sock:/var/run/docker.sock"
        networks:
        - jenkins-net
        container_name : jenkins
        # restart : always
networks: # 创建网络
    jenkins-net:
        driver: bridge

二. 问题

1. 安装Harbor问题

  1. ✖ Need to upgrade docker package to 17.06.0+.
    centos 7 升级docker
    查找已安装的docker
    rpm -qa | grep docker
    卸载docker
    yum remove docker-1.13.1-108.git4ef4b30.el7.centos.x86_64
    yum remove docker-client-1.13.1-108.git4ef4b30.el7.centos.x86_64
    yum remove docker-common-1.13.1-108.git4ef4b30.el7.centos.x86_64
    安装最新版本的docker
    curl -fsSL https://get.docker.com/ | sh
    重启docker
    systemctl restart docker
    设置docker开机启动
    systemctl enable docker

  2. 登录仓库报“http: server gave HTTP response to HTTPS client”

2. 配置gitlab问题

  1. 配置gitlab webhook 报“Error 403 No valid crumb was included in the request”
    新建groovy脚本,init_csrf_disable.groovy
import hudson.security.csrf.DefaultCrumbIssuer
import jenkins.model.Jenkins

def jenkins = Jenkins.instance;
jenkins.setCrumbIssuer(null); 
jenkins.save();

拷贝脚本至jenkins容器
docker cp init_csrf_disable.groovy jenkins:/usr/share/jenkins/ref/init.groovy.d/
重启jenkins容器
docker restart jenkins

相关标签: 运维 ci/cd