mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 13:01:51 +08:00
feat(deploy,gateway): add dual-edition deployment/migration/rollback and TUN route reconciliation
- Add standalone edition (`Dockerfile.standalone`, `docker-compose.standalone.yml`) alongside sandbox edition and publish both in `.github/workflows/release.yml`. - Implement `scripts/deploy-lib.sh`, `install.sh`, `update.sh`, and `scripts/artex-sandbox-firewall.sh --cleanup` with edition detection, legacy standalone -> sandbox migration (symlink-safe workspace permissions), automatic snapshots with pinned `artex-rollback/*` images + PG dump, auto/manual cross-edition rollback, and post-rollback upstream unpinning. - Update `ensureWritableDir` in `internal/sandbox/manager.go` to safely migrate nested root-owned workspace files without following symlinks. - Expose `deploy_edition` in `/api/update/check` and update `UpdateCard` UI/i18n warnings for sandbox vs standalone in-app update/rollback. - Reconcile `artex-gateway` TUN policy routing (`priority 218`, `raw PREROUTING`, `nat POSTROUTING`, `DOCKER-USER`) every 15s to self-heal after host network rule flushes or bridge changes. - Add unit and shell tests (`scripts/deploy_test.sh`, `cmd/artex-gateway/tun_linux_test.go`, `internal/sandbox/sandbox_test.go`, `server/update_test.go`) and update `README.md` / `.env.example`.
This commit is contained in:
1 parent
d786de90af
commit
07309e4530
23 files changed
+2107
-144
No files matched your search
@@ -2,11 +2,14 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Autumn-27/artex/internal/sandbox"
|
||||
"github.com/Autumn-27/artex/selfupdate"
|
||||
)
|
||||
|
||||
@@ -196,3 +199,65 @@ func TestUpdateSettingsValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateCheckReportsDeployEdition(t *testing.T) {
|
||||
origMgr := sandbox.Default()
|
||||
origFetch := relCache.fetch
|
||||
t.Cleanup(func() {
|
||||
sandbox.SetDefault(origMgr)
|
||||
relCache.mu.Lock()
|
||||
relCache.fetch = origFetch
|
||||
relCache.at = time.Time{}
|
||||
relCache.mu.Unlock()
|
||||
})
|
||||
relCache.mu.Lock()
|
||||
relCache.fetch = func(context.Context, *http.Client) (*selfupdate.Release, error) {
|
||||
return &selfupdate.Release{TagName: "v0.3.33"}, nil
|
||||
}
|
||||
relCache.at = time.Time{}
|
||||
relCache.mu.Unlock()
|
||||
|
||||
s := &Server{m: &Manager{}}
|
||||
|
||||
// Local/standalone mode
|
||||
localMgr, err := sandbox.New(sandbox.Config{Mode: sandbox.ModeLocal, DataDir: t.TempDir()})
|
||||
if err != nil {
|
||||
t.Fatalf("sandbox.New local: %v", err)
|
||||
}
|
||||
sandbox.SetDefault(localMgr)
|
||||
rec := httptest.NewRecorder()
|
||||
s.updateCheck(rec, httptest.NewRequest(http.MethodGet, "/api/update/check", nil))
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("updateCheck local status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var resp map[string]any
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatalf("decode local resp: %v", err)
|
||||
}
|
||||
if resp["deploy_edition"] != "standalone" {
|
||||
t.Fatalf("expected deploy_edition=standalone, got %v", resp["deploy_edition"])
|
||||
}
|
||||
|
||||
// Docker sandbox mode
|
||||
dockerMgr, err := sandbox.New(sandbox.Config{
|
||||
Mode: sandbox.ModeDocker,
|
||||
DockerHost: "http://127.0.0.1:2375",
|
||||
DataDir: t.TempDir(),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("sandbox.New docker: %v", err)
|
||||
}
|
||||
sandbox.SetDefault(dockerMgr)
|
||||
rec2 := httptest.NewRecorder()
|
||||
s.updateCheck(rec2, httptest.NewRequest(http.MethodGet, "/api/update/check", nil))
|
||||
if rec2.Code != http.StatusOK {
|
||||
t.Fatalf("updateCheck docker status=%d body=%s", rec2.Code, rec2.Body.String())
|
||||
}
|
||||
var resp2 map[string]any
|
||||
if err := json.Unmarshal(rec2.Body.Bytes(), &resp2); err != nil {
|
||||
t.Fatalf("decode docker resp: %v", err)
|
||||
}
|
||||
if resp2["deploy_edition"] != "sandbox" {
|
||||
t.Fatalf("expected deploy_edition=sandbox, got %v", resp2["deploy_edition"])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user