Skip to content

Commit

Permalink
Initial setup for email template server
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Jul 10, 2023
1 parent 2bcc9c7 commit a381bed
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
42 changes: 42 additions & 0 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ EOF
"GOTRUE_MAILER_URLPATHS_CONFIRMATION=/auth/v1/verify",
"GOTRUE_MAILER_URLPATHS_RECOVERY=/auth/v1/verify",
"GOTRUE_MAILER_URLPATHS_EMAIL_CHANGE=/auth/v1/verify",
fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_INVITE=http://%s:8088/invite", utils.GotrueEmailId),
fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_CONFIRMATION=http://%s:8088/confirmation", utils.GotrueEmailId),
fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_RECOVERY=http://%s:8088/recovery", utils.GotrueEmailId),
fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_MAGIC_LINK=http://%s:8088/magic-link", utils.GotrueEmailId),
fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_EMAIL_CHANGE=http://%s:8088/email-change", utils.GotrueEmailId),
"GOTRUE_RATE_LIMIT_EMAIL_SENT=360000",

fmt.Sprintf("GOTRUE_EXTERNAL_PHONE_ENABLED=%v", utils.Config.Auth.Sms.EnableSignup),
Expand Down Expand Up @@ -431,6 +436,7 @@ EOF
},
start.WithSyslogConfig(container.HostConfig{
RestartPolicy: container.RestartPolicy{Name: "always"},
ExtraHosts: []string{"host.docker.internal:host-gateway"},
}),
utils.GotrueId,
); err != nil {
Expand All @@ -439,6 +445,42 @@ EOF
started = append(started, utils.GotrueId)
}

// Start Gotrue Email template server
if !isContainerExcluded(utils.GotrueEmailImage, excluded) {
cwd, err := os.Getwd()
if err != nil {
return err
}
env := []string{
"GOTRUE_MAILER_TEMPLATES_RECOVERY=/home/templates/recovery.html",
"GOTRUE_MAILER_TEMPLATES_INVITE=/home/templates/invite.html",
"GOTRUE_MAILER_TEMPLATES_CONFIRMATION=/home/templates/confirmation.html",
"GOTRUE_MAILER_TEMPLATES_MAGIC_LINK=/home/templates/magic-link.html",
"GOTRUE_MAILER_TEMPLATES_EMAIL_CHANGE=/home/templates/email-change.html",
}

binds := []string{
filepath.Join(cwd, utils.EmailTemplatesDir) + ":/home/templates:rw,z",
}

if _, err := utils.DockerStart(
ctx,
container.Config{
Image: utils.GotrueEmailImage,
Env: env,
},
container.HostConfig{
Binds: binds,
PortBindings: nat.PortMap{"8088/tcp": []nat.PortBinding{{HostPort: strconv.FormatUint(uint64(54330), 10)}}},
RestartPolicy: container.RestartPolicy{Name: "always"},
},
utils.GotrueEmailId,
); err != nil {
return err
}
started = append(started, utils.GotrueEmailId)
}

// Start Inbucket.
if utils.Config.Inbucket.Enabled && !isContainerExcluded(utils.InbucketImage, excluded) {
inbucketPortBindings := nat.PortMap{"9000/tcp": []nat.PortBinding{{HostPort: strconv.FormatUint(uint64(utils.Config.Inbucket.Port), 10)}}}
Expand Down
2 changes: 2 additions & 0 deletions internal/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
ConfigId string
KongId string
GotrueId string
GotrueEmailId string
InbucketId string
RealtimeId string
RestId string
Expand Down Expand Up @@ -283,6 +284,7 @@ func LoadConfigFS(fsys afero.Fs) error {
ConfigId = "supabase_config_" + Config.ProjectId
KongId = "supabase_kong_" + Config.ProjectId
GotrueId = "supabase_auth_" + Config.ProjectId
GotrueEmailId = "supabase_email_templates_" + Config.ProjectId
InbucketId = "supabase_inbucket_" + Config.ProjectId
RealtimeId = "realtime-dev.supabase_realtime_" + Config.ProjectId
RestId = "supabase_rest_" + Config.ProjectId
Expand Down
5 changes: 4 additions & 1 deletion internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const (
ImageProxyImage = "darthsim/imgproxy:v3.8.0"
EdgeRuntimeImage = "supabase/edge-runtime:v1.5.2"
VectorImage = "timberio/vector:0.28.1-alpine"
GotrueEmailImage = "silentworks/gotrue-email:v0.0.2"
// Update initial schemas in internal/utils/templates/initial_schemas when
// updating any one of these.
GotrueImage = "supabase/gotrue:v2.62.1"
GotrueImage = "supabase/gotrue:v2.82.0"
RealtimeImage = "supabase/realtime:v2.10.1"
StorageImage = "supabase/storage-api:v0.40.4"
LogflareImage = "supabase/logflare:1.0.2"
Expand All @@ -47,6 +48,7 @@ const (

var ServiceImages = []string{
GotrueImage,
GotrueEmailImage,
RealtimeImage,
StorageImage,
ImageProxyImage,
Expand Down Expand Up @@ -168,6 +170,7 @@ var (
CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch")
MigrationsDir = filepath.Join(SupabaseDirPath, "migrations")
FunctionsDir = filepath.Join(SupabaseDirPath, "functions")
EmailTemplatesDir = filepath.Join(SupabaseDirPath, "templates")
FallbackImportMapPath = filepath.Join(FunctionsDir, "import_map.json")
FallbackEnvFilePath = filepath.Join(FunctionsDir, ".env")
DbTestsDir = filepath.Join(SupabaseDirPath, "tests")
Expand Down

0 comments on commit a381bed

Please sign in to comment.