fix(updater): setar docker_config e recriar container com configuração

This commit is contained in:
2026-08-26 16:52:06 -03:00
parent 5ed2d33124
commit fe70100959
2 changed files with 52 additions and 2 deletions
+20 -2
View File
@@ -182,6 +182,16 @@ func shellQuoteArgs(args []string) string {
// app-cliente image.
const updaterPollIntervalSeconds = 300
// buildRecreateCmd takes the app-cliente run argv (built with the wizard-time port) and
// swaps the baked-in port for a `$PORT` shell reference, so the poll script's recreate
// step uses whatever port it reads live from the container (see the PORT= line in
// RunUpdaterDockerContainer) instead of always replaying the port typed into the wizard.
func buildRecreateCmd(recreateArgs []string, wizardPort string) string {
wizardPortArg := shellQuote(fmt.Sprintf("%s:%d", wizardPort, containerAppPort))
livePortArg := fmt.Sprintf(`"$PORT:%d"`, containerAppPort)
return strings.Replace("docker "+shellQuoteArgs(recreateArgs), wizardPortArg, livePortArg, 1)
}
// RunUpdaterDockerContainer starts a tiny self-contained auto-updater for the
// app-dono-cliente container: no third-party updater project, just the official
// `docker:cli` image running a poll loop (docker pull, compare image IDs, recreate on
@@ -192,6 +202,11 @@ const updaterPollIntervalSeconds = 300
// It mounts the docker socket (to pull/recreate) and the host's docker config.json
// (written by the StepDockerLogin `docker login`) so `docker pull` can authenticate
// against the private registry.
//
// The recreate command reuses appClienteRunArgs' host port only as a fallback: at
// recreate time the script re-reads the live container's actual published port via
// `docker inspect`, so a port changed by hand after install survives an auto-update
// instead of being silently reverted to whatever was typed into the wizard.
func RunUpdaterDockerContainer(appImage, appContainerName, configPath, configDestinationPath string, cv ConfigValues) error {
updaterName := "app-dono-updater"
@@ -211,7 +226,7 @@ func RunUpdaterDockerContainer(appImage, appContainerName, configPath, configDes
if err != nil {
return err
}
recreateCmd := "docker " + shellQuoteArgs(recreateArgs)
recreateCmd := buildRecreateCmd(recreateArgs, cv.Server["port"])
script := fmt.Sprintf(`set -e
IMAGE=%s
@@ -221,13 +236,15 @@ while true; do
CURRENT=$(docker inspect --format '{{.Image}}' "$NAME" 2>/dev/null || true)
LATEST=$(docker inspect --format '{{.Id}}' "$IMAGE" 2>/dev/null || true)
if [ -n "$LATEST" ] && [ "$CURRENT" != "$LATEST" ]; then
PORT=$(docker inspect --format '{{(index (index .NetworkSettings.Ports "%d/tcp") 0).HostPort}}' "$NAME" 2>/dev/null || true)
if [ -z "$PORT" ]; then PORT=%s; fi
docker stop "$NAME" >/dev/null 2>&1 || true
docker rm "$NAME" >/dev/null 2>&1 || true
%s
fi
sleep %d
done
`, shellQuote(appImage), shellQuote(appContainerName), recreateCmd, updaterPollIntervalSeconds)
`, shellQuote(appImage), shellQuote(appContainerName), containerAppPort, shellQuote(cv.Server["port"]), recreateCmd, updaterPollIntervalSeconds)
args := []string{
"run", "-d",
@@ -235,6 +252,7 @@ done
"--restart", "unless-stopped",
"-v", "/var/run/docker.sock:/var/run/docker.sock",
"-v", fmt.Sprintf("%s:/config.json", dockerConfigPath),
"-e", "DOCKER_CONFIG=/",
"--log-opt", "max-size=5m",
"--log-opt", "max-file=1",
"--entrypoint", "sh",