refactor: extract ProxyProvider interface with None and NPM implementations

Replace direct npm.Client usage throughout the codebase with the
proxy.Provider interface, enabling pluggable proxy backends. The
deployer, API layer, and proxy manager now use provider-agnostic
route management (ConfigureRoute/DeleteRoute) instead of NPM-specific
API calls. Adds ProxyRouteID (string) to Instance model and
ProxyProvider setting to Settings, with SQLite migrations for
backward compatibility.
This commit is contained in:
2026-04-04 19:39:08 +03:00
parent 6667abf03c
commit 7d6719da12
17 changed files with 365 additions and 249 deletions
+8 -18
View File
@@ -7,9 +7,9 @@ import (
)
// rollback cleans up a failed deployment by removing the container,
// deleting the NPM proxy host, and updating the instance status.
// deleting the proxy route, and updating the instance status.
// Errors during rollback are logged but do not prevent other cleanup steps.
func (d *Deployer) rollback(ctx context.Context, deployID string, containerID string, npmProxyID int, instanceID string) {
func (d *Deployer) rollback(ctx context.Context, deployID string, containerID string, proxyRouteID string, instanceID string) {
d.logDeploy(deployID, "Rolling back failed deployment", "warn")
// Remove the container if it was created.
@@ -22,23 +22,13 @@ func (d *Deployer) rollback(ctx context.Context, deployID string, containerID st
}
}
// Delete the NPM proxy host if it was created.
if npmProxyID > 0 {
settings, err := d.store.GetSettings()
if err != nil {
slog.Warn("rollback: get settings for npm auth", "error", err)
d.logDeploy(deployID, fmt.Sprintf("Rollback: failed to get settings for proxy cleanup: %v", err), "error")
} else if npmPassword, err := d.decryptNpmPassword(settings.NpmPassword); err != nil {
slog.Warn("rollback: decrypt npm password", "error", err)
d.logDeploy(deployID, "Rollback: failed to decrypt NPM password for proxy cleanup", "error")
} else if err := d.npm.Authenticate(ctx, settings.NpmEmail, npmPassword); err != nil {
slog.Warn("rollback: authenticate npm", "error", err)
d.logDeploy(deployID, "Rollback: failed to authenticate NPM for proxy cleanup", "error")
} else if err := d.npm.DeleteProxyHost(ctx, npmProxyID); err != nil {
slog.Warn("rollback: delete proxy host", "proxy_id", npmProxyID, "error", err)
d.logDeploy(deployID, fmt.Sprintf("Rollback: failed to delete proxy host: %v", err), "error")
// Delete the proxy route if it was created.
if proxyRouteID != "" {
if err := d.proxy.DeleteRoute(ctx, proxyRouteID); err != nil {
slog.Warn("rollback: delete proxy route", "route_id", proxyRouteID, "error", err)
d.logDeploy(deployID, fmt.Sprintf("Rollback: failed to delete proxy route: %v", err), "error")
} else {
d.logDeploy(deployID, "Rollback: proxy host deleted", "info")
d.logDeploy(deployID, "Rollback: proxy route deleted", "info")
}
}