Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions agent/app/service/agents_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/1Panel-dev/1Panel/agent/global"
"github.com/1Panel-dev/1Panel/agent/utils/common"
"github.com/1Panel-dev/1Panel/agent/utils/files"
openclawutil "github.com/1Panel-dev/1Panel/agent/utils/openclaw"
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -388,9 +387,6 @@ func migrateOpenclawHTTPSUpgradeWithSystemIP(install *model.AppInstall, fromVers
return nil
}
migrateOpenclawInstallPorts(install)
if err := openclawutil.WriteCatchAllCaddyfile(install.GetPath()); err != nil {
return err
}
configPath := path.Join(install.GetPath(), "data", "conf", "openclaw.json")
var allowedOrigins []string
if conf, err := readOpenclawConfig(configPath); err == nil {
Expand All @@ -417,6 +413,35 @@ func migrateOpenclawHTTPSUpgradeWithSystemIP(install *model.AppInstall, fromVers
return migrateOpenclawInstallEnv(install, allowedOrigins)
}

func shouldRewriteOpenclawBundledCaddyfileOnUpgrade(install *model.AppInstall, fromVersion, toVersion string) bool {
if install == nil || install.App.Key != constant.AppOpenclaw {
return false
}
if strings.TrimSpace(fromVersion) != openclawHTTPSVersion {
return false
}
return common.CompareVersion(strings.TrimSpace(toVersion), openclawHTTPSVersion)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat latest tags as eligible for Caddyfile rewrite

This gate uses common.CompareVersion on toVersion, but that comparator returns false for non-numeric versions like latest. The codebase already treats latest/non-numeric app versions as valid upgrade targets (for example in OpenClaw HTTPS version checks), so an upgrade from 2026.3.13 to latest will skip the Caddyfile rewrite and keep the stale file this change is trying to replace.

Useful? React with 👍 / 👎.

}

func rewriteOpenclawBundledCaddyfileOnUpgrade(install *model.AppInstall, fromVersion, toVersion, sourceAppDir string) error {
if !shouldRewriteOpenclawBundledCaddyfileOnUpgrade(install, fromVersion, toVersion) {
return nil
}
return copyOpenclawBundledCaddyfile(sourceAppDir, install.GetPath())
}

func copyOpenclawBundledCaddyfile(sourceAppDir, installPath string) error {
sourcePath := path.Join(sourceAppDir, "data", "caddy", "Caddyfile")
targetDir := path.Join(installPath, "data", "caddy")
fileOp := files.NewFileOp()
if !fileOp.Stat(targetDir) {
if err := fileOp.CreateDir(targetDir, constant.DirPerm); err != nil {
return err
}
}
return fileOp.CopyFile(sourcePath, targetDir)
}

func migrateOpenclawInstallPorts(install *model.AppInstall) {
if install == nil {
return
Expand Down
3 changes: 3 additions & 0 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,9 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
if err = migrateOpenclawHTTPSUpgrade(&install, oldVersion, detail.Version); err != nil {
return err
}
if err = rewriteOpenclawBundledCaddyfileOnUpgrade(&install, oldVersion, detail.Version, detailDir); err != nil {
return err
}
if req.DockerCompose == "" {
newCompose, err = getUpgradeCompose(install, detail)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion agent/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func InitAgentDB() {
migrations.AddAgentTypeForAgents,
migrations.NormalizeAgentAccountVerifiedStatus,
migrations.NormalizeOllamaAccountAPIType,
migrations.RewriteOpenclawBundledCaddyfile,
migrations.InitAgentAccountModelPool,
migrations.AddHostTable,
migrations.AddAITerminalSettings,
Expand Down
7 changes: 0 additions & 7 deletions agent/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,13 +989,6 @@ var NormalizeOllamaAccountAPIType = &gormigrate.Migration{
},
}

var RewriteOpenclawBundledCaddyfile = &gormigrate.Migration{
ID: "20260318-rewrite-openclaw-bundled-caddyfile",
Migrate: func(tx *gorm.DB) error {
return migrationutils.RewriteOpenclawBundledCaddyfile(tx)
},
}

var InitAgentAccountModelPool = &gormigrate.Migration{
ID: "20260319-init-agent-account-model-pool",
Migrate: func(tx *gorm.DB) error {
Expand Down
42 changes: 0 additions & 42 deletions agent/init/migration/migrations/utils/openclaw_caddyfile.go

This file was deleted.

47 changes: 0 additions & 47 deletions agent/utils/openclaw/caddyfile.go

This file was deleted.

Loading