feat: config を薄くして外部から差し込みやすくする#5005
Conversation
|
Preview (prod) → https://5005-prod.traq-preview.trapti.tech/ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5005 +/- ##
=======================================
Coverage 62.60% 62.60%
=======================================
Files 108 108
Lines 3097 3097
Branches 630 630
=======================================
Hits 1939 1939
Misses 1048 1048
Partials 110 110 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
0b1fa61 to
2ff19c4
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes config.js from the build process, requiring it to be mounted externally when deploying with Docker. The change introduces TypeScript type definitions and JSON schema for configuration validation, and adds automated schema generation via GitHub Actions.
- Removed
public/config.jsfrom the repository and excluded it from build artifacts via a custom Vite plugin - Added
config.d.tsTypeScript definitions andconfig.schema.jsonfor configuration validation - Updated Docker deployment to require external mounting of
config.jswith validation in the startup script
Reviewed changes
Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vite.config.ts | Added Rollup plugin to exclude config.js from build output |
| tsconfig.json | Included config.d.ts in TypeScript compilation |
| tests/unit/tsconfig.json | Included config.d.ts for unit tests |
| public/config.js | Removed configuration file from repository (143 lines deleted) |
| package.json | Added ts-json-schema-generator dependency for schema generation |
| package-lock.json | Updated lock file with new dependency and transitive dependencies |
| config.schema.json | Added JSON schema for configuration validation (134 lines) |
| config.d.ts | Added TypeScript type definitions for Config interface (118 lines) |
| build/docker/startup.sh | Added validation check to ensure config.js is mounted at startup |
| Dockerfile | Removed config.js from default files as it's now externally injected |
| README.md | Added Docker deployment documentation requiring config.js mounting |
| .github/workflows/generate-schema.yml | Added automated workflow to regenerate schema from TypeScript definitions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
768d51d to
c5a9e4c
Compare
| ENV THEME_COLOR=#0D67EA | ||
|
|
||
| # 設定上書き処理用に、.brを消して、元の設定を別のディレクトリに保存しておく | ||
| # config.js は外部から注入されるため除外 |
There was a problem hiding this comment.
[q] これって breaking change はあります?(このままアップデートかけても壊れない?)
というか config.js は消すと fork 先がまずかったりする?もしかして(ちゃんと想像がついてないけど) 特に ex とかで困る可能性があるから、どういう対応が必要になるかが分かるような資料は必要になるかも (理想はそのままアップデートかけてもなにも問題がない状態)
There was a problem hiding this comment.
manifest 側の対応が済んでいれば壊れることはないはずですが、fork は何もしないと確実に動かなくなると思います。
ちょっと考えてみます
|
|
||
| if [ ! -f /app/override/config.js ]; then | ||
| echo "ERROR: config.js is not mounted at /app/override/config.js" | ||
| echo "Please mount config.js when starting the container:" |
There was a problem hiding this comment.
[imo] README.md に誘導する文言入れてあげてほしいかも
| CACHE_KEY=$(md5sum /usr/share/caddy/new-relic.js | cut -d ' ' -f 1) | ||
| mv /usr/share/caddy/new-relic.js /usr/share/caddy/new-relic-$CACHE_KEY.js | ||
| sed -i -e "s/<!-- <script src=\"\/new-relic-{hash}.js\"><\/script> -->/<script src=\"\/new-relic-$CACHE_KEY.js\"><\/script>/" /usr/share/caddy/index.html | ||
| echo "Startup: set up New Relic" |
There was a problem hiding this comment.
なんか format がかかっちゃってる?理由がなければ戻してほしいかも
| on: | ||
| push: | ||
| branches: | ||
| - master |
There was a problem hiding this comment.
[imo] できれば master で push する前に PR のタイミングで生成してもらう(自動テストで diff ないかチェックしてあったら落とす) の方が、 master で変なデータが挟まる可能性がなくて良い気がする
|
|
||
| cp "${CONFIG_SOURCE_PATH}" "${CONFIG_DIST_PATH}" | ||
| else | ||
| echo "config.js not found, downloading from manifest repository..." |
There was a problem hiding this comment.
[q] これ echo で出力する理由ってある? なんか 気持ち的には debug レベルの出力( = 普通はなくていい)な気がしちゃう
There was a problem hiding this comment.
手癖で書いてしまいました
私もいらないと思います
| @@ -0,0 +1,13 @@ | |||
| { | |||
There was a problem hiding this comment.
fallback よりなんか default config として使えるといいかも
There was a problem hiding this comment.
たしかにです
薄いほうがいいとは思うのですが、どうしましょう……?
There was a problem hiding this comment.
今の内容で default config を作ってしまえば良いと思います!元々のゴールは conflict 防止なので、別に最悪そこまで薄くなくても良い
ras0q
left a comment
There was a problem hiding this comment.
issue立てて全然動向を終えてなくてすみません。
問題が複雑になっていそうな気がします。
現状の public/config.js ($schema付きJSONでいいのは間違いないが時すでに遅し) をどこでも動くようにfallbackのものにして、各環境でDockerでマウント or フォークで直接書き換えだけだと足りないですかね?
改めて考えるとたしかにそうですね、なんか勘違いしていた気がします |
c5a9e4c to
fdac172
Compare
📝 WalkthroughWalkthroughTypeScript型からJSON Schemaを自動生成し、生成物の差分をPull Requestでチェックするワークフローを追加。Docker起動時に外部の Changes
Sequence Diagram(s)sequenceDiagram
participant GH as GitHub Actions
participant Repo as Repository
participant Node as Node.js
participant FS as Filesystem/Git
GH->>Repo: checkout
GH->>Node: setup Node 20
GH->>Node: npm ci
GH->>Node: npm run generate-schema
Node->>FS: read `config.d.ts` & tsconfig
Node->>FS: write `config.schema.json`
GH->>FS: git diff --exit-code config.schema.json
alt diff found
FS->>GH: non-zero exit -> job fails
else no diff
FS->>GH: zero exit -> job passes
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
scripts/generate-schema.js (1)
21-23: エラー発生時にエラー内容をログ出力することを推奨します。現在の実装ではエラーが発生しても内容が出力されないため、デバッグが困難になります。
🐛 提案する修正
} catch (e) { + console.error('Failed to generate schema:', e) process.exit(1) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/generate-schema.js` around lines 21 - 23, The catch block in scripts/generate-schema.js currently swallows errors (catch (e) { process.exit(1) }); update it to log the caught error before exiting: inside the catch (e) handler, call console.error(...) (or a logger if available) with the error message/stack (e or e.stack) so the error details are output, then call process.exit(1); keep the existing behavior but ensure the error is logged for debugging.README.md (1)
22-31: ドキュメントにconfig.jsonのサポートも記載することを検討してください。
startup.shではconfig.jsonからconfig.jsへの変換機能が追加されていますが、ドキュメントではconfig.jsのマウントのみが説明されています。config.jsonをマウントするオプションも記載すると、ユーザーにとってより分かりやすくなります。📝 提案する追記例
When deploying using Docker, you can mount `config.js` externally: ```bash docker run -d \ -p 80:80 \ -v /path/to/your/config.js:/app/override/config.js \ traq-ui:latest+Alternatively, you can mount
config.jsonwhich will be automatically converted toconfig.js:
+
+```bash
+docker run -d \
- -p 80:80 \
- -v /path/to/your/config.json:/app/override/config.json \
- traq-ui:latest
+```See
config.jsonin our manifest repository for an example. Refer toconfig.d.tsfor the TypeScript type definition andconfig.schema.jsonfor the JSON Schema.</details> <details> <summary>🤖 Prompt for AI Agents</summary>Verify each finding against the current code and only fix it if needed.
In
@README.mdaround lines 22 - 31, The README currently only documents mounting
config.js via Docker but startup.sh also supports mounting config.json which it
converts to config.js; update the README example text to mention and show the
alternative Docker run that mounts config.json (referencing config.json and
config.js and the startup.sh conversion behavior) and include the same links to
the manifest example and config.d.ts/config.schema.json so users know they can
supply either file and that startup.sh will perform the conversion.</details> </blockquote></details> <details> <summary>.github/workflows/check-schema.yml (1)</summary><blockquote> `25-27`: **スキーマ変更時のエラーメッセージを改善することを検討してください。** `git diff --exit-code` が失敗した場合、ユーザーにとって何をすべきか分かりにくい可能性があります。 <details> <summary>📝 提案する改善</summary> ```diff - name: Check for changes run: | git diff --exit-code config.schema.json + continue-on-error: false + + - name: Fail with helpful message + if: failure() + run: | + echo "::error::config.schema.json is out of sync with config.d.ts. Please run 'npm run generate-schema' and commit the changes." + exit 1🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/check-schema.yml around lines 25 - 27, The "Check for changes" workflow step currently runs "git diff --exit-code config.schema.json" which fails without guidance; update that step to catch failure and print a clear, actionable message telling the user what to do (e.g., that the schema changed and they should run the schema generation/formatter command and commit the updated config.schema.json), include a brief git diff output for context, and then exit non-zero; locate the step named "Check for changes" and replace the direct git diff invocation with a command sequence that echoes the user-facing instructions on failure, shows the diff for debugging, and returns the failing exit code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.github/workflows/check-schema.yml:
- Around line 25-27: The "Check for changes" workflow step currently runs "git
diff --exit-code config.schema.json" which fails without guidance; update that
step to catch failure and print a clear, actionable message telling the user
what to do (e.g., that the schema changed and they should run the schema
generation/formatter command and commit the updated config.schema.json), include
a brief git diff output for context, and then exit non-zero; locate the step
named "Check for changes" and replace the direct git diff invocation with a
command sequence that echoes the user-facing instructions on failure, shows the
diff for debugging, and returns the failing exit code.
In `@README.md`:
- Around line 22-31: The README currently only documents mounting config.js via
Docker but startup.sh also supports mounting config.json which it converts to
config.js; update the README example text to mention and show the alternative
Docker run that mounts config.json (referencing config.json and config.js and
the startup.sh conversion behavior) and include the same links to the manifest
example and config.d.ts/config.schema.json so users know they can supply either
file and that startup.sh will perform the conversion.
In `@scripts/generate-schema.js`:
- Around line 21-23: The catch block in scripts/generate-schema.js currently
swallows errors (catch (e) { process.exit(1) }); update it to log the caught
error before exiting: inside the catch (e) handler, call console.error(...) (or
a logger if available) with the error message/stack (e or e.stack) so the error
details are output, then call process.exit(1); keep the existing behavior but
ensure the error is logged for debugging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ceeb2c41-73ab-484b-9d5f-8f7776ab387f
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (10)
.github/workflows/check-schema.yml.prettierignoreREADME.mdbuild/docker/startup.shconfig.d.tsconfig.schema.jsonpackage.jsonscripts/generate-schema.jstests/unit/tsconfig.jsontsconfig.json
08b8ecd to
91fbd9f
Compare
config.js をビルドから除外する91fbd9f to
6f0e0cf
Compare
6f0e0cf to
04b1f1a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
build/docker/startup.sh (1)
30-34: (オプション)JSON の基本的なバリデーションを追加することを検討してください。不正な JSON がマウントされた場合、生成される
config.jsは無効な JavaScript となり、アプリケーションが起動時にエラーを出す可能性があります。jqを使用したシンプルなバリデーションで、起動前にわかりやすいエラーメッセージを表示できます。💡 バリデーション追加の提案
if [ -f /app/override/config.json ]; then if [ -f /app/override/config.js ]; then echo "WARNING: Both config.json and config.js are mounted at /app/override/" echo "WARNING: config.js will be ignored and overwritten by the mapped config.json" fi + if ! jq empty /app/override/config.json 2>/dev/null; then + echo "ERROR: /app/override/config.json is not valid JSON" + exit 1 + fi echo "Startup: converting config.json to config.js"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@build/docker/startup.sh` around lines 30 - 34, Add a JSON validation step in the startup.sh block that builds /usr/share/caddy/config.js: before running the existing heredoc that cats /app/override/config.json, run a check like invoking jq -e . on /app/override/config.json and if it fails print a clear error to stderr and exit non‑zero; only on success continue to write the file (the code that echoes ";(() => { self.traQConfig = " and cats the file into /usr/share/caddy/config.js should remain unchanged but guarded by this validation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@build/docker/startup.sh`:
- Around line 30-34: Add a JSON validation step in the startup.sh block that
builds /usr/share/caddy/config.js: before running the existing heredoc that cats
/app/override/config.json, run a check like invoking jq -e . on
/app/override/config.json and if it fails print a clear error to stderr and exit
non‑zero; only on success continue to write the file (the code that echoes ";(()
=> { self.traQConfig = " and cats the file into /usr/share/caddy/config.js
should remain unchanged but guarded by this validation).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5fd79f12-8068-4e39-a1fd-1b07179b454c
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (11)
.github/workflows/check-schema.yml.prettierignoreREADME.mdbuild/docker/startup.shconfig.d.tsconfig.schema.jsonpackage.jsonpublic/config.jsscripts/generate-schema.jstests/unit/tsconfig.jsontsconfig.json
✅ Files skipped from review due to trivial changes (6)
- tests/unit/tsconfig.json
- tsconfig.json
- .github/workflows/check-schema.yml
- scripts/generate-schema.js
- README.md
- .prettierignore
🚧 Files skipped from review as they are similar to previous changes (1)
- config.schema.json
概要
なぜこの PR を入れたいのか
closes: #4796
Summary by CodeRabbit
リリースノート
ドキュメント
新機能
改善