mirror of
https://github.com/portainer/portainer.git
synced 2025-07-18 21:09:40 +02:00
Some checks are pending
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package edgestacks
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/filesystem"
|
|
edgestackutils "github.com/portainer/portainer/api/internal/edge/edgestacks"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func (handler *Handler) updateStackVersion(stack *portainer.EdgeStack, deploymentType portainer.EdgeStackDeploymentType, config []byte, oldGitHash string, relatedEnvironmentsIDs []portainer.EndpointID) error {
|
|
stack.Version = stack.Version + 1
|
|
stack.Status = edgestackutils.NewStatus(stack.Status, relatedEnvironmentsIDs)
|
|
|
|
return handler.storeStackFile(stack, deploymentType, config)
|
|
}
|
|
|
|
func (handler *Handler) storeStackFile(stack *portainer.EdgeStack, deploymentType portainer.EdgeStackDeploymentType, config []byte) error {
|
|
if deploymentType != stack.DeploymentType {
|
|
// deployment type was changed - need to delete all old files
|
|
if err := handler.FileService.RemoveDirectory(stack.ProjectPath); err != nil {
|
|
log.Warn().Err(err).Msg("Unable to clear old files")
|
|
}
|
|
|
|
stack.EntryPoint = ""
|
|
stack.ManifestPath = ""
|
|
stack.DeploymentType = deploymentType
|
|
}
|
|
|
|
stackFolder := strconv.Itoa(int(stack.ID))
|
|
entryPoint := ""
|
|
if deploymentType == portainer.EdgeStackDeploymentCompose {
|
|
if stack.EntryPoint == "" {
|
|
stack.EntryPoint = filesystem.ComposeFileDefaultName
|
|
}
|
|
|
|
entryPoint = stack.EntryPoint
|
|
}
|
|
|
|
if deploymentType == portainer.EdgeStackDeploymentKubernetes {
|
|
if stack.ManifestPath == "" {
|
|
stack.ManifestPath = filesystem.ManifestFileDefaultName
|
|
}
|
|
|
|
entryPoint = stack.ManifestPath
|
|
}
|
|
|
|
if _, err := handler.FileService.StoreEdgeStackFileFromBytes(stackFolder, entryPoint, config); err != nil {
|
|
return fmt.Errorf("unable to persist updated Compose file with version on disk: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|