Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prod deploy #2438

Merged
merged 11 commits into from
Jun 20, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/pg-prove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
image_tag: supabase/pg_prove:${{ steps.version.outputs.pg_prove }}
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
- uses: docker/build-push-action@v6
with:
load: true
context: https://github.com/horrendo/pg_prove.git
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- id: build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
context: https://github.com/horrendo/pg_prove.git
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-migra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
image_tag: supabase/migra:${{ steps.version.outputs.migra }}
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
- uses: docker/build-push-action@v6
with:
load: true
context: https://github.com/djrobstep/migra.git
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- id: build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
context: https://github.com/djrobstep/migra.git
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1
github.com/slack-go/slack v0.13.0
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ github.com/containers/storage v1.54.0 h1:xwYAlf6n9OnIlURQLLg3FYHbO74fQ/2W2N6EtQE
github.com/containers/storage v1.54.0/go.mod h1:PlMOoinRrBSnhYODLxt4EXl0nmJt+X0kjG0Xdt9fMTw=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand Down Expand Up @@ -920,8 +920,8 @@ github.com/spf13/cast v0.0.0-20150508191742-4d07383ffe94/go.mod h1:r2rcYCSwa1IEx
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/jwalterweatherman v0.0.0-20141219030609-3d60171a6431/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
7 changes: 3 additions & 4 deletions internal/functions/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -85,7 +84,8 @@ func Run(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPa
// Use network alias because Deno cannot resolve `_` in hostname
dbUrl := fmt.Sprintf("postgresql://postgres:postgres@%s:5432/postgres", utils.DbAliases[0])
// 3. Serve and log to console
if err := ServeFunctions(ctx, envFilePath, noVerifyJWT, importMapPath, dbUrl, runtimeOption, os.Stderr, fsys); err != nil {
fmt.Fprintln(os.Stderr, "Setting up Edge Functions runtime...")
if err := ServeFunctions(ctx, envFilePath, noVerifyJWT, importMapPath, dbUrl, runtimeOption, fsys); err != nil {
return err
}
if err := utils.DockerStreamLogs(ctx, utils.EdgeRuntimeId, os.Stdout, os.Stderr); err != nil {
Expand All @@ -95,7 +95,7 @@ func Run(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPa
return nil
}

func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPath string, dbUrl string, runtimeOption RuntimeOption, w io.Writer, fsys afero.Fs) error {
func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, importMapPath string, dbUrl string, runtimeOption RuntimeOption, fsys afero.Fs) error {
// 1. Load default values
if envFilePath == "" {
if f, err := fsys.Stat(utils.FallbackEnvFilePath); err == nil && !f.IsDir() {
Expand Down Expand Up @@ -167,7 +167,6 @@ EOF
return errors.Errorf("failed to expose ports: %w", err)
}
// 6. Start container
fmt.Fprintln(w, "Setting up Edge Functions runtime...")
_, err = utils.DockerStart(
ctx,
container.Config{
Expand Down
20 changes: 16 additions & 4 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,14 @@ EOF

fmt.Sprintf("GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED=%v", utils.Config.Auth.EnableAnonymousSignIns),

"GOTRUE_SMTP_HOST=" + utils.InbucketId,
"GOTRUE_SMTP_PORT=2500",
"GOTRUE_SMTP_ADMIN_EMAIL=admin@email.com",
fmt.Sprintf("GOTRUE_SMTP_HOST=%s", utils.Config.Auth.Email.Smtp.Host),
fmt.Sprintf("GOTRUE_SMTP_PORT=%d", utils.Config.Auth.Email.Smtp.Port),
fmt.Sprintf("GOTRUE_SMTP_USER=%s", utils.Config.Auth.Email.Smtp.User),
fmt.Sprintf("GOTRUE_SMTP_PASS=%s", utils.Config.Auth.Email.Smtp.Pass),
fmt.Sprintf("GOTRUE_SMTP_ADMIN_EMAIL=%s", utils.Config.Auth.Email.Smtp.AdminEmail),
fmt.Sprintf("GOTRUE_SMTP_SENDER_NAME=%s", utils.Config.Auth.Email.Smtp.SenderName),
fmt.Sprintf("GOTRUE_SMTP_MAX_FREQUENCY=%v", utils.Config.Auth.Email.MaxFrequency),

// TODO: To be reverted to `/auth/v1/verify` once
// https://github.com/supabase/supabase/issues/16100
// is fixed on upstream GoTrue.
Expand All @@ -448,6 +452,14 @@ EOF
fmt.Sprintf("GOTRUE_SECURITY_MANUAL_LINKING_ENABLED=%v", utils.Config.Auth.EnableManualLinking),
}

if utils.Config.Auth.Sessions.Timebox > 0 {
env = append(env, fmt.Sprintf("GOTRUE_SESSIONS_TIMEBOX=%v", utils.Config.Auth.Sessions.Timebox))
}

if utils.Config.Auth.Sessions.InactivityTimeout > 0 {
env = append(env, fmt.Sprintf("GOTRUE_SESSIONS_INACTIVITY_TIMEOUT=%v", utils.Config.Auth.Sessions.InactivityTimeout))
}

for id, tmpl := range utils.Config.Auth.Email.Template {
if len(tmpl.ContentPath) > 0 {
env = append(env, fmt.Sprintf("GOTRUE_MAILER_TEMPLATES_%s=http://%s:%d/email/%s",
Expand Down Expand Up @@ -838,7 +850,7 @@ EOF
// Start all functions.
if utils.Config.EdgeRuntime.Enabled && !isContainerExcluded(utils.EdgeRuntimeImage, excluded) {
dbUrl := fmt.Sprintf("postgresql://%s:%s@%s:%d/%s", dbConfig.User, dbConfig.Password, dbConfig.Host, dbConfig.Port, dbConfig.Database)
if err := serve.ServeFunctions(ctx, "", nil, "", dbUrl, serve.RuntimeOption{}, w, fsys); err != nil {
if err := serve.ServeFunctions(ctx, "", nil, "", dbUrl, serve.RuntimeOption{}, fsys); err != nil {
return err
}
started = append(started, utils.EdgeRuntimeId)
Expand Down
4 changes: 3 additions & 1 deletion internal/start/templates/pooler.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ params = %{
}]
}

{:ok, _} = Supavisor.Tenants.create_tenant(params)
if !Supavisor.Tenants.get_tenant_by_external_id(params["external_id"]) do
{:ok, _} = Supavisor.Tenants.create_tenant(params)
end
27 changes: 26 additions & 1 deletion internal/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ var Config = config{
"magic_link": {},
"email_change": {},
},
Smtp: smtp{
Host: InbucketAliases[0],
Port: 2500,
AdminEmail: "admin@email.com",
},
},
External: map[string]provider{
"apple": {},
Expand Down Expand Up @@ -390,7 +395,9 @@ type (
EnableRefreshTokenRotation bool `toml:"enable_refresh_token_rotation"`
RefreshTokenReuseInterval uint `toml:"refresh_token_reuse_interval"`
EnableManualLinking bool `toml:"enable_manual_linking"`
Hook hook `toml:"hook"`

Hook hook `toml:"hook"`
Sessions sessions `toml:"sessions"`

EnableSignup bool `toml:"enable_signup"`
EnableAnonymousSignIns bool `toml:"enable_anonymous_sign_ins"`
Expand All @@ -409,9 +416,19 @@ type (
DoubleConfirmChanges bool `toml:"double_confirm_changes"`
EnableConfirmations bool `toml:"enable_confirmations"`
Template map[string]emailTemplate `toml:"template"`
Smtp smtp `toml:"smtp"`
MaxFrequency time.Duration `toml:"max_frequency"`
}

smtp struct {
Host string `toml:"host"`
Port uint16 `toml:"port"`
User string `toml:"user"`
Pass string `toml:"pass"`
AdminEmail string `toml:"admin_email"`
SenderName string `toml:"sender_name"`
}

emailTemplate struct {
Subject string `toml:"subject"`
ContentPath string `toml:"content_path"`
Expand Down Expand Up @@ -444,6 +461,11 @@ type (
Secrets string `toml:"secrets"`
}

sessions struct {
Timebox time.Duration `toml:"timebox"`
InactivityTimeout time.Duration `toml:"inactivity_timeout"`
}

twilioConfig struct {
Enabled bool `toml:"enabled"`
AccountSid string `toml:"account_sid"`
Expand Down Expand Up @@ -708,6 +730,9 @@ func LoadConfigFS(fsys afero.Fs) error {
}
}
}
if Config.Auth.Email.Smtp.Pass, err = maybeLoadEnv(Config.Auth.Email.Smtp.Pass); err != nil {
return err
}
// Validate sms config
if Config.Auth.Sms.Twilio.Enabled {
if len(Config.Auth.Sms.Twilio.AccountSid) == 0 {
Expand Down
1 change: 1 addition & 0 deletions internal/utils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestConfigParsing(t *testing.T) {
t.Setenv("AZURE_CLIENT_ID", "hello")
t.Setenv("AZURE_SECRET", "this is cool")
t.Setenv("AUTH_SEND_SMS_SECRETS", "v1,whsec_aWxpa2VzdXBhYmFzZXZlcnltdWNoYW5kaWhvcGV5b3Vkb3Rvbw==")
t.Setenv("SENDGRID_API_KEY", "sendgrid")
assert.NoError(t, LoadConfigFS(fsys))
// Check error
assert.Equal(t, "hello", Config.Auth.External["azure"].ClientId)
Expand Down
10 changes: 7 additions & 3 deletions internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
PgmetaImage = "supabase/postgres-meta:v0.80.0"
StudioImage = "supabase/studio:20240422-5cf8f30"
ImageProxyImage = "darthsim/imgproxy:v3.8.0"
EdgeRuntimeImage = "supabase/edge-runtime:v1.54.2"
EdgeRuntimeImage = "supabase/edge-runtime:v1.54.6"
VectorImage = "timberio/vector:0.28.1-alpine"
SupavisorImage = "supabase/supavisor:1.1.56"
PgProveImage = "supabase/pg_prove:3.36"
Expand Down Expand Up @@ -230,14 +230,18 @@ func GetCurrentBranchFS(fsys afero.Fs) (string, error) {
}

func AssertSupabaseDbIsRunning() error {
if _, err := Docker.ContainerInspect(context.Background(), DbId); err != nil {
return AssertServiceIsRunning(context.Background(), DbId)
}

func AssertServiceIsRunning(ctx context.Context, containerId string) error {
if _, err := Docker.ContainerInspect(ctx, containerId); err != nil {
if client.IsErrNotFound(err) {
return errors.New(ErrNotRunning)
}
if client.IsErrConnectionFailed(err) {
CmdSuggestion = suggestDockerInstall
}
return errors.Errorf("failed to inspect database container: %w", err)
return errors.Errorf("failed to inspect service: %w", err)
}
return nil
}
Expand Down
16 changes: 16 additions & 0 deletions internal/utils/templates/init_config.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ enable_confirmations = false
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
max_frequency = "1s"

# Use a production-ready SMTP server
[auth.email.smtp]
host = "smtp.sendgrid.net"
port = 587
user = "apikey"
pass = "env(SENDGRID_API_KEY)"
admin_email = "admin@email.com"
sender_name = "Admin"

# Uncomment to customize email template
[auth.email.template.invite]
subject = "You have been invited"
Expand All @@ -119,6 +128,13 @@ max_frequency = "5s"
[auth.sms.test_otp]
4152127777 = "123456"

# Configure logged in session timeouts.
[auth.sessions]
# Force log out after the specified duration.
timebox = "24h"
# Force log out if the user has been inactive longer than the specified duration.
inactivity_timeout = "8h"

[auth.hook.custom_access_token]
enabled = true
uri = "pg-functions://postgres/auth/custom-access-token-hook"
Expand Down
16 changes: 16 additions & 0 deletions internal/utils/templates/init_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ enable_confirmations = false
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
max_frequency = "1s"

# Use a production-ready SMTP server
# [auth.email.smtp]
# host = "smtp.sendgrid.net"
# port = 587
# user = "apikey"
# pass = "env(SENDGRID_API_KEY)"
# admin_email = "admin@email.com"
# sender_name = "Admin"

# Uncomment to customize email template
# [auth.email.template.invite]
# subject = "You have been invited"
Expand All @@ -121,6 +130,13 @@ max_frequency = "5s"
# [auth.sms.test_otp]
# 4152127777 = "123456"

# Configure logged in session timeouts.
# [auth.sessions]
# Force log out after the specified duration.
# timebox = "24h"
# Force log out if the user has been inactive longer than the specified duration.
# inactivity_timeout = "8h"

# This hook runs before a token is issued and allows you to add additional claims based on the authentication method used.
# [auth.hook.custom_access_token]
# enabled = true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"bin-links": "^4.0.3",
"https-proxy-agent": "^7.0.2",
"node-fetch": "^3.3.2",
"tar": "7.2.0"
"tar": "7.4.0"
},
"release": {
"branches": [
Expand Down