Drone+Gitea搭建

安装docker和docker-compose

不同的Linux系统安装方式均不相同,请参见 菜鸟教程Docker安装;

其次,安装docker-compose,请参见 菜鸟教程docker-compose安装;

DaoCloud快速安装命令如下:

# 安装docker
curl -sSL https://get.daocloud.io/docker | sh

# 安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.1.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

安装Gitea

根据docker-compose的语法编写yml文件,文件内容如下:

version: "3.7"
services:
    mysql:
        container_name: mysql
        image: mysql:5.7
        restart: always
        ports:
            - "8306:3306"
        volumes:
            - ./mysql/data:/var/lib/mysql:rw
            - ./logs/mysql:/var/log/mysql:rw
        environment:
            MYSQL_ROOT_PASSWORD: "password"
            TZ: "$TZ"
    gitea:
        container_name: gitea
        image: gitea/gitea:latest
        restart: always
        ports:
            - "13000:3000"
            - "10022:22"
        environment:
            - TZ=${TZ}
            - USER_UID=1000
            - USER_GID=1000
        volumes:
            - ./gitea:/data
    drone-server:
        container_name: drone-server
        image: drone/drone:latest
        restart: always
        ports:
            - "8888:80"
        volumes:
            - ./drone:/var/lib/drone/
            - /var/run/docker.sock:/var/run/docker.sock
        environment:
            - DRONE_SERVER_HOST=${DRONE_SERVER_HOST}
            - DRONE_SERVER_PROTO=${DRONE_SERVER_PROTO}
            - DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
            # Gitea Config
            - DRONE_GITEA_CLIENT_ID=${DRONE_GITEA_CLIENT_ID}
            - DRONE_GITEA_CLIENT_SECRET=${DRONE_GITEA_CLIENT_SECRET}
            - DRONE_GITEA_SERVER=${DRONE_GITEA_SERVER}
            - DRONE_DATABASE_DATASOURCE=${DRONE_DATABASE_DATASOURCE}
            - DRONE_DATABASE_DRIVER=${DRONE_DATABASE_DRIVER}
            - DRONE_USER_CREATE=username:root,admin:true
    drone-runner-docker:
        container_name: drone-runner-docker
        image: drone/drone-runner-docker:latest
        restart: always
        depends_on:
            - drone-server
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
        environment:
            - TZ=${TZ}
            - DRONE_RPC_HOST=drone-server
            - DRONE_RPC_PROTO=${DRONE_RPC_PROTO}
            - DRONE_RPC_SECRET=${DRONE_RPC_SECRET}
            - DRONE_RUNNER_CAPACITY=${DRONE_RUNNER_CAPACITY}
            - DRONE_RUNNER_NAME=${DRONE_RUNNER_NAME}

本次搭建采用容器虚拟化mysql数据库,可替换为其它数据库实例;

编写语法,可以在菜鸟教程中查看并学习;

Gitea安装支持多种方式,Docker安装方式请参见 Docker安装Gitea;

执行 docker-compose up -d gitea 命令,可正常启动服务;

使用浏览器访问Gitea安装页面,访问 http://server-ip:3000 并遵循安装向导。

安装Drone

drone-server安装参见官网 Gitea安装文档,请先详细了解各配置项含义,.env示例文件如下:

# 时区
TZ=Asia/Shanghai

# Drone-server
DRONE_SERVER_HOST=ip:8888
DRONE_SERVER_PROTO=http
DRONE_RPC_SECRET=secret

# Gitea
DRONE_GITEA_CLIENT_ID=client_id
DRONE_GITEA_CLIENT_SECRET=client_secret
DRONE_GITEA_SERVER=http://ip:13000/
DRONE_DATABASE_DATASOURCE=root:password@tcp(mysql:3306)/drone
DRONE_DATABASE_DRIVER=mysql

# Drone-runner-docker
DRONE_RPC_PROTO=http
DRONE_RUNNER_CAPACITY=2
DRONE_RUNNER_NAME=docker-runner

当前最新版的Done使用OAuth2与Gitea进行授权通信,进入Gitea界面;

在个人设置中的应用->管理OAuth2应用程序中创建应用,输入应用名称Drone和Drone登录跳转的url地址,比如:http://drone-server/login;

创建应用后将得到客户端IP和客户端密钥,将其配置在.env文件中的DRONE_GITEA_CLIENT_ID和DRONE_GITEA_CLIENT_SECRET;

执行 docker-compose up -d drone-server 命令,可正常启动服务,访问 http://drone-server/login 会自动跳转到Gitea进行授权登录。

你可能感兴趣的:(Drone+Gitea搭建)