其他分享
首页 > 其他分享> > Docker+Gitea+Drone快速搭建轻量级自动化部署(CI/CD)平台

Docker+Gitea+Drone快速搭建轻量级自动化部署(CI/CD)平台

作者:互联网

一、安装Docker

1.1 安装excpet

$ apt-get -f install expect

1.2 编写执行Docker安装脚本

  1. 编写docker_dep.exp脚本
#!/usr/bin/expect

set timeout 5
spawn apt install apt-transport-https ca-certificates software-properties-common curl
expect "Y/n"
send "y\n"
interact
  1. 编辑docker.sh脚本
#!/bin/bash

expect docker_dep.exp

echo "安装docker基本依赖完成"

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | apt-key add -

echo "添加docker gpg key完成"

add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch stable"

echo "添加docker源完成"

apt update

echo "更新apt源完成"

expect docker.exp

echo "安装docker-ce完成"

echo "{
\"registry-mirrors\": [\"https://exmmtkzp.mirror.aliyuncs.com\"]
}" > /etc/docker/daemon.json

systemctl restart docker

echo "更新docker镜像为阿里云完成"
  1. 编辑docker.exp脚本
#!/usr/bin/expect

set timeout 5
spawn apt-get install docker-ce
expect "Y/n"
send "y\n"
interact
  1. 执行docker.sh脚本

Docker运行Gitea

1)先将系统22端口空闲出来,即将默认ssh端口改为其他端口。

2)启动Gitea

# 创建文件目录
mkdir -p gitea/data

# 启动gitea
docker run -d --privileged=true --restart=always --name=gitea -p 22:22 -p 3000:3000 -v $PWD/gitea/data:/data gitea/gitea

# 移除旧容器
docker stop gitea && docker rm gitea

如果出现添加ssh的key到gitea服务器上,仍然无法推送,可尝试新建ssh key再配置一次。

Docker运行Drone

# 生成open SSL, 然后赋值给下面的DRONE_RPC_SECRET
openssl rand -hex 16

# docker 启动 drone,先在gitea中添加Oauth2的ClientID和ClientSecret给drone
docker run \
  --volume=$PWD/drone:/data \
  --env=DRONE_GITEA_SERVER=http://gitea.sleepyocean.cn \
  --env=DRONE_GITEA_CLIENT_ID=2a059034-9124-47a7-9394-1a9919c7058e \
  --env=DRONE_GITEA_CLIENT_SECRET=rAmdK9kFGj12Zqqib0XMJmYmYTFPk1hegnRX7KK5JA02 \
  --env=DRONE_RPC_SECRET=9583246268b343abfc51410a6c418622 \
  --env=DRONE_SERVER_HOST=drone.sleepyocean.cn \
  --publish=10080:80 \
  --publish=10443:443 \
  --restart=always \
  --detach=true \
  --name=drone \
  drone/drone:2.11
  

# docker 启动 pipeline for drone
docker run -d \
-e DRONE_RPC_PROTO=http \
-e DRONE_RPC_HOST=drone.sleepyocean.cn:10080 \
-e DRONE_RPC_SECRET=9583246268b343abfc51410a6c418622 \
-e DRONE_DEBUG=true \
-p 10081:3000 \
--restart always \
--name ssh-runner \
drone/drone-runner-ssh:linux-amd64


# 停止并删除容器
docker stop drone && docker rm drone

标签:CI,gitea,--,Gitea,DRONE,apt,drone,docker,轻量级
来源: https://www.cnblogs.com/sleepyocean/p/16141114.html