{"id":23800088,"url":"https://github.com/sobird/gitea","last_synced_at":"2026-02-27T08:02:47.546Z","repository":{"id":234062864,"uuid":"788232438","full_name":"sobird/gitea","owner":"sobird","description":"Deploy gitea and actions by docker compose","archived":false,"fork":false,"pushed_at":"2024-11-16T11:44:42.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-01T21:34:53.871Z","etag":null,"topics":["git-runner","gitea","gitea-ac"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sobird.png","metadata":{"files":{"readme":"README.asciidoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-18T02:51:04.000Z","updated_at":"2024-11-16T11:44:46.000Z","dependencies_parsed_at":"2024-11-16T12:23:58.399Z","dependency_job_id":"a1b34a9a-4712-4cdc-9861-a51a28907ad5","html_url":"https://github.com/sobird/gitea","commit_stats":null,"previous_names":["sobird/gitea"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobird%2Fgitea","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobird%2Fgitea/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobird%2Fgitea/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobird%2Fgitea/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sobird","download_url":"https://codeload.github.com/sobird/gitea/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240042238,"owners_count":19738836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git-runner","gitea","gitea-ac"],"created_at":"2025-01-01T21:34:22.687Z","updated_at":"2026-02-27T08:02:47.450Z","avatar_url":"https://github.com/sobird.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gitea搭建与Actions配置\n:toc:\n\n\u003e Gitea 是一个开源社区驱动的轻量级代码托管解决方案，后端采用 Go 编写，具有轻量级、支持多种部署方式、支持Actions等优点。\n\n本文在 `macOS` 平台下进行搭建配置，其他平台，操作命令可能略有不同，请自行适配修改。\n\n## 安装\n\n### Docker方式安装\n通过 `docker compose` 安装，新建 `docker-compose.yml` 文件：\n\n```yml\nversion: \"3\"\nservices:\n  gitea:\n    image: gitea/gitea:1.21.0\n    container_name: gitea\n    environment:\n      - USER_UID=1000\n      - USER_GID=1000\n      - GITEA__database__DB_TYPE=postgres\n      - GITEA__database__HOST=db:5432\n      - GITEA__database__NAME=gitea\n      - GITEA__database__USER=gitea\n      - GITEA__database__PASSWD=gitea\n    networks:\n      - gitea_net\n    volumes:\n      - ./gitea_data:/data\n    ports:\n      - \"3000:3000\"\n      - \"10022:22\"\n    depends_on:\n      - db\n\n  db:\n    image: postgres:15\n    environment:\n      - POSTGRES_USER=gitea\n      - POSTGRES_PASSWORD=gitea\n      - POSTGRES_DB=gitea\n    networks:\n      - gitea_net\n    volumes:\n      - ./gitea_postgres_data:/var/lib/postgresql/data\n  \n  # 以容器的方式运行 act_runner 相关配置\n  act_runner:\n    image: gitea/act_runner:latest\n    container_name: act_runner\n    restart: always\n    depends_on:\n      - gitea\n    networks:\n      - gitea_net\n    environment:\n      # - CONFIG_FILE=/config.yaml\n      - GITEA_INSTANCE_URL=http://gitea:3000/\n      - GITEA_RUNNER_REGISTRATION_TOKEN=\u003ctoken\u003e\n      # - GITEA_RUNNER_REGISTRATION_TOKEN_FILE=path/to/token # 也支持从文件中读取token\n      - GITEA_RUNNER_NAME=act_runner\n      # runs-on 的标签实际上是下面这个，上面的只是名字\n      # GITEA_RUNNER_LABELS: \"ubuntu-latest\"\n      # GITEA_MAX_REG_ATTEMPTS\n      # RUNNER_STATE_FILE\n    volumes:\n      # - ./act_runner/config.yaml:/config.yaml\n      - ./act_runner/data:/\n      # 将容器中的缓存目录映射到宿主机\n      - ./act_runner/cache:/root/.cache\n      - /var/run/docker.sock:/var/run/docker.sock\n\n# volumes:\n#   gitea_data:\n#   gitea_postgres_data:\n\nnetworks:\n  gitea_net:\n```\n\n在 `docker-compose.yml` 所在的目录运行 `docker-compose up -d`，启动应用。\n\n### 其他方式安装\n\n其他安装方式或更换数据库类型，可自行查阅官方文档 link:https://docs.gitea.cn/category/installation[installation]\n\n## 站点配置\n\n访问地址 \u003chttp://127.0.0.1:3000\u003e， 初次访问需要配置站点数据，之后就和github等代码仓库类似了。\n\n## Gitea Actions 搭建\n\n### gitea开启actions\n\n修改 `gitea/conf/app.ini` 配置，若使用docker部署，可通过 `docker exec -it ${容器id} /bin/bash` 进入内部修改，修改完后重启 gitea 容器。如果配置了\n\n```yml\n    volumes:\n      - ./gitea_data:/data\n```\n\n则可，直接编辑 `./gitea_data/gitea/conf/app.ini` 即可。\n\n```yml\n# 添加此配置\n[actions]\nENABLED = true\n```\n\n### 查看Gitea Runner token\n\n访问 link:http://localhost:3000/admin/actions/runners[Runners]，点击创建Runner会出现一个token，复制此token。\n\n### 配置act runner\n\n#### 以容器方式运行\n\n参阅上面的 `docker-compose.yml` 配置文件中 `act_runner` 部分。\n\n#### 运行在物理机上\n\n```sh\ngit clone https://gitea.com/gitea/act_runner.git\n\nexport GOPROXY=https://goproxy.cn\n\ncd act_runner\nmake build\n\n# 可根据帮助 自行配置\n./act_runner -h\n\n# 注册 runner 根据提示进行配置\n./act_runner register\n```\n\n### 查看\n返回 link:http://localhost:3000/admin/actions/runners[Runners]，即可看到加入的runner，且状态为 空闲。\n\n## 测试\n\n### 创建测试仓库\n创建名为 `actions-test` 的仓库，在设置中开启 Actions。\n\n为方便操作可将仓库克隆到本地\n```sh\ngit clone http://localhost:3000/sobird/actions-test.git\n```\n\n### 添加工作流文件\n\n以下是一个示例，将 `.gitea/workflows/build.yaml` push 到仓库时会触发 CI 工作，yaml 语法可参考 link:https://docs.github.com/zh/actions/using-workflows/workflow-syntax-for-github-actions[Github Actions Docs]\n\n```yml\nname: Gitea Actions Test\nrun-name: ${{ github.actor }} is testing out Gitea Actions  \non: [push]\njobs:\n  Explore-Gitea-Actions:\n    runs-on: ubuntu-latest\n    steps:\n      - run: echo \"  The job was automatically triggered by a ${{ github.event_name }} event.\"\n      - run: echo \"  This job is now running on a ${{ runner.os }} server hosted by Gitea!\"\n      - run: echo \"  The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.\"\n      - name: Check out repository code\n        uses: actions/checkout@v3\n      - run: echo \"  The ${{ github.repository }} repository has been cloned to the runner.\"\n      - run: echo \" ️ The workflow is now ready to test your code on the runner.\"\n      - name: List files in the repository\n        run: |\n          ls ${{ github.workspace }}\n      - run: echo \"  This job's status is ${{ job.status }}.\"\n```\n\n### 查看运行结果\n\n当代码提交到远程仓库，即会触发上面配置的工作流，访问 link:http://localhost:3000/sobird/actions-test/actions[actions] 进行查看。\n\n## 配置 config.yaml\n\n可通过 `docker run --entrypoint=\"\" --rm -it gitea/act_runner:latest act_runner generate-config \u003e config.yaml` 生成，并将生成的配置文件拷贝到本地 `./act_runner`。\n\n```sh\ndocker cp 3d17a8d385b3:/config.yaml ./act_runner\n```\n\n或者直接复制下面的 config.yaml 到本地 ./act_runner 目录\n\n整个 `config.yaml` 配置文件如下：\n\n```yml\n# Example configuration file, it's safe to copy this as the default config file without any modification.\n\n# You don't have to copy this file to your instance,\n# just run `./act_runner generate-config \u003e config.yaml` to generate a config file.\n\nlog:\n  # The level of logging, can be trace, debug, info, warn, error, fatal\n  level: info\n\nrunner:\n  # Where to store the registration result.\n  file: .runner\n  # Execute how many tasks concurrently at the same time.\n  capacity: 1\n  # Extra environment variables to run jobs.\n  envs:\n    A_TEST_ENV_NAME_1: a_test_env_value_1\n    A_TEST_ENV_NAME_2: a_test_env_value_2\n  # Extra environment variables to run jobs from a file.\n  # It will be ignored if it's empty or the file doesn't exist.\n  env_file: .env\n  # The timeout for a job to be finished.\n  # Please note that the Gitea instance also has a timeout (3h by default) for the job.\n  # So the job could be stopped by the Gitea instance if it's timeout is shorter than this.\n  timeout: 3h\n  # Whether skip verifying the TLS certificate of the Gitea instance.\n  insecure: false\n  # The timeout for fetching the job from the Gitea instance.\n  fetch_timeout: 5s\n  # The interval for fetching the job from the Gitea instance.\n  fetch_interval: 2s\n  # The labels of a runner are used to determine which jobs the runner can run, and how to run them.\n  # Like: \"macos-arm64:host\" or \"ubuntu-latest:docker://gitea/runner-images:ubuntu-latest\"\n  # Find more images provided by Gitea at https://gitea.com/gitea/runner-images .\n  # If it's empty when registering, it will ask for inputting labels.\n  # If it's empty when execute `daemon`, will use labels in `.runner` file.\n  labels:\n    - \"ubuntu-latest:docker://gitea/runner-images:ubuntu-latest\"\n    - \"ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04\"\n    - \"ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04\"\n\ncache:\n  # Enable cache server to use actions/cache.\n  enabled: true\n  # The directory to store the cache data.\n  # If it's empty, the cache data will be stored in $HOME/.cache/actcache.\n  dir: \"\"\n  # The host of the cache server.\n  # It's not for the address to listen, but the address to connect from job containers.\n  # So 0.0.0.0 is a bad choice, leave it empty to detect automatically.\n  host: \"\"\n  # The port of the cache server.\n  # 0 means to use a random available port.\n  port: 0\n  # The external cache server URL. Valid only when enable is true.\n  # If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.\n  # The URL should generally end with \"/\".\n  external_server: \"\"\n\ncontainer:\n  # Specifies the network to which the container will connect.\n  # Could be host, bridge or the name of a custom network.\n  # If it's empty, act_runner will create a network automatically.\n  network: \"gitea_gitea_net\"\n  # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).\n  privileged: false\n  # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).\n  options:\n  # The parent directory of a job's working directory.\n  # NOTE: There is no need to add the first '/' of the path as act_runner will add it automatically. \n  # If the path starts with '/', the '/' will be trimmed.\n  # For example, if the parent directory is /path/to/my/dir, workdir_parent should be path/to/my/dir\n  # If it's empty, /workspace will be used.\n  workdir_parent:\n  # Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob\n  # You can specify multiple volumes. If the sequence is empty, no volumes can be mounted.\n  # For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to:\n  # valid_volumes:\n  #   - data\n  #   - /src/*.json\n  # If you want to allow any volume, please use the following configuration:\n  # valid_volumes:\n  #   - '**'\n  valid_volumes: []\n  # overrides the docker client host with the specified one.\n  # If it's empty, act_runner will find an available docker host automatically.\n  # If it's \"-\", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers.\n  # If it's not empty or \"-\", the specified docker host will be used. An error will be returned if it doesn't work.\n  docker_host: \"\"\n  # Pull docker image(s) even if already present\n  force_pull: true\n  # Rebuild docker image(s) even if already present\n  force_rebuild: false\n\nhost:\n  # The parent directory of a job's working directory.\n  # If it's empty, $HOME/.cache/act/ will be used.\n  workdir_parent:\n```\n\n需要注意的是，要配置 `container.network` (如上所示)，否则工作流中的 `actions/checkout@v3` 无法签出代码。\n\n修改 `docker-compose.yml` 配置后，重启生效\n```yml\n...\n    environment:\n      # 原来的注释打开\n      - CONFIG_FILE=/config.yaml\n      - GITEA_INSTANCE_URL=http://gitea:3000/\n      - GITEA_RUNNER_REGISTRATION_TOKEN=\u003ctoken\u003e # 复制的token\n      - GITEA_RUNNER_NAME=act_runner\n      # runs-on 的标签实际上是下面这个，上面的只是名字\n      # GITEA_RUNNER_LABELS: \"ubuntu-latest\"\n    volumes:\n      # 原来的注释打开\n      - ./act_runner/config.yaml:/config.yaml\n      - ./act_runner/data:/data\n      - ./act_runner/cache:/root/.cache\n      - /var/run/docker.sock:/var/run/docker.sock\n...\n```\n\n## 使用变量\n### 默认上下文变量\n在编写步骤文件时，可以直接使用默认的变量来实现想要的功能，语法为 ${{ xxx }}，具体有哪些变量可查看 link:https://docs.github.com/zh/actions/learn-github-actions/contexts#github-context[Github Actions Context Docs]。\n\n```yml\n- run: echo ${{ github.ref }}\n- run: echo ${{ github.repository }}\n```\n\n输出\n```\nrefs/heads/main\nseepine/actions-test\n```\n\n### 环境变量\n环境变量分为默认环境变量和自定义环境变量，语法为 ${{ env.xxx }}，具体请查看 link:https://docs.github.com/zh/actions/learn-github-actions/variables#default-environment-variables[Github Actions Variables Docs]\n\n```yml\njobs:\n  Explore-Gitea-Actions:\n    runs-on: ubuntu-latest\n    # 自定义方式一\n    env:\n      CUSTOM_KEY: custom env value\n    steps:\n      # 自定义方式二\n      - run: echo CUSTOM_TOKEN=asdf1234 \u003e\u003e $GITHUB_ENV\n\n      - run: echo ${{ env.GITHUB_ACTION_REPOSITORY }}\n      - run: echo ${{ env.CUSTOM_KEY }}\n      - run: echo ${{ env.CUSTOM_TOKEN }}\n```\n\n输出\n\n```\nsobird/actions-test\ncustom env value\nasdf1234\n```\n\n### Secrets变量\n一般用于定义密码等敏感变量，此变量输出时会变成*，但不影响使用，在 `设置-Secrets` 中添加Key-Value即可\n\n```yml\n- run: echo ${{ secrets.CUSTOM_KEY }}\n```\n\n输出\n\n```\n***\n```\n\n### output\n许多时候我们会需要输出一些特定内容供他人获取，若输出到环境变量，我们很难随心定义key，因为有可能会与其他步骤的环境变量冲突而覆盖它，因此出现了output这个用法，最常见的即 link:https://github.com/docker/metadata-action[Docker metadata]\n\n```yml\njobs:\n  Explore-Gitea-Actions:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Gen Meta\n        id: my_meta # 指定一个id\n        run: echo CUSTOM_TOKEN=asdf1234 \u003e\u003e $GITHUB_OUTPUT\n\n      - run: echo ${{ steps.my_meta.outputs.CUSTOM_TOKEN }}\n```\n\n输出\n\n```\nasdf1234\n```\n\n## 进阶用法\n### 指定工作流运行 runner\n若有多个runner节点，我们想指定某个工作流程运行在特定runner上，可在不同runner指定不同label用于区分（可在Runner管理面板，编辑其 labels），例如分别有两个 runner 是 linux 环境和 windows 环境，因此分别设置label为 `linux_runner` 和 `windows_runner`。\n\n```yml\njobs:\n  Explore-Gitea-Actions:\n    runs-on: linux_runner\n    runs-on: windows_runner\n```\n\n### 使用Github的步骤脚本\n在编写步骤配置时，通常都会引用别人写好的脚本，例如\n\n```yml\n- name: Login to DockerHub\n  uses: docker/login-action@v2\n\n- name: Login to DockerHub\n  uses: my_custom/other-action@v2\n```\n\n此时 Gitea Actions 不一定能正常工作，因为它在\n\n* \u003c 1.20 默认是访问 Gitea.com这个代码托管仓库，因此若脚本是在 Github 上时，它将无法下载脚本内容\n* \u003e= 1.20 默认访问 Github.com\n\n所以当出现下载有问题时，我们可以完整写明脚本地址，例如\n\n```yml\n- name: Login to DockerHub\n  uses: https://github.com/my_custom/other-action@v2\n```\n\n也可以通过修改gitea的 `app.ini` 配置，改为从相应的仓库下载\n\n```yml\n[actions]\n# 1.19 可直接填写任意url如：https://github.com\n# 1.20起，不填默认从 github，填self表示从自建仓库下载\nDEFAULT_ACTIONS_URL = self\n```\n\n### 使用 docker\n在 Github Actions 中，默认工作环境可以直接使用 `docker` 命令，因此网上搜的 Github actions 构建 docker 镜像等配置，放在 Gitea Actions 中运行不了，因为 gitea act_runner 默认运行镜像是 `node:16-bullseye` ，并没有 docker 环境，详见工单link:https://gitea.com/gitea/act_runner/issues/63#issuecomment-733637[Gitea act_runner issue]，最简单的解决办法是手动指定运行容器镜像。\n\n```sh\njobs:\n  My-Gitea-Actions:\n    runs-on: ubuntu-latest\n    # 此容器可使用docker，可查看 https://github.com/catthehacker/docker_images\n    container: catthehacker/ubuntu:act-latest\n    steps:\n      - run: docker version\n```\n\n在我本地Mac测试，不指定容器，目前也可运行 `docker version`\n\n### 缓存工具目录\n在步骤中安装构建工具时，例如 `actions-setup` 、 `actions-node` 等，它们都会去下载对应二进制文件，再解压到例如 `/opt/hostedtoolcache` 目录中，最后再配置环境变量，使得容器中能够使用相应的环境，例如\n\n```yml\njobs:\n  Explore-Gitea-Actions:\n    runs-on: ubuntu-latest\n    steps:\n      # 安装node环境\n      - name: Setup Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: 20\n          registry-url: https://registry.npmjs.org/\n\n      - run: node -v\n```\n\n你会发现，每次执行工作流时，它都会重新下载二进制文件，并不会像 Github Actions 一样第一次下载，第二次因有缓存直接跳过，详情可查看工单link:https://gitea.com/gitea/act_runner/issues/70[cache tool folder]，在 act_runner 修复此问题之前，我们可以指定环境变量 RUNNER_TOOL_CACHE 或借助 docker volume 来实现缓存功能\n\n```yml\njobs:\n  Explore-Gitea-Actions:\n    runs-on: ubuntu-latest\n    container: \n      image: catthehacker/ubuntu:act-latest\n      # 方法二，手动指定持久化目录\n      volumes:\n        - ubuntu_hostedtoolcache:/opt/hostedtoolcache\n    env:\n      # 方法一，指定容器将工具缓存路径存放到 /toolcache ，该目录actRunner会默认持久化它\n      RUNNER_TOOL_CACHE: /toolcache\n    steps:\n      - name: Setup Node\n        uses: actions/setup-node@v4\n        with:\n          node-version: 20\n          registry-url: https://registry.npmjs.org/\n\n      - run: node -v\n```\n\n目前，gitea 已经解决此问题，默认会缓存到宿主机 `/var/lib/docker/volumes/act-toolcache/_data`。\n\n### 支持多任务运行\n\n修改 `config.yaml` 配置\n\n```yml\nrunner:\n  # 修改此数字，3表示同时支持3个任务并行，数量最好根据你机器性能和所跑任务负载统一决定，并不是越高越好\n  capacity: 3\n```\n\n### 使用 actions/cache 超时\n\n如果是通过docker部署的 act_runner ，因为容器隔离特性，其他运行的任务容器，无法访问到 act_runner 的cache相关服务，所以需要暴露出对应端口。\n\n已可用，无需配置\n\n## 参考\n\n* link:https://seepine.com/git/gitea/starter/[Gitea - 搭建属于自己的代码仓库]\n* link:https://seepine.com/git/gitea/actions/[Gitea Actions 搭建]\n* link:https://blog.7wate.com/archives/qian-chang-gitea-de-actions[浅尝 Gitea 的 Actions]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsobird%2Fgitea","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsobird%2Fgitea","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsobird%2Fgitea/lists"}