* feat(compose): add docker-compose wrapper (#4713) * feat(compose): add docker-compose wrapper ce-187 * fix(compose): pick compose implementation upon startup * Add static compose build for linux * Fix wget * Fix platofrm specific docker-compose download * Keep amd64 architecture as download parameter * Add tmp folder for docker-compose * fix: line endings * add proxy server * logs * Proxy * Add lite transport for compose * Fix local deployment * refactor: pass proxyManager by ref * fix: string conversion * refactor: compose wrapper remove unused code * fix: tests * Add edge * Fix merge issue * refactor: remove unused code * Move server to proxy implementation * Cleanup wrapper and manager * feat: pass max supported compose syntax version with each endpoint * fix: pick compose syntax version * fix: store wrapper version in portainer * Get and show composeSyntaxMaxVersion at stack creation screen * Get and show composeSyntaxMaxVersion at stack editor screen * refactor: proxy server * Fix used tmp * Bump docker-compose to 1.28.0 * remove message for docker compose limitation * fix: markup typo * Rollback docker compose to 1.27.4 * * attempt to fix the windows build issue * * attempt to debug grunt issue * * use console log in grunt file * fix: try to fix windows build by removing indirect deps from go.mod * Remove tmp folder * Remove builder stage * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose * feat(build/windows): add git for Docker Compose - fixed verbose output * refactor: renames * fix(stack): get endpoint by EndpointProvider * fix(stack): use margin to add space between line instead of using br tag Co-authored-by: Stéphane Busso <stephane.busso@gmail.com> Co-authored-by: Simon Meng <simon.meng@portainer.io> Co-authored-by: yi-portainer <yi.chen@portainer.io> Co-authored-by: Steven Kang <skan070@gmail.com> * refactor(stacks): use compose library * refactor(stacks): remove utils * chore(deps): pin docker-compose-wrapper * chore(build): simplify docker-compose build * chore(build): remove ps compose script * chore(deps): update docker-compose-wrapper * fix(compose): close proxy after command Co-authored-by: Stéphane Busso <stephane.busso@gmail.com> Co-authored-by: Simon Meng <simon.meng@portainer.io> Co-authored-by: yi-portainer <yi.chen@portainer.io> Co-authored-by: Steven Kang <skan070@gmail.com>
113 lines
2.3 KiB
Go
113 lines
2.3 KiB
Go
package exec
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_stackFilePath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stack *portainer.Stack
|
|
expected string
|
|
}{
|
|
// {
|
|
// name: "should return empty result if stack is missing",
|
|
// stack: nil,
|
|
// expected: "",
|
|
// },
|
|
// {
|
|
// name: "should return empty result if stack don't have entrypoint",
|
|
// stack: &portainer.Stack{},
|
|
// expected: "",
|
|
// },
|
|
{
|
|
name: "should allow file name and dir",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: "dir",
|
|
EntryPoint: "file",
|
|
},
|
|
expected: path.Join("dir", "file"),
|
|
},
|
|
{
|
|
name: "should allow file name only",
|
|
stack: &portainer.Stack{
|
|
EntryPoint: "file",
|
|
},
|
|
expected: "file",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := stackFilePath(tt.stack)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_createEnvFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
tests := []struct {
|
|
name string
|
|
stack *portainer.Stack
|
|
expected string
|
|
expectedFile bool
|
|
}{
|
|
// {
|
|
// name: "should not add env file option if stack is missing",
|
|
// stack: nil,
|
|
// expected: "",
|
|
// },
|
|
{
|
|
name: "should not add env file option if stack doesn't have env variables",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: dir,
|
|
},
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "should not add env file option if stack's env variables are empty",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: dir,
|
|
Env: []portainer.Pair{},
|
|
},
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "should add env file option if stack has env variables",
|
|
stack: &portainer.Stack{
|
|
ProjectPath: dir,
|
|
Env: []portainer.Pair{
|
|
{Name: "var1", Value: "value1"},
|
|
{Name: "var2", Value: "value2"},
|
|
},
|
|
},
|
|
expected: "var1=value1\nvar2=value2\n",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, _ := createEnvFile(tt.stack)
|
|
|
|
if tt.expected != "" {
|
|
assert.Equal(t, path.Join(tt.stack.ProjectPath, "stack.env"), result)
|
|
|
|
f, _ := os.Open(path.Join(dir, "stack.env"))
|
|
content, _ := ioutil.ReadAll(f)
|
|
|
|
assert.Equal(t, tt.expected, string(content))
|
|
} else {
|
|
assert.Equal(t, "", result)
|
|
}
|
|
})
|
|
}
|
|
}
|