编辑
2023-08-27
笔记
0

目录

Gitea 安装部署
配置 SSH 直通(可选,不需要 SSH 协议同步无需此步骤,可以使用 https/http 协议同步代替)
docker-compose 安装部署
启用 Gitea Actions 内置的 CI/CD (持续集成、持续交付和持续部署)解决方案
配置 Gitea 服务器
生成 Gitea Runner 配置文件
docker-compose 安装 Gitea Runner 部署
配置仓库启用 Gitea Actions
相关连接

Gitea 安装部署

配置 SSH 直通(可选,不需要 SSH 协议同步无需此步骤,可以使用 https/http 协议同步代替)

bash
# 记录下 UID/GID 替换中的 USER_UID USER_GID sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git # 生成 SSH 密钥对 sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key" # ---------------------------------------------------------------- sudo -u git cat /home/git/.ssh/id_rsa.pub | sudo -u git tee -a /home/git/.ssh/authorized_keys sudo -u git chmod 600 /home/git/.ssh/authorized_keys cat <<"EOF" | sudo tee /usr/local/bin/gitea #!/bin/sh ssh -p 2222 -o StrictHostKeyChecking=no git@127.0.0.1 "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@" EOF sudo chmod +x /usr/local/bin/gitea

docker-compose 安装部署

  • docker-compose.yml
yaml
version: "3" services: caddy: container_name: caddy image: caddy:alpine restart: unless-stopped ports: - "80:80" - "80:80/udp" - "443:443" - "443:443/udp" volumes: - ./Caddyfile:/etc/caddy/Caddyfile gitea: container_name: gitea image: gitea/gitea:latest restart: unless-stopped # depends_on: # - redis environment: - USER=git - USER_UID=111 - USER_GID=122 volumes: - ./gitea:/data - /home/git/.ssh:/data/git/.ssh - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro ports: - "127.0.0.1:2222:22" # redis: # container_name: redis # image: redis:alpine # restart: unless-stopped # volumes: # - ./redis:/data
  • Caddyfile
Caddyfile
:80 { redir https://{host}{uri} } gitea.uing.vip { log { output stdout format console level ERROR } reverse_proxy gitea:3000 }

启用 Gitea Actions 内置的 CI/CD (持续集成、持续交付和持续部署)解决方案

配置 Gitea 服务器

bash
cat << EOF >> gitea/gitea/conf/app.ini [actions] ENABLED=true EOF docker-compose restart gitea

生成 Gitea Runner 配置文件

mkdir gitea_runner && cd gitea_runner docker run --entrypoint="" --rm -it gitea/act_runner:latest act_runner generate-config > config.yaml

docker-compose 安装 Gitea Runner 部署

  • docker-compose.yml
yaml
version: "3" services: gitea_runner: container_name: gitea_runner image: gitea/act_runner:latest # 如果使用服务器容器名称作为 URL HOST 的话,需要先启动 Gitea depends_on: - gitea environment: CONFIG_FILE: /config.yaml # Gitea 服务器地址(也可以是内网地址或者容器内部地址) GITEA_INSTANCE_URL: https://gitea.uing.vip # 获取地址 https://gitea.uing.vip/admin/actions/runners/ GITEA_RUNNER_REGISTRATION_TOKEN: "" # Runner名称(可选)。如果留空,将使用主机名 GITEA_RUNNER_NAME: "" GITEA_RUNNER_LABELS: "" volumes: - ./gitea_runner/config.yaml:/config.yaml - ./gitea_runner/data:/data - /var/run/docker.sock:/var/run/docker.sock

配置仓库启用 Gitea Actions

  1. 打开仓库设置 https://gitea.uing.vip/\<owner>/<repo>/settings
  2. 找到并勾选 启用 Actions ,并 更新仓库设置 保存设置

enable_actions

  1. 在仓库代码下新建目录 .gitea/workflows/,新建 Yaml 文件编写 Gitea Actions 执行代码
bash
git clone git@gitea.uing.vip:cainiao/gitea_runner.git cd gitea_runner && mkdir -p .gitea/workflows/ cat <<"EOF" > .gitea/workflows/demo.yaml name: Gitea Actions Demo run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 on: [push] jobs: Explore-Gitea-Actions: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - name: Check out repository code uses: actions/checkout@v3 - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - run: echo "🖥️ The workflow is now ready to test your code on the runner." - name: List files in the repository run: | ls ${{ gitea.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." EOF git add .gitea/workflows/demo.yaml git commit -m "add .gitea/workflows/demo.yaml" git push
  1. 在仓库的 Actions 下查看到执行过程及结果:https://gitea.uing.vip/\<owner>/<repo>/actions

相关连接

本文作者:菜鸟

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可协议。转载请注明出处!