Skip to content

Commit

Permalink
feat: Add inbucket to local setup (#78)
Browse files Browse the repository at this point in the history
* Add inbucket

* Add additional Gotrue configuration

* chore: gofmt

* make inbucket opt-in

* hide inbucket url when not enabled

* only bind inbucket port when enabled

Co-authored-by: Bobbie Soedirgo <[email protected]>
  • Loading branch information
NixBiks and soedirgo authored Nov 30, 2021
1 parent d39300b commit ea01313
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var (
},
}

dbCommitCmd = &cobra.Command{
dbCommitCmd = &cobra.Command{
Use: "commit <migration name>",
Short: "Diffs the local database with current migrations, writing it as a new migration.",
Args: cobra.ExactArgs(1),
Expand Down
111 changes: 87 additions & 24 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func Run() error {
if err := utils.AssertPortIsAvailable(utils.PgmetaPort); err != nil {
return err
}
if err := utils.AssertPortIsAvailable(utils.InbucketPort); err != nil {
return err
}
}

s := spinner.NewModel()
Expand Down Expand Up @@ -154,9 +157,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m model) View() string {
// TODO: Unhardcode keys
if m.started {
maybeInbucket := ""
if utils.InbucketPort != "" {
maybeInbucket = `
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
DB URL: postgresql://postgres:postgres@localhost:` + utils.DbPort + "/postgres" + maybeInbucket + `
anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiJ9.ZopqoUt20nEV9cklpv9e3yw3PVyZLmKs5qLD6nGL1SI
service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIn0.M2d2z4SFn5C7HlJlaSLfrzuYim9nbY_XI40uWFN3hEE`
}
Expand Down Expand Up @@ -323,6 +332,19 @@ func run(p *tea.Program) error {
return err
}
}
if _, _, err := utils.Docker.ImageInspectWithRaw(ctx, "docker.io/"+utils.InbucketImage); err != nil {
out, err := utils.Docker.ImagePull(
ctx,
"docker.io/"+utils.InbucketImage,
types.ImagePullOptions{},
)
if err != nil {
return err
}
if err := utils.ProcessPullOutput(out, p); err != nil {
return err
}
}
if _, _, err := utils.Docker.ImageInspectWithRaw(ctx, "docker.io/"+utils.RealtimeImage); err != nil {
out, err := utils.Docker.ImagePull(
ctx,
Expand Down Expand Up @@ -689,35 +711,76 @@ EOSQL

// Start gotrue.

if _, err := utils.DockerRun(
ctx,
utils.GotrueId,
&container.Config{
Image: utils.GotrueImage,
Env: []string{
"GOTRUE_API_HOST=0.0.0.0",
"GOTRUE_API_PORT=9999",
{
env := []string{
"API_EXTERNAL_URL=http://localhost:" + utils.ApiPort,

"GOTRUE_API_HOST=0.0.0.0",
"GOTRUE_API_PORT=9999",

"GOTRUE_DB_DRIVER=postgres",
"GOTRUE_DB_DATABASE_URL=postgres://supabase_auth_admin:postgres@" + utils.PgbouncerId + ":5432/postgres?sslmode=disable",

"GOTRUE_DB_DRIVER=postgres",
"GOTRUE_DB_DATABASE_URL=postgres://supabase_auth_admin:postgres@" + utils.PgbouncerId + ":5432/postgres?sslmode=disable",
"GOTRUE_SITE_URL=http://localhost:3000",
"GOTRUE_DISABLE_SIGNUP=false",

"GOTRUE_SITE_URL=http://localhost:8000",
"GOTRUE_DISABLE_SIGNUP=false",
"GOTRUE_JWT_SECRET=super-secret-jwt-token-with-at-least-32-characters-long",
"GOTRUE_JWT_EXP=3600",
"GOTRUE_JWT_DEFAULT_GROUP_NAME=authenticated",

"GOTRUE_JWT_SECRET=super-secret-jwt-token-with-at-least-32-characters-long",
"GOTRUE_JWT_EXP=3600",
"GOTRUE_JWT_DEFAULT_GROUP_NAME=authenticated",
"GOTRUE_EXTERNAL_EMAIL_ENABLED=true",

"GOTRUE_EXTERNAL_EMAIL_ENABLED=true",
"GOTRUE_MAILER_AUTOCONFIRM=true",
"GOTRUE_EXTERNAL_PHONE_ENABLED=true",
"GOTRUE_SMS_AUTOCONFIRM=true",
}

"GOTRUE_EXTERNAL_PHONE_ENABLED=true",
"GOTRUE_SMS_AUTOCONFIRM=true",
if utils.InbucketPort == "" {
env = append(env, "GOTRUE_MAILER_AUTOCONFIRM=true")
} else {
env = append(env,
"GOTRUE_MAILER_AUTOCONFIRM=false",
"GOTRUE_SMTP_HOST="+utils.InbucketId,
"GOTRUE_SMTP_PORT=2500",
"GOTRUE_SMTP_USER=GOTRUE_SMTP_USER",
"GOTRUE_SMTP_PASS=GOTRUE_SMTP_PASS",
"[email protected]",
"GOTRUE_MAILER_URLPATHS_INVITE=/auth/v1/verify",
"GOTRUE_MAILER_URLPATHS_CONFIRMATION=/auth/v1/verify",
"GOTRUE_MAILER_URLPATHS_RECOVERY=/auth/v1/verify",
"GOTRUE_MAILER_URLPATHS_EMAIL_CHANGE=/auth/v1/verify",
)
}

if _, err := utils.DockerRun(
ctx,
utils.GotrueId,
&container.Config{
Image: utils.GotrueImage,
Env: env,
},
},
&container.HostConfig{NetworkMode: container.NetworkMode(utils.NetId)},
); err != nil {
return err
&container.HostConfig{NetworkMode: container.NetworkMode(utils.NetId)},
); err != nil {
return err
}
}

// Start Inbucket.
{
hostConfig := container.HostConfig{NetworkMode: container.NetworkMode(utils.NetId)}
if utils.InbucketPort != "" {
hostConfig.PortBindings = nat.PortMap{"9000/tcp": []nat.PortBinding{{HostPort: utils.InbucketPort}}}
}

if _, err := utils.DockerRun(
ctx,
utils.InbucketId,
&container.Config{
Image: utils.InbucketImage,
},
&hostConfig,
); err != nil {
return err
}
}

// Start Realtime.
Expand Down
39 changes: 23 additions & 16 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
PgbouncerImage = "edoburu/pgbouncer:1.15.0"
KongImage = "library/kong:2.1"
GotrueImage = "supabase/gotrue:v2.2.6"
InbucketImage = "inbucket/inbucket:stable"
RealtimeImage = "supabase/realtime:v0.18.0"
PostgrestImage = "postgrest/postgrest:v8.0.0"
StorageImage = "supabase/storage-api:v0.9.3"
Expand All @@ -66,22 +67,24 @@ var (
return docker
}()

ApiPort string
DbPort string
PgmetaPort string
DbVersion string
DbImage string
ProjectId string
NetId string
DbId string
PgbouncerId string
KongId string
GotrueId string
RealtimeId string
RestId string
StorageId string
DifferId string
PgmetaId string
ApiPort string
InbucketPort string
DbPort string
PgmetaPort string
DbVersion string
DbImage string
ProjectId string
NetId string
DbId string
PgbouncerId string
KongId string
GotrueId string
InbucketId string
RealtimeId string
RestId string
StorageId string
DifferId string
PgmetaId string
)

func GetCurrentTimestamp() string {
Expand Down Expand Up @@ -126,6 +129,9 @@ func LoadConfig() {
}

ApiPort = fmt.Sprint(viper.GetUint("ports.api"))
if viper.IsSet("ports.inbucket") {
InbucketPort = fmt.Sprint(viper.GetUint("ports.inbucket"))
}
DbPort = fmt.Sprint(viper.GetUint("ports.db"))
PgmetaPort = fmt.Sprint(viper.GetUint("ports.pgMeta"))
DbVersion = viper.GetString("dbVersion")
Expand Down Expand Up @@ -158,6 +164,7 @@ func LoadConfig() {
PgbouncerId = "supabase_pgbouncer_" + ProjectId
KongId = "supabase_kong_" + ProjectId
GotrueId = "supabase_auth_" + ProjectId
InbucketId = "supabase_inbucket_" + ProjectId
RealtimeId = "supabase_realtime_" + ProjectId
RestId = "supabase_rest_" + ProjectId
StorageId = "supabase_storage_" + ProjectId
Expand Down

0 comments on commit ea01313

Please sign in to comment.