mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 06:19:41 +02:00
fix(stack): env placeholder as host path [BE-11187] (#12186)
Some checks are pending
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_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 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-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
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
Some checks are pending
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_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 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-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
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
This commit is contained in:
parent
517abc662a
commit
753150e03c
3 changed files with 235 additions and 0 deletions
|
@ -143,3 +143,230 @@ func containerExists(containerName string) bool {
|
|||
|
||||
return strings.Contains(string(out), containerName)
|
||||
}
|
||||
|
||||
func Test_Config(t *testing.T) {
|
||||
checkPrerequisites(t)
|
||||
|
||||
ctx := context.Background()
|
||||
dir := t.TempDir()
|
||||
projectName := "configtest"
|
||||
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
composeFileContent string
|
||||
expectFileContent string
|
||||
envFileContent string
|
||||
}{
|
||||
{
|
||||
name: "compose file with relative path",
|
||||
composeFileContent: `services:
|
||||
app:
|
||||
image: 'nginx:latest'
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ./nginx-data:/data`,
|
||||
expectFileContent: `name: configtest
|
||||
services:
|
||||
app:
|
||||
image: nginx:latest
|
||||
networks:
|
||||
default: null
|
||||
ports:
|
||||
- mode: ingress
|
||||
target: 80
|
||||
published: "80"
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./nginx-data
|
||||
target: /data
|
||||
bind:
|
||||
create_host_path: true
|
||||
networks:
|
||||
default:
|
||||
name: configtest_default
|
||||
`,
|
||||
envFileContent: "",
|
||||
},
|
||||
{
|
||||
name: "compose file with absolute path",
|
||||
composeFileContent: `services:
|
||||
app:
|
||||
image: 'nginx:latest'
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- /nginx-data:/data`,
|
||||
expectFileContent: `name: configtest
|
||||
services:
|
||||
app:
|
||||
image: nginx:latest
|
||||
networks:
|
||||
default: null
|
||||
ports:
|
||||
- mode: ingress
|
||||
target: 80
|
||||
published: "80"
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- type: bind
|
||||
source: /nginx-data
|
||||
target: /data
|
||||
bind:
|
||||
create_host_path: true
|
||||
networks:
|
||||
default:
|
||||
name: configtest_default
|
||||
`,
|
||||
envFileContent: "",
|
||||
},
|
||||
{
|
||||
name: "compose file with declared volume",
|
||||
composeFileContent: `services:
|
||||
app:
|
||||
image: 'nginx:latest'
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- nginx-data:/data
|
||||
volumes:
|
||||
nginx-data:
|
||||
driver: local`,
|
||||
expectFileContent: `name: configtest
|
||||
services:
|
||||
app:
|
||||
image: nginx:latest
|
||||
networks:
|
||||
default: null
|
||||
ports:
|
||||
- mode: ingress
|
||||
target: 80
|
||||
published: "80"
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- type: volume
|
||||
source: nginx-data
|
||||
target: /data
|
||||
volume: {}
|
||||
networks:
|
||||
default:
|
||||
name: configtest_default
|
||||
volumes:
|
||||
nginx-data:
|
||||
name: configtest_nginx-data
|
||||
driver: local
|
||||
`,
|
||||
envFileContent: "",
|
||||
},
|
||||
{
|
||||
name: "compose file with relative path environment variable placeholder",
|
||||
composeFileContent: `services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- 8019:80
|
||||
volumes:
|
||||
- ${WEB_HOME}:/usr/share/nginx/html/
|
||||
env_file:
|
||||
- stack.env
|
||||
`,
|
||||
expectFileContent: `name: configtest
|
||||
services:
|
||||
nginx:
|
||||
environment:
|
||||
WEB_HOME: ./html
|
||||
image: nginx:latest
|
||||
networks:
|
||||
default: null
|
||||
ports:
|
||||
- mode: ingress
|
||||
target: 80
|
||||
published: "8019"
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ./html
|
||||
target: /usr/share/nginx/html
|
||||
bind:
|
||||
create_host_path: true
|
||||
networks:
|
||||
default:
|
||||
name: configtest_default
|
||||
`,
|
||||
envFileContent: `WEB_HOME=./html`,
|
||||
},
|
||||
{
|
||||
name: "compose file with absolute path environment variable placeholder",
|
||||
composeFileContent: `services:
|
||||
nginx:
|
||||
image: nginx:latest
|
||||
ports:
|
||||
- 8019:80
|
||||
volumes:
|
||||
- ${WEB_HOME}:/usr/share/nginx/html/
|
||||
env_file:
|
||||
- stack.env
|
||||
`,
|
||||
|
||||
expectFileContent: `name: configtest
|
||||
services:
|
||||
nginx:
|
||||
environment:
|
||||
WEB_HOME: /usr/share/nginx/html
|
||||
image: nginx:latest
|
||||
networks:
|
||||
default: null
|
||||
ports:
|
||||
- mode: ingress
|
||||
target: 80
|
||||
published: "8019"
|
||||
protocol: tcp
|
||||
volumes:
|
||||
- type: bind
|
||||
source: /usr/share/nginx/html
|
||||
target: /usr/share/nginx/html
|
||||
bind:
|
||||
create_host_path: true
|
||||
networks:
|
||||
default:
|
||||
name: configtest_default
|
||||
`,
|
||||
envFileContent: `WEB_HOME=/usr/share/nginx/html`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
composeFilePath, err := createFile(dir, "docker-compose.yml", tc.composeFileContent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
envFilePath := ""
|
||||
if tc.envFileContent != "" {
|
||||
envFilePath, err = createFile(dir, "stack.env", tc.envFileContent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
w := setup(t)
|
||||
actual, err := w.Config(ctx, []string{composeFilePath}, libstack.Options{
|
||||
WorkingDir: dir,
|
||||
ProjectName: projectName,
|
||||
EnvFilePath: envFilePath,
|
||||
ConfigOptions: []string{"--no-path-resolution"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get config: %s. Error: %s", string(actual), err)
|
||||
}
|
||||
|
||||
if string(actual) != tc.expectFileContent {
|
||||
t.Fatalf("unexpected config output: %s(len=%d), expect: %s(len=%d)", actual, len(actual), tc.expectFileContent, len(tc.expectFileContent))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue