mirror of https://github.com/portainer/portainer
fix(edgestack): unify gitops update flow [BE-12184] (#1110)
parent
0ff39f9a61
commit
b70321a0aa
|
|
@ -60,9 +60,9 @@ type (
|
||||||
// EnvVars is a list of environment variables to inject into the stack
|
// EnvVars is a list of environment variables to inject into the stack
|
||||||
EnvVars []portainer.Pair
|
EnvVars []portainer.Pair
|
||||||
|
|
||||||
// Used only for EE async edge agent
|
// ForceUpdate is a flag indicating if the agent must force the update of the stack.
|
||||||
// ReadyRePullImage is a flag to indicate whether the auto update is trigger to re-pull image
|
// Used only for EE
|
||||||
ReadyRePullImage bool
|
ForceUpdate bool
|
||||||
|
|
||||||
DeployerOptionsPayload DeployerOptionsPayload
|
DeployerOptionsPayload DeployerOptionsPayload
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +77,14 @@ type (
|
||||||
// This flag drives `docker compose down --volumes` option
|
// This flag drives `docker compose down --volumes` option
|
||||||
// Used only for EE
|
// Used only for EE
|
||||||
RemoveVolumes bool
|
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.
|
// RegistryCredentials holds the credentials for a Docker registry.
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateGitObject updates a git object based on its config
|
// 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 {
|
if gitConfig == nil {
|
||||||
return false, "", nil
|
return false, "", nil
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *g
|
||||||
|
|
||||||
hashChanged := !strings.EqualFold(newHash, gitConfig.ConfigHash)
|
hashChanged := !strings.EqualFold(newHash, gitConfig.ConfigHash)
|
||||||
|
|
||||||
if !hashChanged && !forceUpdate {
|
if !hashChanged {
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("hash", newHash).
|
Str("hash", newHash).
|
||||||
Str("url", gitConfig.URL).
|
Str("url", gitConfig.URL).
|
||||||
|
|
|
||||||
|
|
@ -354,6 +354,14 @@ type (
|
||||||
Status []EdgeStackDeploymentStatus
|
Status []EdgeStackDeploymentStatus
|
||||||
// EE only feature
|
// EE only feature
|
||||||
DeploymentInfo StackDeploymentInfo
|
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 is a flag to indicate whether the auto update is trigger to re-pull image
|
||||||
ReadyRePullImage bool `json:"ReadyRePullImage,omitempty"`
|
ReadyRePullImage bool `json:"ReadyRePullImage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ func redeployWhenChangedSecondStage(
|
||||||
var gitCommitChangedOrForceUpdate bool
|
var gitCommitChangedOrForceUpdate bool
|
||||||
|
|
||||||
if !stack.FromAppTemplate {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -131,6 +131,10 @@ func redeployWhenChangedSecondStage(
|
||||||
stack.UpdateDate = time.Now().Unix()
|
stack.UpdateDate = time.Now().Unix()
|
||||||
gitCommitChangedOrForceUpdate = updated
|
gitCommitChangedOrForceUpdate = updated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if stack.AutoUpdate != nil && stack.AutoUpdate.ForceUpdate {
|
||||||
|
gitCommitChangedOrForceUpdate = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !gitCommitChangedOrForceUpdate {
|
if !gitCommitChangedOrForceUpdate {
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ export function AutoUpdateSettings({
|
||||||
checked={value.ForcePullImage || false}
|
checked={value.ForcePullImage || false}
|
||||||
label="Re-pull image"
|
label="Re-pull image"
|
||||||
labelClass="col-sm-3 col-lg-2"
|
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 })}
|
onChange={(value) => onChange({ ForcePullImage: value })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -110,17 +110,9 @@ export function AutoUpdateSettings({
|
||||||
) : (
|
) : (
|
||||||
<p>
|
<p>
|
||||||
If enabled, then when redeploy is triggered via the webhook or
|
If enabled, then when redeploy is triggered via the webhook or
|
||||||
polling, the stack behavior depends on the stack type:
|
polling, the stack will be always redeployed, even if Portainer
|
||||||
<br />
|
detects no difference between the git repo and what was stored
|
||||||
<strong>Regular stacks:</strong> Redeploy whenever triggered,
|
locally on last git pull.
|
||||||
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.
|
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue