1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

gitea 1.23からforgejo 11へ移行 (Docker + MySQL版)

Last updated at Posted at 2025-12-19

はじめに

2024年以降、forgejoは独自進化を加速させています。

gitea 1.23からは直接forgejo 11系へ移行できないため、一度gitea 1.22とforgejo 10系を経由する手順が必要です。

本記事では、Docker+MySQL環境において安全に移行するための具体的なステップを解説します。

  • 必ずバックアップをとりましょう
  • 以下でrmと書いてある部分でも、本当にrmするのではなくmvでどこかに移動するようにしましょう
  • 並走させながら作業する場合、forgejoに適用するものを誤ってgiteaに適用しないように気をつけましょう

移行の全体フロー

安全を期すため新旧環境を並行して立ち上げ、リバースプロキシで切り替える方法をおすすめします。

  1. gitea 1.23を停止し、データをforgejo用の場所にコピー
  2. 以下全ての作業はコピーした先で実施
  3. DBダウングレード (1.23 → 1.22相当)
  4. gitea 1.22での動作確認
  5. forgejo 10へのアップグレード(置き換え)
  6. forgejo 11への最終アップグレード
  7. forgejo Action Runnerの再登録

forgejo本体の更新

1. データベースのダウングレード

gitea 1.23のDBをforgejo 10が認識できるバージョン(298)へ書き換えます。

こちらはPostgreSQLですので、MySQLの場合は以下を適用します。

123to122.sql
-- 311
ALTER TABLE `issue` DROP COLUMN `time_estimate`;

-- 310
ALTER TABLE `protected_branch` DROP COLUMN `priority`;

-- 309 (Table: notification)
-- MySQLではDROP INDEXを行う際に対象テーブルの指定が必要です
ALTER TABLE `notification`
  DROP INDEX `IDX_notification_commit_id`,
  DROP INDEX `IDX_notification_issue_id`,
  DROP INDEX `IDX_notification_repo_id`,
  DROP INDEX `IDX_notification_source`,
  DROP INDEX `IDX_notification_status`,
  DROP INDEX `IDX_notification_u_s_uu`,
  DROP INDEX `IDX_notification_updated_by`,
  DROP INDEX `IDX_notification_user_id`;

-- 308 (Table: action)
ALTER TABLE `action`
  DROP INDEX `IDX_action_r_u_d`,
  DROP INDEX `IDX_action_au_r_c_u_d`,
  DROP INDEX `IDX_action_c_u`,
  DROP INDEX `IDX_action_c_u_d`;

-- 307 was only a data migration fix for dates after year 9999 (No action needed)

-- 306
ALTER TABLE `protected_branch` DROP COLUMN `block_admin_merge_override`;

-- 305
DROP TABLE IF EXISTS `repo_license`;

-- 304
ALTER TABLE `release` DROP COLUMN `sha1`;

-- 303
ALTER TABLE `comment` DROP COLUMN `comment_meta_data`;

-- 302
ALTER TABLE `action_task` DROP COLUMN `stopped`, DROP COLUMN `log_expired`;

-- 301
ALTER TABLE `oauth2_application` DROP COLUMN `skip_secondary_authorization`;

-- 300
ALTER TABLE `protected_branch`
  DROP COLUMN `can_force_push`,
  DROP COLUMN `enable_force_push_allowlist`,
  DROP COLUMN `force_push_allowlist_user_i_ds`,
  DROP COLUMN `force_push_allowlist_team_i_ds`,
  DROP COLUMN `force_push_allowlist_deploy_keys`;

-- 299
ALTER TABLE `issue` DROP COLUMN `content_version`;
ALTER TABLE `comment` DROP COLUMN `content_version`;

-- Update version to 298
UPDATE `version` SET `version` = 298;

こんな感じで適用です。

cat 123to122.sql | docker exec -i forgejo-db mysql -u root -p${DBのパスワード} gitea

適用後、gitea 1.22で起動しようとするとコード検索インデックス(Bleve)のエラーが出る場合があります。

...s/graceful/server.go:50:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 on PID: 18
...exer/code/indexer.go:168:func3() [F] PID: 18 Unable to initialize the bleve Repository Indexer at path: /data/gitea/indexers/repos.bleve Error: error parsing mapping JSON: error building analyzer: no tokenizer with name or type 'letter' registered
mapping contents:
{"types":{"_all":{"enabled":false,"dynamic":false},"repoIndexerDocType"....

その際は、インデックスを一度削除(rm -rf data/gitea/indexers/repos.bleve/)して再起動すれば、自動的に再生成されます(作成完了を待つ必要はありません)。

2. gitea 1.22からforgejo 10への移行

上記gitea 1.22と同一ボリュームで、以下の変更をしたコンテナを立ち上げます。

  • イメージ名を gitea/gitea:1.22 から codeberg.org/forgejo/forgejo:10 に変更
  • 環境変数のprefixを GITEA__からFORGEJO__に変更
  • /data/gitea/conf/app.ini の中にWebやメール差出人名などとしてgiteaがある場合は変更(ディレクトリ名など内部的に使うものは変更しないことをおすすめします)

forgejo 10を起動すると、ログにmigrationしましたという内容が出てきます。

...ations/migrations.go:498:Migrate() [I] Migration[299]: Add content version to issue and comment table
...ations/migrations.go:498:Migrate() [I] Migration[300]: Add force-push branch protection support
...ations/migrations.go:498:Migrate() [I] Migration[301]: Add skip_secondary_authorization option to oauth2 application table
...ations/migrations.go:498:Migrate() [I] Migration[302]: Add index to action_task stopped log_expired
...ations/migrations.go:498:Migrate() [I] Migration[303]: Gitea last drop
...ations/migrations.go:498:Migrate() [I] Migration[304]: Migrate `secret` column to store keying material

3. forgejo 10からforgejo 11への移行

イメージ名を codeberg.org/forgejo/forgejo:10 から codeberg.org/forgejo/forgejo:11 に変更して立ち上げ直します。

forgejo action runner のセットアップ

forgejoでは、gitea時代と異なり手動登録が推奨されます。また、DinDコンテナは分離されます。

1. action runnerコンテナを「待機状態」で起動

docker-compose.ymlcommand: sleep infinityでコンテナを落ちないようにして起動します。

2. ファイルパーミッションを調整

/data/の所有者が0:0では動きませんので、docker-compose.ymlで指定したUID:GIDにchownします。

3. コンテナ内で手動登録

docker exec -it forgejo-runner bash

forgejoのWeb画面から新規にrunner登録トークンを取得し、forgejo-runner registerで登録します。

xxxxxxxxx:~$ forgejo-runner register
INFO Registering runner, arch=amd64, os=linux, version=v10.0.1.
WARN Runner in user-mode.
INFO Enter the Forgejo instance URL (for example, https://next.forgejo.org/):
https://xxxxxxxx
INFO Enter the runner token:
web画面で取得したトークンを入れる
INFO Enter the runner name (if set empty, use hostname: xxxxxxxxx):
forgejo-dind
INFO Enter the runner labels, leave blank to use the default labels (comma-separated, for example, ubuntu-20.04:docker://node:20-bookworm,ubuntu-18.04:docker://node:20-bookworm):
ラベルを適当に入れる
INFO Registering runner, name=forgejo-dind, instance=https://xxxxxx, labels=[xxxxxxxxxx].
DEBU Successfully pinged the Forgejo instance server
INFO Runner registered successfully.
xxxxxxxxx:~$

入力した値が /data/.runner にjsonで入っていることを確認します。

また、細かい設定を書き換える場合はここでyamlを生成して書き換えます。

xxxxxxxxx:~$ forgejo-runner generate-config > config.yml

4. コンテナ再起動

command: forgejo-runner -c /data/config.yml dameon にして再起動します。

teaコマンドはfjコマンドへ

teaコマンドはforgejo-cliになり、その略称はfjとなります。
昔懐かし、いにしえのnntp! (老害発言)

docker-compose.yml サンプル

移行用gitea 1.22とforgejoをまとめた構成例です。

docker-compose.yml
networks:
  forgejo:
  
services:
  db:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: gitea
    volumes:
      - ./db:/var/lib/mysql
    networks:
      - forgejo

  # ステップ2: 動作確認用のgitea 1.22
  gitea-122:
    image: gitea/gitea:1.22
    depends_on: [db]
    volumes:
      - ./data:/data
    networks:
      - forgejo
    environment:
      GITEA__server__ROOT_URL: https://xxxxxxxxxx
      GITEA__server__SSH_PORT: 9922
      ...

  # ステップ2,3: forgejo本体 (v10移行後に11へ変更)
  forgejo:
    #image: codeberg.org/forgejo/forgejo:10
    #image: codeberg.org/forgejo/forgejo:11
    depends_on: [db]
    volumes:
      - ./data:/data
    networks:
      - forgejo
    environment:
      FORGEJO__server__ROOT_URL: https://xxxxxxxxxx
      FORGEJO__server__SSH_PORT: 9922
      ...

  # Runner一式
  dind:
    image: docker:dind
    privileged: true
    networks:
      - forgejo
    command: ["dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false"]

  forgejo-runner:
    image: data.forgejo.org/forgejo/runner:11
    depends_on: [forgejo, dind]
    # 最初は以下のsleepで起動し、execで中に入ってregisterを行う
    #command: sleep infinity
    #command: forgejo-runner -c /data/config.yml daemon
    environment:
      DOCKER_HOST: tcp://dind:2375
    user: 1001:1001
    volumes:
      - ./runner-data:/data

おわりに

以上、移行作業のメモとログを利用し、ほとんど生成AIに書かせたまとめでした。
皆様の移行が成功することを、この生成AIが願っているそうです😆

Bonan forĝejon!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?