Ci&di方案

Posted by Wh0ami-hy on July 9, 2024

1. 方案

Gitness

资源占用少,个人开发者

gitlab + gitlab自带的CI/CD

小型团队

gitlab + Jenkins

大型团队

2. Gitness

https://docs.gitness.com/

3. Gitlab + Jenkins

version: '3'
services:
  jenkins:
    image: 'jenkins/jenkins:2.60.2-alpine'
    container_name: jenkins
    hostname: jenkins
    ports:
      - "8081:8080"
      - "50001:50000"
    volumes:
      - /data/jenkins:/var/jenkins_home
      - /data/home/:/home
      - /var/run/docker.sock:/var/run/docker.sock
      - /bin/docker:/bin/docker #宿主机的docker可执行映射到镜像里面 后面build的时候会用到
    privileged: true

4. Gitlab + Gitlab Runner

Gitlab只是个代码仓库,想要实现CI/CD还需安装gitlab-runnergitlab-runner相当于Gitlab中任务的执行器,Gitlab会在需要执行任务时调用它

下载gitlab-runner的Docker镜像,选用alpine-bleeding,这个版本非常小巧。完整版可以选择latest

docker pull gitlab/gitlab-runner:alpine-bleeding

创建文件docker-compose.yml

version: '3.6'
name: gitlab
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    hostname: '192.168.163.129'
    privileged: true
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.163.129:8929'
        gitlab_rails['time_zone'] = 'Asia/Shanghai'
      GITLAB_ROOT_PASSWORD: 'Ytjt@123' # 这里设置密码,要大小写和数字
    ports:
      - '8929:8929'
      - '443:443'
      - '2424:22'
    volumes:
      - './gitlab/config:/etc/gitlab'
      - './gitlab/logs:/var/log/gitlab'
      - './gitlab/data:/var/opt/gitlab'
    shm_size: '256m'
      

  gitlab-runner:
    image: 'gitlab/gitlab-runner:alpine-bleeding' # alpine-bleeding很精简,完整版用latest
    container_name: gitlab-runner
    privileged: true
    restart: always
    volumes:
      # 这两步骤是为了让容器内的gitlab-runner可以访问到docker
      - /var/run/docker.sock:/var/run/docker.sock
      - /bin/docker:/bin/dcoker
      # 将当前目录的config文件,映射到容器的/etc/gitlab-runner目录
      - ./gitlab-runner:/etc/gitlab-runner
    environment:
      # 也是指定docker
      RUNNER_EXECUTOR: "docker"
    depends_on:
      - gitlab

networks:
  gitlab:
    external: true

注册时会出现交互界面,提示你输入注册地址、token、执行器类型等信息,执行器建议选择ssh,ssh能远程执行Linux命令,推荐使用这个


本站总访问量