mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(system): path to upgrade swarm to BE [EE-4624] (#8124)
This commit is contained in:
parent
b59a0ba823
commit
db9d87c918
8 changed files with 54 additions and 21 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cbroglie/mustache"
|
||||
|
@ -17,8 +18,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// mustacheUpgradeStandaloneTemplateFile represents the name of the template file for the standalone upgrade
|
||||
mustacheUpgradeStandaloneTemplateFile = "upgrade-standalone.yml.mustache"
|
||||
// mustacheUpgradeDockerTemplateFile represents the name of the template file for the docker upgrade
|
||||
mustacheUpgradeDockerTemplateFile = "upgrade-docker.yml.mustache"
|
||||
|
||||
// portainerImagePrefixEnvVar represents the name of the environment variable used to define the image prefix for portainer-updater
|
||||
// useful if there's a need to test PR images
|
||||
|
@ -60,19 +61,20 @@ func (service *service) Upgrade(licenseKey string) error {
|
|||
|
||||
switch service.platform {
|
||||
case platform.PlatformDockerStandalone:
|
||||
return service.UpgradeDockerStandalone(licenseKey, portainer.APIVersion)
|
||||
// case platform.PlatformDockerSwarm:
|
||||
return service.upgradeDocker(licenseKey, portainer.APIVersion, "standalone")
|
||||
case platform.PlatformDockerSwarm:
|
||||
return service.upgradeDocker(licenseKey, portainer.APIVersion, "swarm")
|
||||
// case platform.PlatformKubernetes:
|
||||
// case platform.PlatformPodman:
|
||||
// case platform.PlatformNomad:
|
||||
// default:
|
||||
}
|
||||
|
||||
return errors.New("unsupported platform")
|
||||
return fmt.Errorf("unsupported platform %s", service.platform)
|
||||
}
|
||||
|
||||
func (service *service) UpgradeDockerStandalone(licenseKey, version string) error {
|
||||
templateName := filesystem.JoinPaths(service.assetsPath, "mustache-templates", mustacheUpgradeStandaloneTemplateFile)
|
||||
func (service *service) upgradeDocker(licenseKey, version, envType string) error {
|
||||
templateName := filesystem.JoinPaths(service.assetsPath, "mustache-templates", mustacheUpgradeDockerTemplateFile)
|
||||
|
||||
portainerImagePrefix := os.Getenv(portainerImagePrefixEnvVar)
|
||||
if portainerImagePrefix == "" {
|
||||
|
@ -88,6 +90,7 @@ func (service *service) UpgradeDockerStandalone(licenseKey, version string) erro
|
|||
"skip_pull_image": skipPullImage,
|
||||
"updater_image": os.Getenv(updaterImageEnvVar),
|
||||
"license": licenseKey,
|
||||
"envType": envType,
|
||||
})
|
||||
|
||||
log.Debug().
|
||||
|
@ -99,7 +102,8 @@ func (service *service) UpgradeDockerStandalone(licenseKey, version string) erro
|
|||
}
|
||||
|
||||
tmpDir := os.TempDir()
|
||||
filePath := filesystem.JoinPaths(tmpDir, fmt.Sprintf("upgrade-%d.yml", time.Now().Unix()))
|
||||
timeId := time.Now().Unix()
|
||||
filePath := filesystem.JoinPaths(tmpDir, fmt.Sprintf("upgrade-%d.yml", timeId))
|
||||
|
||||
r := bytes.NewReader([]byte(composeFile))
|
||||
|
||||
|
@ -108,18 +112,28 @@ func (service *service) UpgradeDockerStandalone(licenseKey, version string) erro
|
|||
return errors.Wrap(err, "failed to create upgrade compose file")
|
||||
}
|
||||
|
||||
projectName := fmt.Sprintf(
|
||||
"portainer-upgrade-%d-%s",
|
||||
timeId,
|
||||
strings.Replace(version, ".", "-", -1))
|
||||
|
||||
err = service.composeDeployer.Deploy(
|
||||
context.Background(),
|
||||
[]string{filePath},
|
||||
libstack.DeployOptions{
|
||||
ForceRecreate: true,
|
||||
AbortOnContainerExit: true,
|
||||
Options: libstack.Options{
|
||||
ProjectName: projectName,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
// optimally, server was restarted by the updater, so we should not reach this point
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to deploy upgrade stack")
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.New("upgrade failed: server should have been restarted by the updater")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue