From 63e374900178acda57683b484c3aa840f578f09b Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Thu, 15 Jun 2023 14:17:16 +0800 Subject: [PATCH 1/3] fix: persist config volume between restarts --- internal/db/start/start.go | 7 +++++-- internal/stop/stop.go | 2 +- internal/utils/config.go | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/db/start/start.go b/internal/db/start/start.go index 967ecff089..74610ccfdc 100644 --- a/internal/db/start/start.go +++ b/internal/db/start/start.go @@ -81,8 +81,11 @@ func StartDatabase(ctx context.Context, fsys afero.Fs, w io.Writer, options ...f hostConfig := WithSyslogConfig(container.HostConfig{ PortBindings: nat.PortMap{"5432/tcp": []nat.PortBinding{{HostPort: hostPort}}}, RestartPolicy: container.RestartPolicy{Name: "always"}, - Binds: []string{utils.DbId + ":/var/lib/postgresql/data"}, - ExtraHosts: []string{"host.docker.internal:host-gateway"}, + Binds: []string{ + utils.DbId + ":/var/lib/postgresql/data", + utils.ConfigId + ":/etc/postgresql-custom", + }, + ExtraHosts: []string{"host.docker.internal:host-gateway"}, }) if utils.Config.Db.MajorVersion <= 14 { config.Entrypoint = nil diff --git a/internal/stop/stop.go b/internal/stop/stop.go index b97c9c6958..3cb178ab0d 100644 --- a/internal/stop/stop.go +++ b/internal/stop/stop.go @@ -55,7 +55,7 @@ func stop(ctx context.Context, backup bool) error { fmt.Fprintln(os.Stderr, "Storage directory saved to volume:", utils.StorageId) } else { // TODO: label named volumes to use VolumesPrune for branch support - volumes := []string{utils.DbId, utils.StorageId} + volumes := []string{utils.ConfigId, utils.DbId, utils.StorageId} utils.WaitAll(volumes, func(name string) { if err := utils.Docker.VolumeRemove(ctx, name, true); err != nil { fmt.Fprintln(os.Stderr, "failed to remove volume:", name, err) diff --git a/internal/utils/config.go b/internal/utils/config.go index 8be6892b3f..f52d26b3ab 100644 --- a/internal/utils/config.go +++ b/internal/utils/config.go @@ -21,6 +21,7 @@ var ( DbImage string NetId string DbId string + ConfigId string KongId string GotrueId string InbucketId string @@ -206,6 +207,7 @@ func LoadConfigFS(fsys afero.Fs) error { } else { NetId = "supabase_network_" + Config.ProjectId DbId = "supabase_db_" + Config.ProjectId + ConfigId = "supabase_config_" + Config.ProjectId KongId = "supabase_kong_" + Config.ProjectId GotrueId = "supabase_auth_" + Config.ProjectId InbucketId = "supabase_inbucket_" + Config.ProjectId From 2e8a454aa7f19c1730c21773fe9c8c4dfa777b16 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Thu, 15 Jun 2023 14:32:49 +0800 Subject: [PATCH 2/3] chore: update unit tests for removing config volume --- internal/db/start/start_test.go | 1 + internal/stop/stop_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/internal/db/start/start_test.go b/internal/db/start/start_test.go index 49e52055da..d0bd0367e8 100644 --- a/internal/db/start/start_test.go +++ b/internal/db/start/start_test.go @@ -86,6 +86,7 @@ func TestStartDatabase(t *testing.T) { utils.DbImage = utils.Pg15Image utils.Config.Db.MajorVersion = 15 utils.DbId = "supabase_db_test" + utils.ConfigId = "supabase_config_test" utils.Config.Db.Port = 5432 // Setup in-memory fs fsys := afero.NewMemMapFs() diff --git a/internal/stop/stop_test.go b/internal/stop/stop_test.go index 3c65f026ac..7f236e3be7 100644 --- a/internal/stop/stop_test.go +++ b/internal/stop/stop_test.go @@ -100,6 +100,7 @@ func TestStopServices(t *testing.T) { t.Run("removes data volumes", func(t *testing.T) { utils.DbId = "test-db" + utils.ConfigId = "test-config-db" utils.StorageId = "test-storage" // Setup mock docker require.NoError(t, apitest.MockDocker(utils.Docker)) @@ -112,6 +113,9 @@ func TestStopServices(t *testing.T) { Post("/v" + utils.Docker.ClientVersion() + "/containers/prune"). Reply(http.StatusOK). JSON(types.ContainersPruneReport{}) + gock.New(utils.Docker.DaemonHost()). + Delete("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.ConfigId). + Reply(http.StatusOK) gock.New(utils.Docker.DaemonHost()). Delete("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.DbId). Reply(http.StatusOK) From b64a97899ac6c10f2418b51d0bc86b8e6e2c9380 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Thu, 15 Jun 2023 14:42:16 +0800 Subject: [PATCH 3/3] chore: cleanup functions cache volume on stop --- internal/stop/stop.go | 4 +++- internal/stop/stop_test.go | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/stop/stop.go b/internal/stop/stop.go index 3cb178ab0d..01905739f6 100644 --- a/internal/stop/stop.go +++ b/internal/stop/stop.go @@ -52,10 +52,12 @@ func stop(ctx context.Context, backup bool) error { // Remove named volumes if backup { fmt.Fprintln(os.Stderr, "Postgres database saved to volume:", utils.DbId) + fmt.Fprintln(os.Stderr, "Postgres config saved to volume:", utils.ConfigId) fmt.Fprintln(os.Stderr, "Storage directory saved to volume:", utils.StorageId) + fmt.Fprintln(os.Stderr, "Functions cache saved to volume:", utils.DenoRelayId) } else { // TODO: label named volumes to use VolumesPrune for branch support - volumes := []string{utils.ConfigId, utils.DbId, utils.StorageId} + volumes := []string{utils.ConfigId, utils.DbId, utils.StorageId, utils.DenoRelayId} utils.WaitAll(volumes, func(name string) { if err := utils.Docker.VolumeRemove(ctx, name, true); err != nil { fmt.Fprintln(os.Stderr, "failed to remove volume:", name, err) diff --git a/internal/stop/stop_test.go b/internal/stop/stop_test.go index 7f236e3be7..1ad1e828f9 100644 --- a/internal/stop/stop_test.go +++ b/internal/stop/stop_test.go @@ -100,8 +100,9 @@ func TestStopServices(t *testing.T) { t.Run("removes data volumes", func(t *testing.T) { utils.DbId = "test-db" - utils.ConfigId = "test-config-db" + utils.ConfigId = "test-config" utils.StorageId = "test-storage" + utils.DenoRelayId = "test-functions" // Setup mock docker require.NoError(t, apitest.MockDocker(utils.Docker)) defer gock.OffAll() @@ -122,6 +123,9 @@ func TestStopServices(t *testing.T) { gock.New(utils.Docker.DaemonHost()). Delete("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.StorageId). Reply(http.StatusNotFound) + gock.New(utils.Docker.DaemonHost()). + Delete("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.DenoRelayId). + Reply(http.StatusNotFound) gock.New(utils.Docker.DaemonHost()). Post("/v" + utils.Docker.ClientVersion() + "/networks/prune"). Reply(http.StatusOK).