在 fly.io 上运行 Gitea
Gitea 被设计为能在众多不同平台上运行,对资源的要求极低。这意味着无论你手头是什么电脑,Gitea 基本上都能跑起来。
虽然你可能希望自托管一个实例,但有时未必想亲自打理服务器的方方面面,比如防火墙、Web 服务器、TLS 证书等等。这时 fly.io 就派上了用场。fly.io 是一个提供慷慨免费额度的平台,你只需告诉它你想运行的 Docker 镜像,它就会帮你处理所有费时费力的运维琐事。
开始前,你需要先注册一个 fly.io 账号。好在他们有一份不错的入门指南,可以带你一步步完成操作。
有了账号之后,就可以着手在 fly.io 上运行 Gitea 了。
# create a directory to store fly.io application config
mkdir gitea-on-fly
# enter into the newly created directory
cd gitea-on-fly
# tell fly.io you wish to create a new application in the amsterdam region (there are many other regions you could pick too)
# pick any name for the app that you'd like, in the example we are using `gitea-on-fly`
flyctl launch --name gitea-on-fly --no-deploy --region ams
# give the newely create application persistant storage, so your data persists between app updates
flyctl volumes create gitea_data --size 1 --region ams --app gitea-on-fly
你会注意到,创建应用后,在你刚建立的目录中会生成一个名为 fly.toml 的新文件。其中包含大量占位信息,你需要将其替换为以下内容。请使用创建应用时所选的名称,替换下面配置中所有出现 gitea-on-fly 的地方。
app = "gitea-on-fly"
kill_timeout = 5
[build]
image = "gitea/gitea:latest" # latest is the most recent stable release
[env]
GITEA__database__DB_TYPE="sqlite3"
GITEA__database__PATH="/data/gitea/gitea.db"
GITEA__server__DOMAIN="gitea-on-fly.fly.dev"
GITEA__server__SSH_DOMAIN="gitea-on-fly.fly.dev"
GITEA__server__ROOT_URL="https://gitea-on-fly.fly.dev"
GITEA__security__INSTALL_LOCK="true" # Don't show installer
# GITEA__service__DISABLE_REGISTRATION="true" # TODO: uncomment once you have created your first user
# persist data
[[mounts]]
destination = "/data"
source = "gitea_data"
# ssh traffic
[[services]]
internal_port = 22
protocol = "tcp"
[[services.ports]]
port = 22
# https traffic
[[services]]
internal_port = 3000
protocol = "tcp"
[[services.ports]]
handlers = ["http"]
force_https = true
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
将配置示例中的名称替换为你选择的应用名称后,运行 flyctl deploy,它就会把所有内容推送到 fly.io 并部署你的 Gitea 实例。
现在你可以访问 https://gitea-on-fly.fly.dev(或者你选的其他名称),创建账户并使用你的 Gitea 实例。
如果你希望自己是实例上唯一能注册账户的人,在注册完自己的账户后,可以取消环境变量 GITEA__service__DISABLE_REGISTRATION 的注释,然后再次运行 flyctl deploy,即可关闭注册。
现在你已经成功在 fly.io 上运行 Gitea 实例了,接下来可以进一步考虑备份、使用自己的域名、通过 fly.io CLI 扩容内存/CPU,甚至用 fly.io 托管的 Postgres 替代 SQLite 作为数据库。
