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:
ji ruo committed 2026-12-02 13:31:05 +08:00
1 parent d786de90af
commit 07309e4530
23 files changed
+2107 -144

No files matched your search

+14 -8
View File
@@ -11,6 +11,7 @@ import (
"sync"
"time"
"github.com/Autumn-27/artex/internal/sandbox"
"github.com/Autumn-27/artex/selfupdate"
)
@@ -214,16 +215,21 @@ func (s *Server) updateCheck(w http.ResponseWriter, r *http.Request) {
if selfupdate.InDocker() {
mode = "docker"
}
deployEdition := "standalone"
if mgr := sandbox.Default(); mgr != nil && mgr.Enabled() {
deployEdition = "sandbox"
}
boot := bootUpdateState()
out := map[string]any{
"current": current,
"mode": mode,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"has_backup": selfupdate.HasBackup(),
"repo": selfupdate.Repo,
"boot_notice": boot.Detail,
"rolled_back": boot.RolledBack,
"current": current,
"mode": mode,
"deploy_edition": deployEdition,
"os": runtime.GOOS,
"arch": runtime.GOARCH,
"has_backup": selfupdate.HasBackup(),
"repo": selfupdate.Repo,
"boot_notice": boot.Detail,
"rolled_back": boot.RolledBack,
}
// 顶栏提示走缓存(默认);用户点"检查更新"时带 force=1 强制回源。
+3
View File
@@ -25,6 +25,9 @@ func (cfg *updateSettings) validate() error {
func (s *Server) loadUpdateSettings() (updateSettings, error) {
cfg := updateSettings{}
if s.m == nil || s.m.pg == nil {
return cfg, nil
}
raw, ok, err := s.m.pg.GetSetting(updateSettingsKey)
if err != nil {
return cfg, fmt.Errorf("读取更新网络设置失败: %w", err)
+65
View File
@@ -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"])
}
}