From a5c7ae343f4472f4855280d12eac8788a42e5860 Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Fri, 13 Aug 2021 17:54:14 +0800 Subject: [PATCH] feat: add pg-meta --- internal/init/init.go | 3 ++- internal/start/start.go | 27 +++++++++++++++++++++++++++ internal/utils/utils.go | 7 ++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/internal/init/init.go b/internal/init/init.go index 82b62202d..07cacb385 100644 --- a/internal/init/init.go +++ b/internal/init/init.go @@ -1046,7 +1046,8 @@ ALTER EVENT TRIGGER issue_pg_cron_access OWNER TO postgres; "projectId": "%[1]s", "ports": { "api": 8000, - "db": 5432 + "db": 5432, + "pgMeta": 3000 }, "dbVersion": "120007", "excludeSchemas": ["extensions"] diff --git a/internal/start/start.go b/internal/start/start.go index 87c1f6877..620ede6ba 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -259,6 +259,13 @@ func Start() error { } io.Copy(os.Stdout, out) } + if _, _, err := utils.Docker.ImageInspectWithRaw(ctx, "docker.io/"+utils.PgMetaImage); err != nil { + out, err := utils.Docker.ImagePull(ctx, "docker.io/"+utils.PgMetaImage, types.ImagePullOptions{}) + if err != nil { + return err + } + io.Copy(os.Stdout, out) + } } fmt.Println("Done pulling images.") @@ -513,6 +520,26 @@ EOSQL fmt.Println("Started.") + // Start pg-meta. + + if err := utils.DockerRun( + ctx, + utils.PgMetaId, + &container.Config{ + Image: utils.PgMetaImage, + Env: []string{ + "PG_META_PORT=8080", + "PG_META_DB_HOST=" + utils.DbId, + }, + }, + &container.HostConfig{ + PortBindings: nat.PortMap{"8080/tcp": []nat.PortBinding{{HostPort: utils.PgMetaPort}}}, + NetworkMode: container.NetworkMode(utils.NetId), + }, + ); err != nil { + return err + } + // switch db on switch branch for { diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 29f35420c..6e6f969da 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -123,8 +123,9 @@ GRANT supabase_admin TO authenticator GRANTED BY postgres; RealtimeImage = "supabase/realtime:v0.15.0" PostgrestImage = "postgrest/postgrest:v7.0.1" DifferImage = "supabase/pgadmin-schema-diff:cli-0.0.2" + PgMetaImage = "supabase/postgres-meta:v0.24.1" // Latest supabase/postgres image *on hosted platform*. - LatestDbImage = "supabase/postgres:0.14.0" + LatestDbImage = "supabase/postgres:0.14.0" ) var ( @@ -138,6 +139,7 @@ var ( }() ApiPort string DbPort string + PgMetaPort string DbImage string ProjectId string NetId string @@ -148,6 +150,7 @@ var ( RealtimeId string RestId string DifferId string + PgMetaId string ) func GetCurrentTimestamp() string { @@ -186,6 +189,7 @@ func LoadConfig() { ApiPort = fmt.Sprint(viper.GetUint("ports.api")) DbPort = fmt.Sprint(viper.GetUint("ports.db")) + PgMetaPort = fmt.Sprint(viper.GetUint("ports.pgMeta")) dbVersion := viper.GetString("dbVersion") switch dbVersion { case "120007": @@ -203,6 +207,7 @@ func LoadConfig() { RealtimeId = "supabase_realtime_" + ProjectId RestId = "supabase_rest_" + ProjectId DifferId = "supabase_differ_" + ProjectId + PgMetaId = "supabase_pg_meta_" + ProjectId } func AssertSupabaseStartIsRunning() {