fix(edgestack): unify gitops update flow [BE-12184] (#1110)

develop
Oscar Zhou 2025-11-01 20:20:51 +13:00 committed by GitHub
parent 0ff39f9a61
commit b70321a0aa
5 changed files with 30 additions and 18 deletions

View File

@ -60,9 +60,9 @@ type (
// EnvVars is a list of environment variables to inject into the stack
EnvVars []portainer.Pair
// Used only for EE async edge agent
// ReadyRePullImage is a flag to indicate whether the auto update is trigger to re-pull image
ReadyRePullImage bool
// ForceUpdate is a flag indicating if the agent must force the update of the stack.
// Used only for EE
ForceUpdate bool
DeployerOptionsPayload DeployerOptionsPayload
}
@ -77,6 +77,14 @@ type (
// This flag drives `docker compose down --volumes` option
// Used only for EE
RemoveVolumes bool
// ForceRecreate is a flag indicating if the agent must force the redeployment of the stack.
// This field is only used when the Force Redeployment is triggered.
// Once the stack is redeployed, this field will be reset to false.
// For standard edge agent, this field is used in agent side
// For async edge agent, this field is used in both agent side and server side.
// This flag drives `docker compose up --force-recreate` option
ForceRecreate bool
}
// RegistryCredentials holds the credentials for a Docker registry.

View File

@ -13,7 +13,7 @@ import (
)
// UpdateGitObject updates a git object based on its config
func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *gittypes.RepoConfig, forceUpdate, enableVersionFolder bool, projectPath string) (bool, string, error) {
func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *gittypes.RepoConfig, enableVersionFolder bool, projectPath string) (bool, string, error) {
if gitConfig == nil {
return false, "", nil
}
@ -43,7 +43,7 @@ func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *g
hashChanged := !strings.EqualFold(newHash, gitConfig.ConfigHash)
if !hashChanged && !forceUpdate {
if !hashChanged {
log.Debug().
Str("hash", newHash).
Str("url", gitConfig.URL).

View File

@ -354,6 +354,14 @@ type (
Status []EdgeStackDeploymentStatus
// EE only feature
DeploymentInfo StackDeploymentInfo
// RePullImage is a flag to indicate whether the auto update is trigger to re-pull image
RePullImage bool `json:"RePullImage,omitempty"`
// ForceRedeploy is a flag to indicate whether the force redeployment is set for the current
// deployment of the edge stack. The redeployment could be triggered by GitOps Update or manually by user.
ForceRedeploy bool `json:"ForceRedeploy,omitempty"`
// Deprecated(2.36): use ForceRedeploy and RePullImage instead for cleaner
// responsibility, but keep it for backward compatibility. To remove in future versions (2.44+)
// ReadyRePullImage is a flag to indicate whether the auto update is trigger to re-pull image
ReadyRePullImage bool `json:"ReadyRePullImage,omitempty"`
}

View File

@ -121,7 +121,7 @@ func redeployWhenChangedSecondStage(
var gitCommitChangedOrForceUpdate bool
if !stack.FromAppTemplate {
updated, newHash, err := update.UpdateGitObject(gitService, fmt.Sprintf("stack:%d", stack.ID), stack.GitConfig, false, false, stack.ProjectPath)
updated, newHash, err := update.UpdateGitObject(gitService, fmt.Sprintf("stack:%d", stack.ID), stack.GitConfig, false, stack.ProjectPath)
if err != nil {
return err
}
@ -131,6 +131,10 @@ func redeployWhenChangedSecondStage(
stack.UpdateDate = time.Now().Unix()
gitCommitChangedOrForceUpdate = updated
}
if stack.AutoUpdate != nil && stack.AutoUpdate.ForceUpdate {
gitCommitChangedOrForceUpdate = true
}
}
if !gitCommitChangedOrForceUpdate {

View File

@ -77,7 +77,7 @@ export function AutoUpdateSettings({
checked={value.ForcePullImage || false}
label="Re-pull image"
labelClass="col-sm-3 col-lg-2"
tooltip="If enabled, then when redeploy is triggered via the webhook or polling, if there's a newer image with the tag that you've specified (e.g. changeable development builds), it's pulled and redeployed. If you haven't specified a tag, or have specified 'latest' as the tag, then the image with the tag 'latest' is pulled and redeployed. With relative path enabled, it also redeploys when mounted files (not just the compose file) change."
tooltip="If enabled, then when redeploy is triggered via the webhook or polling, if there's a newer image with the tag that you've specified (e.g. changeable development builds), it's pulled and redeployed. If you haven't specified a tag, or have specified 'latest' as the tag, then the image with the tag 'latest' is pulled and redeployed."
onChange={(value) => onChange({ ForcePullImage: value })}
/>
</div>
@ -110,17 +110,9 @@ export function AutoUpdateSettings({
) : (
<p>
If enabled, then when redeploy is triggered via the webhook or
polling, the stack behavior depends on the stack type:
<br />
<strong>Regular stacks:</strong> Redeploy whenever triggered,
without checking for docker-compose file changes
<br />
<strong>Edge stacks:</strong> Redeploy only when the
docker-compose file in the Git repository has changed. Commits
that change unrelated files or mounted files (via relative paths)
do not trigger redeployment. Currently, this option does not
change the redeployment behavior, and it remains a temporary
solution until a more complete behavior is added later.
polling, the stack will be always redeployed, even if Portainer
detects no difference between the git repo and what was stored
locally on last git pull.
</p>
)
}