`

gitea 和 drone的ci集成配置笔记

 
阅读更多

https://docs.gitea.io/en-us/install-with-docker/ (gitea相关文档)

https://docs.drone.io/ (drone的官方文档)

 

目前是在我mac本机采用docker-compose方式实现的

1、首先安装docker等软件;

2、安装gitea和 drone,直接给出相关的docker-compose.yml文件:

version: "3.7"
services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    ports:
      - "10022:22"
      - "13000:3000"
    environment:
      - APP_NAME="yjph83 Gitea Git with a cup of tea"
      - RUN_MODE=dev
      - HTTP_PORT=3000
      - ROOT_URL="http://drone-gitea-server:13000"
      - LOCAL_ROOT_URL="http://drone-gitea-server:13000"
      - DB_TYPE=mysql
      - DB_HOST=db-server:3306
      - DB_NAME=gitea
      - DB_USER=root
      - DB_PASSWD=password
      - TZ=Asia/Shanghai
    volumes:
      - /Volumes/data/develop/dockers/gitea/_data:/data:rw
    restart: always
    networks:
      - default
    extra_hosts:
      - db-server:10.9.37.87
      - drone-gitea-server:10.9.37.87

  drone-server:
    image: drone/drone:latest
    container_name: drone-server
    ports:
      - "8080:80"
      - "8443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /Volumes/data/develop/dockers/drone/_data:/data:rw
    restart: always
    environment:
      - DRONE_GITEA_SERVER=http://drone-gitea-server:13000
      - DRONE_RUNNER_CAPACITY=2
      - DRONE_SERVER_HOST=drone-server-api:8080
      - DRONE_GITEA_CLIENT_ID=fcf59681-0d8e-4918-8bae-fe6e649d457c
      - DRONE_GITEA_CLIENT_SECRET=6mBkAkG7uE0Rs7dt_9rHZ9jkcWLktjbD5wkeUvoOUpI=
      - DRONE_USER_CREATE=username:yjph83,admin:true
      - DRONE_RPC_SECRET=9c3921e3e748aff725d2e16ef31fbc42
      - DRONE_LOGS_DEBUG=true
      - TZ=Asia/Shanghai
    networks:
      - default
    extra_hosts:
      - drone-gitea-server:10.9.37.87
      - drone-server-api:10.9.37.87

  drone-runner:
    image: drone/drone-runner-docker
    container_name: drone-runner
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    restart: always
    environment:
      - DRONE_RPC_PROTO=http
      - DRONE_RPC_HOST=drone-server-api:8080
      - DRONE_RPC_SECRET=9c3921e3e748aff725d2e16ef31fbc42
      - DRONE_RUNNER_CAPACITY=2
      - DRONE_RUNNER_NAME=drone-runner
      - DRONE_LOGS_DEBUG=true
      - TZ=Asia/Shanghai
    ports:
      - "23000:3000"
    networks:
      - default   
    extra_hosts:
      - drone-server-api:10.9.37.87
      - drone-gitea-server:10.9.37.87


networks:
  default:

 注意:

- HTTP_PORT=3000
- ROOT_URL="http://drone-gitea-server:13000"
- LOCAL_ROOT_URL="http://drone-gitea-server:13000"

 

如果:映射的外端口不是3000, 最好配置ROOT_URL 和 LOCAL_ROOT_URL两个属性;否则只能在app.in i中修改SSH_DOMAIN、DOMAIN、ROOT_URL属性配置并重启;

[server]
APP_DATA_PATH    = /data/gitea
SSH_DOMAIN       = drone-gitea-server
HTTP_PORT        = 3000
ROOT_URL         = http://drone-gitea-server:13000/
DISABLE_SSH      = false
SSH_PORT         = 22
SSH_LISTEN_PORT  = 22
LFS_START_SERVER = true
LFS_CONTENT_PATH = /data/git/lfs
DOMAIN           = drone-gitea-server
LFS_JWT_SECRET   = -gfnZXF4v0kBretZgNMp2XyZkV3i7CxmMnnswgFir_Q
OFFLINE_MODE     = false

 gitea连接的需要mysql,我是单独的docker 启动方式;如果安装需要自己修改对应属性的值;

当这些启动好后则需要在gitea上注册,配置管理员用户, 同时在安装drone时,配置的

- DRONE_USER_CREATE=username:yjph83,admin:true

如果是gitea中存在的用户,则不用配置token,该处表示yjph83 是drone 的管理员,admin:true 就表示管理员角色;

以下的配置是先不用管, 当gitea中添加drone应用后自动生成后,再来修改配置,重启docker

- DRONE_GITEA_CLIENT_ID=fcf59681-0d8e-4918-8bae-fe6e649d457c
- DRONE_GITEA_CLIENT_SECRET=6mBkAkG7uE0Rs7dt_9rHZ9jkcWLktjbD5wkeUvoOUpI=

gitea服务的注册、登录就自行百度了,

配置在gitea页面上配置drone的回调路径则必须和配置上一致:

 

http://drone-server-api:8080/login

 与

- DRONE_SERVER_HOST=drone-server-api:8080

相对应

drone的配置在drone服务上登录后会自动跳转同步gitea上的项目后,激活drone 服务即可;

drone的demo如下:

global-variables:
  git-image: &git-image reg.xxxx.io/library/git
  repo-image: &repo-image reg.xxxx.io/xxh/pipeline-backend
  step-when: &step-when
    when:
      branch: [ master ]
      event: [ push ]

#定义工作空间和路径
workspace:
  base: /goworkspace
  path: /goworkspace
kind: pipeline
name: default

clone:
  # 指定克隆深度
  depth:  50
  # 禁用默认的clone行为
  disable:  true

steps:
# clone
  - name: clone-code
    image: *git-image
    commands:
      - git clone --branch ${DRONE_BRANCH} ${DRONE_GIT_HTTP_URL}

# 编译构建
  - name: build
    image: reg.xxxx.io/library/golangci-lint:v1.21.0
    volumes:
      - name: cache
        path: /go/pkg/mod
    commands:
      - go env -w GOPROXY=https://goproxy.cn,direct
      - go env -w GOPRIVATE=code.xxxx.com
      - export GO111MODULE=on
      - cd ${DRONE_REPO_NAME}
      - go mod tidy
      - go build -o pipeline/main ./cmd/pipeline/main.go
    <<: *step-when

# 打镜像
  - name: dev-docker
    image: plugins/docker
    pull: never
    commands:
      - cd ${DRONE_REPO_NAME}
    settings:
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
      repo: *repo-image
      tags:
        - daily
      registry: reg.xxxx.io
      dockerfile: ./Dockerfile
    <<: *step-when

# 定义主机的磁盘目录
volumes:
  - name: cache
    host:
      path: /tmp/cache

 该过程是将默认的 git clone 提取出来自定义;

还可以不用自定义

workspace:
  base: /goworkspace
kind: pipeline
name: default

steps:
# 编译构建
  - name: build
    image: reg.xxxx.io/library/golangci-lint:v1.21.0
    volumes:
      - name: cache
        path: /go/pkg/mod
    commands:
      - go env -w GOPROXY=https://goproxy.io,direct
      - go env -w GOPRIVATE=drone-gitea-server
      - export GO111MODULE=on
      - go mod tidy
      - go build -o pipeline/main ./cmd/pipeline/main.go
    when:
      branch:
        - master
      event:
        - push
# 打镜像
  - name: dev-docker
    image: plugins/docker
    pull: never
    settings:
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
      repo: reg.xxxx.io/xxh/pipeline-backend
      tags:
        - daily
      registry: reg.xxxx.io
      dockerfile: ./Dockerfile
    when:
      branch: [ master ]
      event: [ push ]

volumes:
  - name: cache
    host:
      path: /tmp/cache

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics