セクション A: モジュラーモノリスのリポジトリ骨組みを追加#1
Merged
Merged
Conversation
`github.com/fun-dotto/server` を Go 1.25.7 でモジュール化し、 モジュラーモノリスの土台となる go.mod / go.sum を追加した。 直接依存は cmd/migrate-job 用の ariga.io/atlas と cloud.google.com/go/cloudsqlconn のみで、後続コミットで導入する 他のサブシステムが必要な依存はそれぞれの取り込み時に追加する。
開発者ローカル / CI / Cloud Run Job ビルドのいずれも `mise install` 一発でセットアップできるよう、依存ツールを mise.toml に集約した。Go・Terraform・Atlas・Task・oapi-codegen に加え、§B〜§D の履歴移植で使う git-filter-repo も同梱する。 Taskfile.yml には setup / install / build / test に加え、 Atlas の差分生成 (migrate:diff) ・lint・ローカル apply、 academic API のコード生成タスクも併せて定義する。 .gitignore には bin/、ローカル env、Atlas/Terraform/mise の ローカル成果物を追加してコミット汚染を防ぐ。
cmd/ 配下の全 Go バイナリを 1 つの Docker イメージに同梱して Cloud Run Service / Job からは command で /bin/<name> を切り替える 方針 (Notion 計画 §2 の単一イメージ・マルチバイナリ方針) を実現する。 batch-jobs/Dockerfile を雛形に、ビルダは golang:1.25.7-bookworm、 ランタイムは distroless/static-debian12:nonroot を採用し、 -tags timetzdata / CGO_ENABLED=0 / -trimpath -ldflags="-s -w" を統一する。 academic-api / build-class-change-notifications-job / dispatch-notifications-job / migrate-job の 4 バイナリを最初から同梱対象とし、 ファイルアクセス禁止を徹底するため後段で go:embed 対応する前提で組む。 .dockerignore にはビルド不要なディレクトリ (docs / infra / migrations / way 等) と bin/ などを列挙して context サイズと層キャッシュ効率を改善する。
GORM AutoMigrate を廃止して Atlas + versioned SQL に統一する方針 (Notion 計画 §3) の入口として、atlas.hcl と cmd/migrate-job を追加する。 - atlas.hcl: internal/shared/model/ の GORM モデルを desired state とする external_schema を宣言。env "local" は使い捨て docker dev DB、 env "prod" は Cloud Run Job の `var.url` を受け取って migrations/ を適用する。 - cmd/migrate-job/main.go: cloudsqlconn 経由で Cloud SQL に IAM 認証付きで 繋いだ *sql.DB を ariga.io/atlas/sql/migrate.Executor に渡し、 Cloud SQL Auth Proxy のサイドカーや atlas CLI バイナリ同梱を回避する。 context.WithTimeout(10 分) を必ず外側で掛け、エラーは log.Fatal で non-zero exit する。Atlas のリビジョン管理テーブル選定は §E で仕上げる ため、Phase 1 のスキャフォールドとして TODO コメントで明示している。
§B〜§G で各サービス・基盤を流し込む受け皿として、目標アーキテクチャ
(Notion 計画 §2) で定めたディレクトリを .gitkeep だけで先に切る。
internal/{shared,modules}, api/openapi, gen, assets, migrations,
infra, .github/workflows をブランチ単位の取り込み待ち状態にする。
AGENTS.md / CLAUDE.md は way submodule の instructing/backend 配下を参照する 1 行リダイレクトのみとし、リポジトリ固有のルールは 持たせない (Notion 計画 §7-A の方針)。 .env.example には migrate-job が要求する Cloud SQL IAM 認証用の 環境変数 (INSTANCE_CONNECTION_NAME / DB_NAME / DB_IAM_USER) と、 ローカル開発で task migrate:apply:local を回す際の DEV_DATABASE_URL を雛形として記録する。
Contributor
There was a problem hiding this comment.
Pull request overview
モジュラーモノリス移行に向けて、後続の各サブシステムを載せるためのリポジトリ骨組み(Go モジュール、ツールチェーン、Docker ビルド、Atlas マイグレーション、ディレクトリ構成)を追加するPRです。
Changes:
- mise / Taskfile によるツールチェーンと開発タスクの導入
- マルチバイナリ単一イメージの Dockerfile と、Cloud Run Job 用 migrate-job のスキャフォールド実装
- Atlas 設定・.env.example・.gitignore/.dockerignore・空ディレクトリ確保(.gitkeep)の追加
Reviewed changes
Copilot reviewed 10 out of 21 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Taskfile.yml | 開発タスク(setup/build/test/migrate 等)を追加 |
| mise.toml | mise で利用するツール定義を追加 |
| go.mod | Go モジュール初期化と依存関係追加 |
| go.sum | 依存関係のチェックサム追加 |
| Dockerfile | マルチバイナリ単一イメージ構成の追加 |
| cmd/migrate-job/main.go | Cloud SQL IAM 認証+Atlas Executor によるマイグレーション適用ジョブ追加 |
| atlas.hcl | GORM provider を前提にした Atlas プロジェクト設定追加 |
| .gitignore | ビルド成果物・ローカル状態ファイル等の除外追加 |
| .dockerignore | Docker ビルドコンテキストの除外ルール追加 |
| .env.example | migrate-job 用の環境変数雛形追加 |
| AGENTS.md | エージェント向けガイドの参照(リダイレクト)追加 |
| CLAUDE.md | エージェント向けガイドの参照(リダイレクト)追加 |
| migrations/.gitkeep | 空ディレクトリ確保 |
| internal/shared/.gitkeep | 空ディレクトリ確保 |
| internal/modules/.gitkeep | 空ディレクトリ確保 |
| infra/.gitkeep | 空ディレクトリ確保 |
| gen/.gitkeep | 空ディレクトリ確保 |
| cmd/.gitkeep | 空ディレクトリ確保 |
| assets/.gitkeep | 空ディレクトリ確保 |
| api/openapi/.gitkeep | 空ディレクトリ確保 |
| .github/workflows/.gitkeep | 空ディレクトリ確保 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+37
| desc: Build all binaries under cmd/ | ||
| cmds: | ||
| - rm -rf ./bin | ||
| - mkdir -p ./bin | ||
| - "{{.GO}} build -tags timetzdata -trimpath -ldflags='-s -w' -o ./bin/academic-api ./cmd/academic-api" | ||
| - "{{.GO}} build -tags timetzdata -trimpath -ldflags='-s -w' -o ./bin/build-class-change-notifications-job ./cmd/build-class-change-notifications-job" | ||
| - "{{.GO}} build -tags timetzdata -trimpath -ldflags='-s -w' -o ./bin/dispatch-notifications-job ./cmd/dispatch-notifications-job" |
Comment on lines
+26
to
+28
| - rm -rf ./gen/academic | ||
| - mkdir -p ./gen/academic | ||
| - oapi-codegen -config ./api/openapi/academic/config.yaml ./api/openapi/academic/openapi.yaml |
Comment on lines
+19
to
+23
| for cmd in academic-api build-class-change-notifications-job dispatch-notifications-job migrate-job; do \ | ||
| CGO_ENABLED=0 GOOS=linux \ | ||
| go build -tags timetzdata -trimpath -ldflags='-s -w' \ | ||
| -o /out/bin/${cmd} ./cmd/${cmd}; \ | ||
| done |
Comment on lines
+25
to
+33
| # ---- Runtime stage ---- | ||
| FROM gcr.io/distroless/static-debian12:nonroot | ||
|
|
||
| COPY --from=builder /out/bin/ /bin/ | ||
|
|
||
| USER nonroot:nonroot | ||
|
|
||
| # 各 Cloud Run Service / Job は command で /bin/<name> を指定して起動する。 | ||
| ENTRYPOINT [] |
| **/*.out | ||
| docs/ | ||
| infra/ | ||
| migrations/ |
Comment on lines
+12
to
+47
| data "external_schema" "gorm" { | ||
| program = [ | ||
| "go", | ||
| "run", | ||
| "-mod=mod", | ||
| "ariga.io/atlas-provider-gorm", | ||
| "load", | ||
| "--path", "./internal/shared/model", | ||
| "--dialect", "postgres", | ||
| ] | ||
| } | ||
|
|
||
| env "local" { | ||
| src = data.external_schema.gorm.url | ||
| dev = "docker://postgres/16/dev?search_path=public" | ||
|
|
||
| migration { | ||
| dir = "file://migrations" | ||
| } | ||
|
|
||
| format { | ||
| migrate { | ||
| diff = "{{ sql . \" \" }}" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| env "prod" { | ||
| src = data.external_schema.gorm.url | ||
| url = var.url | ||
| dev = "docker://postgres/16/dev?search_path=public" | ||
|
|
||
| migration { | ||
| dir = "file://migrations" | ||
| } | ||
| } |
| // - 望ましいスキーマ (desired state) は internal/shared/model/ の GORM モデルを正とする。 | ||
| // - migrations/ 配下に versioned SQL を保存し、サム (atlas.sum) で改ざん検知。 | ||
| // - dev DB は使い捨ての Docker コンテナ (Postgres 16) を利用する。 | ||
| // - cmd/migrate-job が ariga.io/atlas-go-sdk (atlasexec) 経由で migrations/ を適用する。 |
Comment on lines
+1
to
+7
| [tools] | ||
| go = "1.25.7" | ||
| terraform = "1.9.8" | ||
| "aqua:ariga/atlas" = "latest" | ||
| "aqua:go-task/task" = "latest" | ||
| "go:github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen" = "latest" | ||
| "ubi:newren/git-filter-repo" = { version = "latest", exe = "git-filter-repo" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
やったこと
Notion 計画 §7-A のリポジトリ骨組みを構築する。後続の §B〜§G で各サブシステムを流し込む受け皿を一式用意する。
go.mod(Go 1.25.7、github.com/fun-dotto/server) とgo.sumを生成。直接依存は cmd/migrate-job 用のariga.io/atlas/cloud.google.com/go/cloudsqlconnのみmise.tomlに Go・Terraform・Atlas・Task・oapi-codegen・git-filter-repo を集約Taskfile.ymlに setup / install / build / test / generate:academic / migrate:diff・lint・apply:local を整備.gitignoreに bin/、ローカル env、Atlas/Terraform/mise 中間物を追加Dockerfileをgolang:1.25.7-bookwormビルダ +distroless/static-debian12:nonrootランタイムで構築。academic-api / build-class-change-notifications-job / dispatch-notifications-job / migrate-job の 4 バイナリを/bin/<name>に同梱.dockerignoreでビルド context を絞るatlas.hclに GORM provider + 使い捨て docker dev DB +env "local"/env "prod"を定義cmd/migrate-job/main.goでcloudsqlconnIAM 認証付き*sql.DBを構築し、ariga.io/atlas/sql/migrate.Executorでmigrations/を適用するスキャフォールドを実装。context.WithTimeout(10m)で確実に non-zero exitinternal/{shared,modules},api/openapi,gen,assets,migrations,infra,.github/workflowsを.gitkeepで確保AGENTS.md/CLAUDE.mdは way のinstructing/backend/を参照する 1 行リダイレクト.env.exampleに migrate-job が要求する環境変数を雛形化確認したこと
mise installで Go・Terraform・Atlas・Task・oapi-codegen・git-filter-repo が揃うことを確認mise exec -- go build ./cmd/migrate-jobがローカルでビルド成功することを確認 (約 35 MB の static binary が生成)go mod tidyの差分をgo.mod/go.sumにコミット済みであることを確認メモ
cmd/migrate-jobのリビジョン管理テーブル選定 (atlas_schema_revisions) と本番 DB へ向けた疎通検証は §E で仕上げる。Phase 1 のスキャフォールド段階のためmigrate.NopRevisionReadWriterを使っており、TODO コメントで明示している