從Gogs遷移到Gitea

Gogs 其實一個升級版本引起奇怪事情,於是順便遷移到 Gitea 上,在 Gitea 官方上建意由 0.9.X 或以前升級會比較方便。

但我升級到 0.11.X 以上出現問題,所在這記錄一下解決過程。

起因

事源於新版 Gogs 加了/修改了 git hook 的處理方法,兼容上出現一些問題。 在推送時出現 hook declined 並被 reject.


! [remote rejected] master -> master (pre-receive hook declined)

可能的成因是這個hook不再生效或不再兼容了





#在 /var/gogs/git/gogs-repositories/<user>/<repo>.git/hooks/pre-receiv
#找到以下內容
#!/usr/bin/env bash
"/app/gogs/gogs" hook --config='/data/gogs/conf/app.ini' pre-receive

遷移

Gitea 是 Gogs 在 0.9.X 上分支,並後續開發的版本。

使用Docker 作為啟動



docker run -d --name=gitea -p 10022:22 -p 10080:3000 -v /var/lib/gitea:/data gitea/gitea:latest
docker stop gitea

遷移 git 倉庫和數據庫

複制倉庫到 Gitea






cp -r /var/gogs/git/gogs-repositories/* /var/lib/gitea/git/repositories/
cd /var/lib/gitea/gitea/conf
mv app.ini app.ini.bak
cp /var/gogs/gogs/conf/app.ini .
vim app.ini

複制數據庫


CREATE DATABASE gitea WITH TEMPLATE gogs OWNER <username>;

修改 Gitea 參數














[repository]
ROOT = /data/git/repositories
[server]
APP_DATA_PATH = /data/gitea
ROOT_URL = https://domain
DOMAIN = domain
[database]
DB_TYPE = postgres
HOST = 172.17.0.1:5432 #docker 到外部 postgres SQL
NAME = gitea
USER = USER
PASSWD = PASSWD
SSL_MODE = disable

啟動並排錯

啟動 Docker


docker start gitea

查看 log 是否順利(通常都不順利


less /var/lib/gitea/gitea/log/gitea.log

如果看到收Migration出現問題(如下

























2018/08/03 10:58:17 [I] Migration: empty step
2018/08/03 10:58:17 [I] Migration: empty step
2018/08/03 10:58:17 [I] Migration: empty step
2018/08/03 10:58:17 [I] Migration: remove index column from repo_unit table
2018/08/03 10:58:17 [I] Migration: remove organization watch repositories
2018/08/03 10:58:17 [I] Migration: add deleted branches
2018/08/03 10:58:18 [I] Migration: add repo indexer status
2018/08/03 10:58:18 [I] Migration: adds time tracking and stopwatches
2018/08/03 10:58:19 [I] Migration: migrate protected branch struct
2018/08/03 10:58:19 [I] Migration: add default value to user prohibit_login
2018/08/03 10:58:19 [I] Migration: add lfs lock table
2018/08/03 10:58:20 [I] Migration: add reactions
2018/08/03 10:58:20 [I] Migration: add pull request options
2018/08/03 10:58:20 [I] Migration: add writable deploy keys
2018/08/03 10:58:21 [I] Migration: remove is_owner, num_teams columns from org_user
2018/08/03 10:58:21 [I] Migration: add closed_unix column for issues
2018/08/03 10:58:22 [I] Migration: add label descriptions
2018/08/03 10:58:22 [I] Migration: add merge whitelist for protected branches
2018/08/03 10:58:23 [I] Migration: add is_fsck_enabled column for repos
2018/08/03 10:58:23 [I] Migration: add size column for attachments
2018/08/03 10:58:24 [I] Migration: add last used passcode column for TOTP
2018/08/03 10:58:24 [I] Migration: add language column for user setting
2018/08/03 10:58:25 [I] Migration: add multiple assignees
2018/08/03 10:58:26 [...itea/routers/init.go:60 GlobalInit()] [E] Failed to initialize ORM engine: migrate: do migrate: pq: column "ref" does not exist

出現欄位失蹤 do migrate: pq: column "ref" does not exist




# 查看 Migration 的版本
SELECT version FROM public.version t
# 顯示的是 64,

到 Github 上查看源碼 https://github.com/go-gitea/gitea/tree/master/models/migrations

找出 v64.go 並在 type Issue 或到要需要的 Ref


ALTER TABLE public.issue ADD ref text NULL

再重啟 Docker 並繼續排查問題。

清理錯誤的 Hook

再次推送時,會出現新的錯誤

remote: ./hooks/post-receive.d/post-receive: line 2: /app/gogs/gogs: No such file or directory

使用以下指令清理不需要的 Gogs Hook



cd /var/lib/gitea/git/repositories
grep -rHn gogs *|cut -d : -f1 | xargs rm

到這步為止,之前推送失敗的倉庫都能推送上服務器