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
@@ -6,8 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -120,21 +118,13 @@ func TestControlStepUpAndAuditE2E(t *testing.T) {
|
||||
pbSrv := httptest.NewServer(fake.handler(t))
|
||||
defer pbSrv.Close()
|
||||
|
||||
// Enable the anker-solix plugin globally via a plugins.json.
|
||||
dir := t.TempDir()
|
||||
pluginsFile := filepath.Join(dir, "plugins.json")
|
||||
if err := os.WriteFile(pluginsFile, []byte(`{"anker-solix":{"enabled":true}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s := New(config.Config{
|
||||
UsersCollection: "users",
|
||||
PluginsFile: pluginsFile,
|
||||
OCPPRequireTLS: false, // httptest is plaintext; TLS enforcement covered elsewhere
|
||||
}, pb.New(pbSrv.URL, "admin@test.local", "pw"))
|
||||
// The global layer normally lives in PocketBase; point it at the file above
|
||||
// so this test does not have to stand up an app_settings collection too.
|
||||
s.pluginStore = plugins.NewFileStore(pluginsFile)
|
||||
// The global layer normally lives in PocketBase; seed it in memory so this
|
||||
// test does not have to stand up an app_settings collection too.
|
||||
s.pluginStore = plugins.NewMemoryStore([]byte(`{"anker-solix":{"enabled":true}}`))
|
||||
s.plugins = plugins.NewManager(s.pluginStore)
|
||||
if err := s.plugins.Load(context.Background()); err != nil {
|
||||
t.Fatalf("load plugins: %v", err)
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
// Resolution is a cascade: the top layer wins, and a lower layer only fills a
|
||||
// field the layers above left blank.
|
||||
//
|
||||
// - global (L1): the plugin's config in plugins.json, set in the API Server
|
||||
// panel by a superadmin. This is the top of the cascade for everyone.
|
||||
// - global (L1): pluginSettings on the app_settings singleton, set in the API
|
||||
// Server panel by a superadmin. This is the top of the cascade for everyone.
|
||||
// - org (L2): pluginSettings.toyota on the caller's organization record,
|
||||
// editable by an org admin. Present only for users who belong to an org.
|
||||
// - user (L3): pluginSettings.toyota on the caller's own user record.
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
// organization, an org admin) can impose settings from above. See integrations.go
|
||||
// for the full rationale; only the fields differ.
|
||||
//
|
||||
// - global (L1): the plugin's config in plugins.json, set in the API Server
|
||||
// panel by a superadmin — the top of the cascade for everyone.
|
||||
// - global (L1): pluginSettings on the app_settings singleton, set in the API
|
||||
// Server panel by a superadmin — the top of the cascade for everyone.
|
||||
// - org (L2): pluginSettings.ankerSolix on the caller's organization record.
|
||||
// - user (L3): pluginSettings.ankerSolix on the caller's own user record.
|
||||
//
|
||||
|
||||
@@ -93,8 +93,7 @@ func writeTestJSON(w http.ResponseWriter, status int, v any) {
|
||||
func newSchemaTestServer(t *testing.T, f *fakeSchemaPB) *Server {
|
||||
t.Helper()
|
||||
pbSrv := f.server(t)
|
||||
// PluginsFile empty: no legacy import in play here.
|
||||
return New(config.Config{UsersCollection: "users", PluginsFile: ""},
|
||||
return New(config.Config{UsersCollection: "users"},
|
||||
pb.New(pbSrv.URL, "admin@test.local", "pw"))
|
||||
}
|
||||
|
||||
|
||||
@@ -159,12 +159,10 @@ type Server struct {
|
||||
pb *pb.Client
|
||||
plugins *plugins.Manager
|
||||
|
||||
// pluginStore is the Manager's backing store, kept here so the one-time
|
||||
// import of a legacy plugins.json can address it directly. legacyPlugins is
|
||||
// the path that import reads; pluginsStop ends the background load retry.
|
||||
pluginStore plugins.Store
|
||||
legacyPlugins string
|
||||
pluginsStop context.CancelFunc
|
||||
// pluginStore is the Manager's backing store; pluginsStop ends the
|
||||
// background load retry started by StartPlugins.
|
||||
pluginStore plugins.Store
|
||||
pluginsStop context.CancelFunc
|
||||
|
||||
// ocpp is the OCPP 1.6J Central System that Anker Solix chargers connect to
|
||||
// when their owner picks a control mode of own/proxy (see internal/ocpp and
|
||||
@@ -181,14 +179,13 @@ func New(cfg config.Config, client *pb.Client) *Server {
|
||||
// and user (L3) layers, rather than in a file beside the binary.
|
||||
store := plugins.NewPocketBaseStore(client, colAppSettings)
|
||||
return &Server{
|
||||
cfg: cfg,
|
||||
pb: client,
|
||||
pluginStore: store,
|
||||
legacyPlugins: cfg.PluginsFile,
|
||||
plugins: plugins.NewManager(store),
|
||||
ocpp: ocpp.NewCSMS(func(f string, a ...any) { log.Printf("ocpp: "+f, a...) }),
|
||||
control: newControlIndex(),
|
||||
ctlRL: newRateLimiter(30, time.Minute), // 30 control commands / min / charger
|
||||
cfg: cfg,
|
||||
pb: client,
|
||||
pluginStore: store,
|
||||
plugins: plugins.NewManager(store),
|
||||
ocpp: ocpp.NewCSMS(func(f string, a ...any) { log.Printf("ocpp: "+f, a...) }),
|
||||
control: newControlIndex(),
|
||||
ctlRL: newRateLimiter(30, time.Minute), // 30 control commands / min / charger
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +231,7 @@ func (s *Server) StartPlugins() error {
|
||||
// create just that one collection — not a full schema reconcile, which an
|
||||
// operator who turned the bootstrap off has not asked for — and read again.
|
||||
func (s *Server) loadPlugins(ctx context.Context) error {
|
||||
err := s.readPlugins(ctx)
|
||||
err := s.plugins.Load(ctx)
|
||||
if err == nil || !plugins.IsMissingCollection(err) {
|
||||
return err
|
||||
}
|
||||
@@ -245,20 +242,6 @@ func (s *Server) loadPlugins(ctx context.Context) error {
|
||||
return err // report the original problem, not the repair's
|
||||
}
|
||||
log.Printf("plugins: created %s", colAppSettings)
|
||||
return s.readPlugins(ctx)
|
||||
}
|
||||
|
||||
// readPlugins imports a pre-PocketBase plugins.json if one is still lying around
|
||||
// and the database holds no settings yet, then reads the settings.
|
||||
func (s *Server) readPlugins(ctx context.Context) error {
|
||||
switch migrated, err := plugins.MigrateLegacyFile(ctx, s.pluginStore, s.legacyPlugins); {
|
||||
case err != nil:
|
||||
// Not fatal: the read below reports the real problem if there is one.
|
||||
log.Printf("plugins: legacy import skipped: %v", err)
|
||||
case migrated:
|
||||
log.Printf("plugins: imported %s into PocketBase; renamed it to %s.migrated",
|
||||
s.legacyPlugins, s.legacyPlugins)
|
||||
}
|
||||
return s.plugins.Load(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -456,15 +454,11 @@ func newProviderTestServer(t *testing.T, fake *fakeProviderPB) *httptest.Server
|
||||
pbSrv := httptest.NewServer(fake.handler())
|
||||
t.Cleanup(pbSrv.Close)
|
||||
|
||||
pluginsFile := filepath.Join(t.TempDir(), "plugins.json")
|
||||
if err := os.WriteFile(pluginsFile, []byte(`{"toyota":{"enabled":false}}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New(config.Config{UsersCollection: "users", PluginsFile: pluginsFile},
|
||||
s := New(config.Config{UsersCollection: "users"},
|
||||
pb.New(pbSrv.URL, "admin@test.local", "pw"))
|
||||
// The global layer normally lives in PocketBase; point it at the file above
|
||||
// so this test does not have to stand up an app_settings collection too.
|
||||
s.pluginStore = plugins.NewFileStore(pluginsFile)
|
||||
// The global layer normally lives in PocketBase; seed it in memory so this
|
||||
// test does not have to stand up an app_settings collection too.
|
||||
s.pluginStore = plugins.NewMemoryStore([]byte(`{"toyota":{"enabled":false}}`))
|
||||
s.plugins = plugins.NewManager(s.pluginStore)
|
||||
if err := s.plugins.Load(context.Background()); err != nil {
|
||||
t.Fatalf("load plugins: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user