0
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?

Supabase で local の docker と remote の staging/prod で config.toml をうまくする

Last updated at Posted at 2025-04-03

はじめに

表題ままなのですが、supabase で開発をしていて config.toml が supabase-cli で config push や pull(というか link でdiff確認) できるのだけど、local docker と remote と環境を分けて管理したいところもあるので、その対応方法の一つを編み出してみた(大げさ)のでメモ。

設定方法

$ supabase config push
$ supabase link

って結構気持ちいい?機能があるのですが、それを実行する時って、.env を普通に使っても、環境のあれこれ整理整頓しづらかった。

ところで config.toml は、remote の supabase.com の branch には対応しているとのこと

これを利用することで supabase remote 環境で branch を切っていないシングルでの運用の時もうまくできそう。

config.toml
# For detailed configuration reference documentation, visit:
# https://supabase.com/docs/guides/local-development/cli/config
# A string used to distinguish different Supabase projects on the same host. Defaults to the
# working directory name when running `supabase init`.
project_id = "your-docker-container-base-id"

[remotes.default]
# project_id = "env(REMOTES_DEFAULT_PROJECT_ID)"  # 202504 ここで env は使えない?
project_id = "your-remote-project-id" # 20桁の英字のID

[auth]
enabled = true
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
# in emails.
site_url = "http://localhost:5173"
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
additional_redirect_urls = ["http://localhost:5173"]

[remotes.default.auth]
site_url = "env(REMOTES_DEFAULT_AUTH_SITE_URL)"
additional_redirect_urls = ["env(REMOTES_DEFAULT_AUTH_SITE_URL)"]

# [remotes.default.xxxx.xxxx] で色々追加できるよ
# ex.) ↓ 例えばこんな感じ
# [auth.email.smtp]
# enabled = false
# [remotes.default.auth.email.smtp]
# enabled = true
# host = "env(SMTP_HOST)"
# port = "env(SMTP_PORT)"
# user = "env(SMTP_USER)"
# pass = "env(SMTP_PASS)"
# admin_email = "env(SMTP_ADMIN_EMAIL)"
# sender_name = "env(SMTP_SENDER_NAME)"
.env
REMOTES_DEFAULT_PROJECT_ID="202504 ここで env は使えない?"
REMOTES_DEFAULT_AUTH_SITE_URL="https://your-website.example.com"

TODO

[remotes.default]
project_id = "env(REMOTES_DEFAULT_PROJECT_ID)"

これに対応していないっぽい。

もう少し調査して状況によって issue 立てるか pull request も。

そこまで project_id の秘匿にこだわる必要は今のところはないのだけれど。

もしかしたら

.env.preview というのも supabase 関連で少し目にするので、何かしらそれで対応できる可能性もあるよ。

注意事項

additional_redirect_urls の配列的なところが、まるッと一気に設定できないと思うので、もし環境変数対応するなら

config.toml
[remotes.default.auth]
site_url = "env(REMOTES_DEFAULT_AUTH_SITE_URL)"
additional_redirect_urls = [
    "env(REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL1)",
    "env(REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL2)",
    "env(REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL3)",
    ]
.env
REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL1="https://your-website.example.com"
REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL2="https://her-website.example.com"
REMOTES_DEFAULT_AUTH_ADDITIONAL_REDIERCT_URL3="https://he-website.example.com"

こんな感じに丁寧にするしかないのかな。

お願い

もし間違えていたり、アップデートがあって対応方法が変わったよ!とかお気づきの方は、コメントなどいただけると助かります。

0
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
0
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?