安装

使用docker安装,参考官网教程:使用 Docker 安装 - Docs (gitea.io)

新建下面的docker-compose.yml:

version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.17.3
    container_name: gitea
    environment:
      - USER_UID=6001
      - USER_GID=6001
    restart: always
    networks:
      - gitea
    volumes:
      - /home/git/gitea-data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "13000:3000"
      - "22006:22"

注意最后指定的端口映射用来提供ssh和https访问暴露。中间的volumn第一行指定了挂载数据卷的位置。

需要注意,gitea官方规定不能使用root用户运行,要提前创建一个用户,并且将数据卷放在该用户可读的位置上。

配置

在gitea第一次启动时,就可以依照向导完成配置。

第一次配置完成后,如果后面想修改一些基本配置,发现在管理页面不能修改只能查看,这时要进入到挂载的数据目录下,找到gitea/conf/app.ini文件完成修改。我的配置如下:

APP_NAME = Claws个人仓库 | Claws Gitea
RUN_MODE = prod
RUN_USER = git

[repository]
ROOT = /data/git/repositories

[repository.local]
LOCAL_COPY_PATH = /data/gitea/tmp/local-repo

[repository.upload]
TEMP_PATH = /data/gitea/uploads

[server]
APP_DATA_PATH    = /data/gitea
DOMAIN           = gitea.claws.top
SSH_DOMAIN       = gitea.claws.top
HTTP_PORT        = 3000
ROOT_URL         = https://gitea.claws.top/
DISABLE_SSH      = false
SSH_PORT         = 22006
SSH_LISTEN_PORT  = 22
LFS_START_SERVER = true
LFS_JWT_SECRET   = 95qxhC_cu-PL_3HYRUbR33RCC_LlM78vFv1_vwZIDi0
OFFLINE_MODE     = false

[database]
PATH     = /data/gitea/gitea.db
DB_TYPE  = sqlite3
HOST     = localhost:3306
NAME     = gitea
USER     = root
PASSWD   = 
LOG_SQL  = false
SCHEMA   = 
SSL_MODE = disable
CHARSET  = utf8

[indexer]
ISSUE_INDEXER_PATH = /data/gitea/indexers/issues.bleve

[session]
PROVIDER_CONFIG = /data/gitea/sessions
PROVIDER        = file

[picture]
AVATAR_UPLOAD_PATH            = /data/gitea/avatars
REPOSITORY_AVATAR_UPLOAD_PATH = /data/gitea/repo-avatars
DISABLE_GRAVATAR              = false
ENABLE_FEDERATED_AVATAR       = true

[attachment]
PATH = /data/gitea/attachments

[log]
MODE      = console
LEVEL     = info
ROUTER    = console
ROOT_PATH = /data/gitea/log

[security]
INSTALL_LOCK                  = true
SECRET_KEY                    = 
REVERSE_PROXY_LIMIT           = 1
REVERSE_PROXY_TRUSTED_PROXIES = *
INTERNAL_TOKEN                = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2NjY0MTI3NjN9.pj-hn4Mi5tE5K1crC6M7CLsp_cN5WoLUASY3Ba32bk0
PASSWORD_HASH_ALGO            = pbkdf2

[service]
DISABLE_REGISTRATION              = true
REQUIRE_SIGNIN_VIEW               = false
REGISTER_EMAIL_CONFIRM            = true
ENABLE_NOTIFY_MAIL                = true
ALLOW_ONLY_EXTERNAL_REGISTRATION  = false
ENABLE_CAPTCHA                    = false
DEFAULT_KEEP_EMAIL_PRIVATE        = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING       = true
NO_REPLY_ADDRESS                  = noreply.localhost

[lfs]
PATH = /data/git/lfs

[mailer]
ENABLED = true
HOST    = smtp.qq.com:465
FROM    = 2821624044@qq.com
USER    = 2821624044
PASSWD  = wfwapyrbmrpidcga

[openid]
ENABLE_OPENID_SIGNIN = true
ENABLE_OPENID_SIGNUP = false

[repository.pull-request]
DEFAULT_MERGE_STYLE = merge

[repository.signing]
DEFAULT_TRUST_MODEL = committer

在server的ssh相关配置中,SSH_PORT 指定的是显示给用户访问的ssh端口,而SSH_LISTEN_PORT 则是容器监听的端口,二者有所差别。可能还需要配置一下端口转发。