mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
feat(stacks): support automated sync for stacks [EE-248] (#5340)
This commit is contained in:
parent
5fe90db36a
commit
bcccdfb669
94 changed files with 2680 additions and 469 deletions
|
@ -2,6 +2,7 @@ package stackutils
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
)
|
||||
|
@ -10,3 +11,12 @@ import (
|
|||
func ResourceControlID(endpointID portainer.EndpointID, name string) string {
|
||||
return fmt.Sprintf("%d_%s", endpointID, name)
|
||||
}
|
||||
|
||||
// GetStackFilePaths returns a list of file paths based on stack project path
|
||||
func GetStackFilePaths(stack *portainer.Stack) []string {
|
||||
var filePaths []string
|
||||
for _, file := range append([]string{stack.EntryPoint}, stack.AdditionalFiles...) {
|
||||
filePaths = append(filePaths, path.Join(stack.ProjectPath, file))
|
||||
}
|
||||
return filePaths
|
||||
}
|
||||
|
|
26
api/internal/stackutils/stackutils_test.go
Normal file
26
api/internal/stackutils/stackutils_test.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package stackutils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_GetStackFilePaths(t *testing.T) {
|
||||
stack := &portainer.Stack{
|
||||
ProjectPath: "/tmp/stack/1",
|
||||
EntryPoint: "file-one.yml",
|
||||
}
|
||||
|
||||
t.Run("stack doesn't have additional files", func(t *testing.T) {
|
||||
expected := []string{"/tmp/stack/1/file-one.yml"}
|
||||
assert.ElementsMatch(t, expected, GetStackFilePaths(stack))
|
||||
})
|
||||
|
||||
t.Run("stack has additional files", func(t *testing.T) {
|
||||
stack.AdditionalFiles = []string{"file-two.yml", "file-three.yml"}
|
||||
expected := []string{"/tmp/stack/1/file-one.yml", "/tmp/stack/1/file-two.yml", "/tmp/stack/1/file-three.yml"}
|
||||
assert.ElementsMatch(t, expected, GetStackFilePaths(stack))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue