Plugins: drop the plugins.json migration, and the volume it needed
The project has no public installs, so there is nothing to migrate from. MigrateLegacyFile, the file-backed Store it read through, PLUGINS_FILE and the legacy path threaded through the Server all go. What is left is one store, PocketBase, and a plugins package that touches no filesystem at all. That was the last thing keeping api_data alive, so the volume goes too. All four compose files now declare exactly one volume, pb_data, and the standalone API Server compose declares none - it talks to an external PocketBase and has nothing of its own to keep. Backing up the stack is backing up one path again. Both images get simpler for it. The API Server image loses VOLUME /data and the su-exec entrypoint that existed only to fix a mounted volume's ownership, so it goes back to a plain USER app; its working directory is now /app and holds nothing. The AIO image loses its second volume and chowns only /pb/pb_data. One consequence worth stating plainly, because it is a small regression rather than a no-op. The panel's Settings -> PocketBase and Settings -> Web App screens write .env in the working directory, which is now ephemeral. In the multi-container stack that changes nothing: compose sets all five of those keys as container environment, and loadDotEnv only applies a key that is not already set, so the file could never win a restart there anyway. In the AIO image it did win for POCKETBASE_ADMIN_EMAIL/_PASSWORD, which are not in that container's environment - so a service account fixed from the panel now lasts only until the container is recreated. Both READMEs say so. Moving those two screens into the app_settings singleton would close it properly; the PocketBase URL and credentials cannot follow, since they are how the database is reached in the first place. go build, go vet and go test ./... pass; the compose files parse and each resolves to a single pb_data volume. Not verified: no Docker CLI here, so neither image was built. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
660af5736a
commit
ee4ac441be
@@ -4,9 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -194,144 +191,3 @@ func TestExternalPluginRoundTrip(t *testing.T) {
|
||||
t.Fatal("removed external plugin came back")
|
||||
}
|
||||
}
|
||||
|
||||
// --- file store -------------------------------------------------------------
|
||||
|
||||
// The file store writes via temp file + rename, leaving nothing behind.
|
||||
func TestFileStoreLeavesNoTempFiles(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "plugins.json")
|
||||
m := loadedManager(t, NewFileStore(path))
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
if _, err := m.Upsert(context.Background(), "test-a", true, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
if e.Name() != "plugins.json" {
|
||||
t.Fatalf("unexpected leftover file: %s", e.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An unwritable directory is a persist failure, not a silent success.
|
||||
func TestFileStoreUnwritableIsAPersistFailure(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "missing-dir", "plugins.json")
|
||||
m := loadedManager(t, NewFileStore(path))
|
||||
|
||||
if _, err := m.Upsert(context.Background(), "test-a", true, nil); !IsPersist(err) {
|
||||
t.Fatalf("expected persist failure, got %v", err)
|
||||
}
|
||||
if v, _ := m.Get("test-a"); v.Enabled {
|
||||
t.Fatal("plugin reported enabled although the save never landed")
|
||||
}
|
||||
}
|
||||
|
||||
// --- legacy import ----------------------------------------------------------
|
||||
|
||||
func TestMigrateLegacyFileImportsOnceThenRenames(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "plugins.json")
|
||||
legacy := `{"test-a":{"enabled":true,"config":{"user":"me"}}}`
|
||||
if err := os.WriteFile(path, []byte(legacy), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := &memoryStore{}
|
||||
ctx := context.Background()
|
||||
|
||||
migrated, err := MigrateLegacyFile(ctx, store, path)
|
||||
if err != nil || !migrated {
|
||||
t.Fatalf("first import: migrated=%v err=%v", migrated, err)
|
||||
}
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
t.Fatal("the legacy file should have been renamed away")
|
||||
}
|
||||
if _, err := os.Stat(path + ".migrated"); err != nil {
|
||||
t.Fatalf("renamed file missing: %v", err)
|
||||
}
|
||||
|
||||
m := loadedManager(t, store)
|
||||
if v, _ := m.Get("test-a"); !v.Enabled || v.Config["user"] != "me" {
|
||||
t.Fatalf("imported settings wrong: enabled=%v config=%v", v.Enabled, v.Config)
|
||||
}
|
||||
|
||||
// A second pass must not re-import (and there is nothing left to import).
|
||||
if migrated, err := MigrateLegacyFile(ctx, store, path); migrated || err != nil {
|
||||
t.Fatalf("second import: migrated=%v err=%v", migrated, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A store that already holds settings must never be seeded from a stale file.
|
||||
func TestMigrateLegacyFileSkipsWhenStoreHasSettings(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "plugins.json")
|
||||
if err := os.WriteFile(path, []byte(`{"test-a":{"enabled":true}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := seeded(`{"test-b":{"enabled":true}}`)
|
||||
|
||||
migrated, err := MigrateLegacyFile(context.Background(), store, path)
|
||||
if err != nil || migrated {
|
||||
t.Fatalf("migrated=%v err=%v — a populated store must not be overwritten", migrated, err)
|
||||
}
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
t.Fatal("the file should be left alone when nothing was imported")
|
||||
}
|
||||
}
|
||||
|
||||
// An unreadable store must not trigger an import either: seeding on a failed
|
||||
// read would overwrite live settings with a stale file.
|
||||
func TestMigrateLegacyFileSkipsWhenStoreUnreachable(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "plugins.json")
|
||||
if err := os.WriteFile(path, []byte(`{"test-a":{"enabled":true}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := &memoryStore{failLoad: errNotReady}
|
||||
|
||||
if migrated, err := MigrateLegacyFile(context.Background(), store, path); migrated || err == nil {
|
||||
t.Fatalf("migrated=%v err=%v — must refuse while the store is unreachable", migrated, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A corrupt legacy file is reported and left on disk, not written into the DB.
|
||||
func TestMigrateLegacyFileRejectsCorruptFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "plugins.json")
|
||||
if err := os.WriteFile(path, []byte(`{"test-a":{"enabled":true}}junk`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := &memoryStore{}
|
||||
|
||||
migrated, err := MigrateLegacyFile(context.Background(), store, path)
|
||||
if migrated || err == nil {
|
||||
t.Fatalf("migrated=%v err=%v — a corrupt file must not be imported", migrated, err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "not imported") {
|
||||
t.Fatalf("error should say nothing was imported, got: %v", err)
|
||||
}
|
||||
if store.data != nil {
|
||||
t.Fatal("nothing should have been written")
|
||||
}
|
||||
if _, statErr := os.Stat(path); statErr != nil {
|
||||
t.Fatal("the corrupt file should be left on disk for inspection")
|
||||
}
|
||||
}
|
||||
|
||||
// A fresh install has no file and no settings; that is not an error.
|
||||
func TestMigrateLegacyFileNoFile(t *testing.T) {
|
||||
store := &memoryStore{}
|
||||
path := filepath.Join(t.TempDir(), "plugins.json")
|
||||
if migrated, err := MigrateLegacyFile(context.Background(), store, path); migrated || err != nil {
|
||||
t.Fatalf("migrated=%v err=%v", migrated, err)
|
||||
}
|
||||
if migrated, err := MigrateLegacyFile(context.Background(), store, ""); migrated || err != nil {
|
||||
t.Fatalf("empty path: migrated=%v err=%v", migrated, err)
|
||||
}
|
||||
}
|
||||
|
||||
// writeTestFile is a small helper shared with store_pb_test.go.
|
||||
func writeTestFile(path, content string) error {
|
||||
return os.WriteFile(path, []byte(content), 0o600)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user