使用Gitea搭建git服务

文档地址:https://gitea.io/zh-cn/

安装

docker方式:

docker pull gitea/gitea:latest  # 拉取 Gitea 镜像
sudo mkdir -p /var/lib/gitea  # 创建一个目录作为数据存储
docker run -d --name=gitea -p 10022:22 -p 10080:3000 -v /var/lib/gitea:/data gitea/gitea:latest
# 10022 为容器内部ssh端口绑定到主机端口10022
# 10080 为容器内部的服务端口绑定到主机端口10080

浏览器访问 http://hostname:10080/ 可看到git页面。

配置说明

配置说明文档地址:https://docs.gitea.io/zh-cn/config-cheat-sheet/

/var/lib/gitea 目录结构:

/var/lib/gitea
- git
- gitea
	- conf
		-app.ini  # 可直接修改该配置文件
-ssh

由于是docker方式启动,该配置文件在容器内生效,所以需要更改 server 配置中 HTTP_ADDR、HTTP_PORT、SSH_PORT 为本地默认配置:HTTP_ADDR=127.0.0.1、HTTP_PORT=3000、SSH_PORT=22,以供容器使用。

API访问

API访问文档地址:

api访问默认开启,可在配置文件中调整 ENABLE_SWAGGER 关闭api访问。

使用api时,需要认证通过才能正常访问,有以下两种认证方式:

  1. url查询参数方式

  2. http header 方式

    • 指定 Authorization: token ...

    • 示例

      curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" 
          -H "accept: application/json" 
          -H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" 
          -H "Content-Type: application/json" -d "{ "body": "testing", "title": "test 20"}" -i
      

以上两种方式中的 token、access_token、Authorization:token 均是一样的,可在 Gitea web 界面中得到:Settings | Applications | Generate New Token

原文地址:https://www.cnblogs.com/KbMan/p/12095849.html