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 #2589

Merged
merged 12 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"os/signal"

"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/supabase/cli/internal/seed/buckets"
"github.com/supabase/cli/internal/utils"
Expand All @@ -27,7 +28,7 @@ var (
Short: "Seed buckets declared in [storage.buckets]",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return buckets.Run(cmd.Context(), flags.ProjectRef, utils.NewConsole())
return buckets.Run(cmd.Context(), flags.ProjectRef, true, afero.NewOsFs())
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func GenYamlDoc(cmd *cobra.Command, root *SpecDoc) CmdDoc {
Subcommands: subcommands,
}

names := strings.Split(cmd.CommandPath(), " ")
names := strings.Fields(cmd.CommandPath())
if len(names) > 3 {
base := strings.Join(names[2:], "-")
names = append(names[:2], base)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/charmbracelet/lipgloss v0.12.1
github.com/containers/common v0.59.2
github.com/deepmap/oapi-codegen/v2 v2.2.0
github.com/docker/cli v26.1.2+incompatible
github.com/docker/docker v26.1.4+incompatible
github.com/docker/cli v26.1.5+incompatible
github.com/docker/docker v26.1.5+incompatible
github.com/docker/go-connections v0.5.0
github.com/docker/go-units v0.5.0
github.com/getsentry/sentry-go v0.28.1
Expand Down Expand Up @@ -48,7 +48,8 @@ require (
github.com/stripe/pg-schema-diff v0.7.0
github.com/withfig/autocomplete-tools/packages/cobra v1.2.0
github.com/zalando/go-keyring v0.2.5
golang.org/x/mod v0.19.0
go.opentelemetry.io/otel v1.28.0
golang.org/x/mod v0.20.0
golang.org/x/oauth2 v0.21.0
golang.org/x/term v0.22.0
google.golang.org/grpc v1.65.0
Expand Down Expand Up @@ -317,7 +318,6 @@ require (
go-simpler.org/musttag v0.12.2 // indirect
go-simpler.org/sloglint v0.7.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk=
github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE=
github.com/docker/cli v26.1.2+incompatible h1:/MWZpUMMlr1hCGyquL8QNbL1hbivQ1kLuT3Z9s1Tlpg=
github.com/docker/cli v26.1.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v26.1.5+incompatible h1:NxXGSdz2N+Ibdaw330TDO3d/6/f7MvHuiMbuFaIQDTk=
github.com/docker/cli v26.1.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v26.1.4+incompatible h1:vuTpXDuoga+Z38m1OZHzl7NKisKWaWlhjQk7IDPSLsU=
github.com/docker/docker v26.1.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.1.5+incompatible h1:NEAxTwEjxV6VbBMBoGG3zPqbiJosIApZjxlbrG9q3/g=
github.com/docker/docker v26.1.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.8.1 h1:j/eKUktUltBtMzKqmfLB0PAgqYyMHOp5vfsD1807oKo=
github.com/docker/docker-credential-helpers v0.8.1/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c h1:lzqkGL9b3znc+ZUgi7FlLnqjQhcXxkNM/quxIjBVMD0=
Expand Down Expand Up @@ -1146,8 +1146,8 @@ golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
5 changes: 3 additions & 2 deletions internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/supabase/cli/internal/utils/tenant"
"github.com/supabase/cli/pkg/api"
"github.com/supabase/cli/pkg/fetcher"
"github.com/supabase/cli/pkg/queue"
"golang.org/x/term"
)

Expand Down Expand Up @@ -362,14 +363,14 @@ func downloadSample(ctx context.Context, client *github.Client, templateUrl stri

type Downloader struct {
api *fetcher.Fetcher
queue *utils.JobQueue
queue *queue.JobQueue
fsys afero.Fs
}

func NewDownloader(concurrency uint, fsys afero.Fs) *Downloader {
return &Downloader{
api: fetcher.NewFetcher("", fetcher.WithExpectedStatus(http.StatusOK)),
queue: utils.NewJobQueue(concurrency),
queue: queue.NewJobQueue(concurrency),
fsys: fsys,
}
}
Expand Down
18 changes: 14 additions & 4 deletions internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/supabase/cli/internal/gen/keys"
"github.com/supabase/cli/internal/migration/apply"
"github.com/supabase/cli/internal/migration/repair"
"github.com/supabase/cli/internal/seed/buckets"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/migration"
)
Expand All @@ -43,17 +45,21 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F
}
return resetRemote(ctx, version, config, fsys, options...)
}

// Config file is loaded before parsing --linked or --local flags
if err := utils.AssertSupabaseDbIsRunning(); err != nil {
return err
}

// Reset postgres database because extensions (pg_cron, pg_net) require postgres
if err := resetDatabase(ctx, version, fsys, options...); err != nil {
return err
}

// Seed objects from supabase/buckets directory
if err := start.WaitForHealthyService(ctx, 30*time.Second, utils.StorageId); err != nil {
return err
}
if err := buckets.Run(ctx, "", false, fsys); err != nil {
return err
}
branch := keys.GetGitBranch(fsys)
fmt.Fprintln(os.Stderr, "Finished "+utils.Aqua("supabase db reset")+" on branch "+utils.Aqua(branch)+".")
return nil
Expand Down Expand Up @@ -199,7 +205,7 @@ func RestartDatabase(ctx context.Context, w io.Writer) error {

func restartServices(ctx context.Context) error {
// No need to restart PostgREST because it automatically reconnects and listens for schema changes
services := []string{utils.StorageId, utils.GotrueId, utils.RealtimeId}
services := listServicesToRestart()
result := utils.WaitAll(services, func(id string) error {
if err := utils.Docker.ContainerRestart(ctx, id, container.StopOptions{}); err != nil && !errdefs.IsNotFound(err) {
return errors.Errorf("Failed to restart %s: %w", id, err)
Expand All @@ -210,6 +216,10 @@ func restartServices(ctx context.Context) error {
return errors.Join(result...)
}

func listServicesToRestart() []string {
return []string{utils.StorageId, utils.GotrueId, utils.RealtimeId, utils.PoolerId}
}

func resetRemote(ctx context.Context, version string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
fmt.Fprintln(os.Stderr, "Resetting remote database"+toLogMessage(version))
conn, err := utils.ConnectByConfigStream(ctx, config, io.Discard, options...)
Expand Down
7 changes: 6 additions & 1 deletion internal/db/reset/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func TestRestartDatabase(t *testing.T) {
utils.StorageId = "test-storage"
utils.GotrueId = "test-auth"
utils.RealtimeId = "test-realtime"
for _, container := range []string{utils.StorageId, utils.GotrueId, utils.RealtimeId} {
utils.PoolerId = "test-pooler"
for _, container := range listServicesToRestart() {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart").
Reply(http.StatusOK)
Expand Down Expand Up @@ -259,11 +260,15 @@ func TestRestartDatabase(t *testing.T) {
utils.StorageId = "test-storage"
utils.GotrueId = "test-auth"
utils.RealtimeId = "test-realtime"
utils.PoolerId = "test-pooler"
for _, container := range []string{utils.StorageId, utils.GotrueId, utils.RealtimeId} {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart").
Reply(http.StatusServiceUnavailable)
}
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.PoolerId + "/restart").
Reply(http.StatusNotFound)
// Run test
err := RestartDatabase(context.Background(), io.Discard)
// Check error
Expand Down
Loading
Loading