Skip to content

Commit

Permalink
feat(start): add Supabase Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Nov 30, 2021
1 parent b396cc0 commit b4042d1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/init/templates/init_config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ports": {
"api": 54321,
"db": 54322,
"pgMeta": 54323
"studio": 54323
},
"dbVersion": "{{ .DbVersion }}"
}
28 changes: 22 additions & 6 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Run() error {
if err := utils.AssertPortIsAvailable(utils.DbPort); err != nil {
return err
}
if err := utils.AssertPortIsAvailable(utils.PgmetaPort); err != nil {
if err := utils.AssertPortIsAvailable(utils.StudioPort); err != nil {
return err
}
if err := utils.AssertPortIsAvailable(utils.InbucketPort); err != nil {
Expand Down Expand Up @@ -165,7 +165,8 @@ Inbucket URL: http://localhost:` + utils.InbucketPort

return `Started local development setup.
API URL: http://localhost:` + utils.ApiPort + `
DB URL: postgresql://postgres:postgres@localhost:` + utils.DbPort + "/postgres" + maybeInbucket + `
DB URL: postgresql://postgres:postgres@localhost:` + utils.DbPort + `/postgres
Studio URL: http://localhost:` + utils.StudioPort + maybeInbucket + `
anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiJ9.ZopqoUt20nEV9cklpv9e3yw3PVyZLmKs5qLD6nGL1SI
service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIn0.M2d2z4SFn5C7HlJlaSLfrzuYim9nbY_XI40uWFN3hEE`
}
Expand Down Expand Up @@ -412,7 +413,7 @@ func run(p *tea.Program) error {
}
}

p.Send(utils.StatusMsg("Starting db container..."))
p.Send(utils.StatusMsg("Starting database..."))

// Start postgres.
{
Expand Down Expand Up @@ -710,7 +711,6 @@ EOSQL
}

// Start gotrue.

{
env := []string{
"API_EXTERNAL_URL=http://localhost:" + utils.ApiPort,
Expand Down Expand Up @@ -784,7 +784,6 @@ EOSQL
}

// Start Realtime.

{
if _, err := utils.DockerRun(ctx, utils.RealtimeId, &container.Config{
Image: utils.RealtimeImage,
Expand Down Expand Up @@ -874,9 +873,26 @@ EOSQL
"PG_META_DB_HOST=" + utils.PgbouncerId,
},
},
&container.HostConfig{NetworkMode: container.NetworkMode(utils.NetId)},
); err != nil {
return err
}

// Start Studio.
if _, err := utils.DockerRun(
ctx,
utils.StudioId,
&container.Config{
Image: utils.StudioImage,
Env: []string{
"SUPABASE_URL=http://" + utils.KongId + ":8000",
"STUDIO_PG_META_URL=http://" + utils.PgmetaId + ":8080",
"SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIn0.M2d2z4SFn5C7HlJlaSLfrzuYim9nbY_XI40uWFN3hEE",
},
},
&container.HostConfig{
PortBindings: nat.PortMap{"8080/tcp": []nat.PortBinding{{HostPort: utils.PgmetaPort}}},
NetworkMode: container.NetworkMode(utils.NetId),
PortBindings: nat.PortMap{"3000/tcp": []nat.PortBinding{{HostPort: utils.StudioPort}}},
},
); err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions internal/start/templates/kong_config
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ services:
- /storage/v1/
plugins:
- name: cors
- name: pg-meta
_comment: "pg-meta: /pg/* -> http://pg-meta:8080/*"
url: http://supabase_pg_meta_{{ .ProjectId }}:8080/
routes:
- name: pg-meta-all
strip_path: true
paths:
- /pg/
consumers:
- username: anon
keyauth_credentials:
Expand Down
8 changes: 6 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
StorageImage = "supabase/storage-api:v0.9.3"
DifferImage = "supabase/pgadmin-schema-diff:cli-0.0.4"
PgmetaImage = "supabase/postgres-meta:v0.28.0"
// TODO: Hardcode version once provided upstream.
StudioImage = "supabase/studio:latest"

// Args: dbname
TerminateDbSqlFmt = `ALTER DATABASE "%[1]s" CONNECTION LIMIT 0;
Expand All @@ -70,7 +72,7 @@ var (
ApiPort string
InbucketPort string
DbPort string
PgmetaPort string
StudioPort string
DbVersion string
DbImage string
ProjectId string
Expand All @@ -85,6 +87,7 @@ var (
StorageId string
DifferId string
PgmetaId string
StudioId string
)

func GetCurrentTimestamp() string {
Expand Down Expand Up @@ -133,7 +136,7 @@ func LoadConfig() {
InbucketPort = fmt.Sprint(viper.GetUint("ports.inbucket"))
}
DbPort = fmt.Sprint(viper.GetUint("ports.db"))
PgmetaPort = fmt.Sprint(viper.GetUint("ports.pgMeta"))
StudioPort = fmt.Sprint(viper.GetUint("ports.studio"))
DbVersion = viper.GetString("dbVersion")
switch DbVersion {
case
Expand Down Expand Up @@ -170,6 +173,7 @@ func LoadConfig() {
StorageId = "supabase_storage_" + ProjectId
DifferId = "supabase_differ_" + ProjectId
PgmetaId = "supabase_pg_meta_" + ProjectId
StudioId = "supabase_studio_" + ProjectId
}

func AssertSupabaseStartIsRunning() {
Expand Down

0 comments on commit b4042d1

Please sign in to comment.