mirror of https://github.com/portainer/portainer
feat(edgestack): git stack versioning [EE-5458] (#9126)
parent
ceabb2884b
commit
bc47061624
|
@ -320,8 +320,16 @@ func (service *Service) StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileNam
|
||||||
// GetEdgeStackProjectPathByVersion returns the absolute path on the FS for a edge stack based
|
// GetEdgeStackProjectPathByVersion returns the absolute path on the FS for a edge stack based
|
||||||
// on its identifier and version.
|
// on its identifier and version.
|
||||||
// EE only feature
|
// EE only feature
|
||||||
func (service *Service) GetEdgeStackProjectPathByVersion(edgeStackIdentifier string, version int) string {
|
func (service *Service) GetEdgeStackProjectPathByVersion(edgeStackIdentifier string, version int, commitHash string) string {
|
||||||
versionStr := fmt.Sprintf("v%d", version)
|
versionStr := ""
|
||||||
|
if version != 0 {
|
||||||
|
versionStr = fmt.Sprintf("v%d", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if commitHash != "" {
|
||||||
|
versionStr = fmt.Sprintf("%s", commitHash)
|
||||||
|
}
|
||||||
|
|
||||||
return JoinPaths(service.wrapFileStore(EdgeStackStorePath), edgeStackIdentifier, versionStr)
|
return JoinPaths(service.wrapFileStore(EdgeStackStorePath), edgeStackIdentifier, versionStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +337,10 @@ func (service *Service) GetEdgeStackProjectPathByVersion(edgeStackIdentifier str
|
||||||
// It returns the path to the folder where the file is stored.
|
// It returns the path to the folder where the file is stored.
|
||||||
// EE only feature
|
// EE only feature
|
||||||
func (service *Service) StoreEdgeStackFileFromBytesByVersion(edgeStackIdentifier, fileName string, version int, data []byte) (string, error) {
|
func (service *Service) StoreEdgeStackFileFromBytesByVersion(edgeStackIdentifier, fileName string, version int, data []byte) (string, error) {
|
||||||
versionStr := fmt.Sprintf("v%d", version)
|
versionStr := ""
|
||||||
|
if version != 0 {
|
||||||
|
versionStr = fmt.Sprintf("v%d", version)
|
||||||
|
}
|
||||||
stackStorePath := JoinPaths(EdgeStackStorePath, edgeStackIdentifier, versionStr)
|
stackStorePath := JoinPaths(EdgeStackStorePath, edgeStackIdentifier, versionStr)
|
||||||
|
|
||||||
err := service.createDirectoryInStore(stackStorePath)
|
err := service.createDirectoryInStore(stackStorePath)
|
||||||
|
@ -349,8 +360,16 @@ func (service *Service) StoreEdgeStackFileFromBytesByVersion(edgeStackIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormProjectPathByVersion returns the absolute path on the FS for a project based with version
|
// FormProjectPathByVersion returns the absolute path on the FS for a project based with version
|
||||||
func (service *Service) FormProjectPathByVersion(path string, version int) string {
|
func (service *Service) FormProjectPathByVersion(path string, version int, commitHash string) string {
|
||||||
versionStr := fmt.Sprintf("v%d", version)
|
versionStr := ""
|
||||||
|
if version != 0 {
|
||||||
|
versionStr = fmt.Sprintf("v%d", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if commitHash != "" {
|
||||||
|
versionStr = fmt.Sprintf("%s", commitHash)
|
||||||
|
}
|
||||||
|
|
||||||
return JoinPaths(path, versionStr)
|
return JoinPaths(path, versionStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
|
"github.com/portainer/portainer/api/filesystem"
|
||||||
"github.com/portainer/portainer/api/git"
|
"github.com/portainer/portainer/api/git"
|
||||||
gittypes "github.com/portainer/portainer/api/git/types"
|
gittypes "github.com/portainer/portainer/api/git/types"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 bool, projectPath string) (bool, string, error) {
|
func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *gittypes.RepoConfig, forceUpdate, enableVersionFolder bool, projectPath string) (bool, string, error) {
|
||||||
if gitConfig == nil {
|
if gitConfig == nil {
|
||||||
return false, "", nil
|
return false, "", nil
|
||||||
}
|
}
|
||||||
|
@ -46,10 +47,15 @@ func UpdateGitObject(gitService portainer.GitService, objId string, gitConfig *g
|
||||||
return false, newHash, nil
|
return false, newHash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toDir := projectPath
|
||||||
|
if enableVersionFolder {
|
||||||
|
toDir = filesystem.JoinPaths(projectPath, newHash)
|
||||||
|
}
|
||||||
|
|
||||||
cloneParams := &cloneRepositoryParameters{
|
cloneParams := &cloneRepositoryParameters{
|
||||||
url: gitConfig.URL,
|
url: gitConfig.URL,
|
||||||
ref: gitConfig.ReferenceName,
|
ref: gitConfig.ReferenceName,
|
||||||
toDir: projectPath,
|
toDir: toDir,
|
||||||
tlsSkipVerify: gitConfig.TLSSkipVerify,
|
tlsSkipVerify: gitConfig.TLSSkipVerify,
|
||||||
}
|
}
|
||||||
if gitConfig.Authentication != nil {
|
if gitConfig.Authentication != nil {
|
||||||
|
|
|
@ -1388,9 +1388,9 @@ type (
|
||||||
RollbackStackFile(stackIdentifier, fileName string) error
|
RollbackStackFile(stackIdentifier, fileName string) error
|
||||||
GetEdgeStackProjectPath(edgeStackIdentifier string) string
|
GetEdgeStackProjectPath(edgeStackIdentifier string) string
|
||||||
StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileName string, data []byte) (string, error)
|
StoreEdgeStackFileFromBytes(edgeStackIdentifier, fileName string, data []byte) (string, error)
|
||||||
GetEdgeStackProjectPathByVersion(edgeStackIdentifier string, version int) string
|
GetEdgeStackProjectPathByVersion(edgeStackIdentifier string, version int, commitHash string) string
|
||||||
StoreEdgeStackFileFromBytesByVersion(edgeStackIdentifier, fileName string, version int, data []byte) (string, error)
|
StoreEdgeStackFileFromBytesByVersion(edgeStackIdentifier, fileName string, version int, data []byte) (string, error)
|
||||||
FormProjectPathByVersion(projectIdentifier string, version int) string
|
FormProjectPathByVersion(projectIdentifier string, version int, commitHash string) string
|
||||||
SafeMoveDirectory(src, dst string) error
|
SafeMoveDirectory(src, dst string) error
|
||||||
StoreRegistryManagementFileFromBytes(folder, fileName string, data []byte) (string, error)
|
StoreRegistryManagementFileFromBytes(folder, fileName string, data []byte) (string, error)
|
||||||
KeyPairFilesExist() (bool, error)
|
KeyPairFilesExist() (bool, error)
|
||||||
|
|
|
@ -61,7 +61,7 @@ func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, data
|
||||||
|
|
||||||
var gitCommitChangedOrForceUpdate bool
|
var gitCommitChangedOrForceUpdate bool
|
||||||
if !stack.FromAppTemplate {
|
if !stack.FromAppTemplate {
|
||||||
updated, newHash, err := update.UpdateGitObject(gitService, fmt.Sprintf("stack:%d", stackID), stack.GitConfig, false, stack.ProjectPath)
|
updated, newHash, err := update.UpdateGitObject(gitService, fmt.Sprintf("stack:%d", stackID), stack.GitConfig, false, false, stack.ProjectPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue