Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Crash when using env_file path within include #11772

Closed
clementgoclock opened this issue Apr 26, 2024 · 1 comment · Fixed by compose-spec/compose-go#621
Closed

[BUG] Crash when using env_file path within include #11772

clementgoclock opened this issue Apr 26, 2024 · 1 comment · Fixed by compose-spec/compose-go#621
Assignees
Labels

Comments

@clementgoclock
Copy link

clementgoclock commented Apr 26, 2024

Description

As shown in the documentation, we can use path and required in the env_file parameter.
If they are added in an include context, they cause a crash.

I'm not sure if this function is supported, using path and required in the include context, but since it's not specified in the documentation, I gave it a try.

I expect compose to tell me that this method is not allowed or that it works.

Steps To Reproduce

  1. Use this compose.yaml
include:
    - path: include.svc.compose.yaml
      env_file:
        - path: ./vpn.env
          required: false
  1. Launch docker compose config
  2. Observe crash:
clement@fedora:~/work/repo/teleporter-compose$ docker compose config
panic: interface conversion: interface {} is map[string]interface {}, not string

goroutine 1 [running]:
github.com/compose-spec/compose-go/v2/types.(*StringList).DecodeMapstructure(0xc00049efa8, {0x1e27c40?, 0xc000163e90?})
	github.com/compose-spec/compose-go/v2@v2.0.2/types/stringOrList.go:31 +0x1e6
github.com/compose-spec/compose-go/v2/loader.decoderHook({0x1e27c40?, 0xc000163e90?, 0xc000163e90?}, {0x1ead060?, 0xc00049efa8?, 0x1e27c40?})
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/mapstructure.go:52 +0x2a5
github.com/mitchellh/mapstructure.DecodeHookExec({0x1f79600?, 0x247ace0?}, {0x1e27c40?, 0xc000163e90?, 0x1f79600?}, {0x1ead060?, 0xc00049efa8?, 0x1f79600?})
	github.com/mitchellh/mapstructure@v1.5.0/decode_hooks.go:51 +0x134
github.com/compose-spec/compose-go/v2/loader.Transform.ComposeDecodeHookFunc.func1({0x1e27c40?, 0xc000163e90?, 0x4190a8?}, {0x1ead060?, 0xc00049efa8?, 0x7fc800c51950?})
	github.com/mitchellh/mapstructure@v1.5.0/decode_hooks.go:69 +0x10d
github.com/mitchellh/mapstructure.DecodeHookExec({0x1f79600?, 0xc0000acc40?}, {0x1e27c40?, 0xc000163e90?, 0x8?}, {0x1ead060?, 0xc00049efa8?, 0xc0006e09e0?})
	github.com/mitchellh/mapstructure@v1.5.0/decode_hooks.go:51 +0x134
github.com/mitchellh/mapstructure.(*Decoder).decode(0xc0004a4760, {0xc0006e09e0, 0xc}, {0x1e27c40?, 0xc000163e90?}, {0x1ead060?, 0xc00049efa8?, 0x33?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:459 +0x134
github.com/mitchellh/mapstructure.(*Decoder).decodeStructFromMap(0xc0004a4760, {0xc0006e09a9, 0x3}, {0x1f70c80?, 0xc0006ea840?, 0x1f79600?}, {0x20d63c0?, 0xc00049ef80?, 0x2?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1411 +0xaa5
github.com/mitchellh/mapstructure.(*Decoder).decodeStruct(0x1f79600?, {0xc0006e09a9, 0x3}, {0x1f70c80?, 0xc0006ea840?}, {0x20d63c0?, 0xc00049ef80?, 0xc00034dfe8?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1235 +0x55c
github.com/mitchellh/mapstructure.(*Decoder).decode(0xc0004a4760, {0xc0006e09a9, 0x3}, {0x1f70c80?, 0xc0006ea840?}, {0x20d63c0?, 0xc00049ef80?, 0x2699000?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:482 +0x25f
github.com/mitchellh/mapstructure.(*Decoder).decodeSlice(0xc0004a4760, {0x0, 0x0}, {0x1e27c40, 0xc000163ea8}, {0x1e2c020?, 0xc000163ec0?, 0xc000312bf0?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:1139 +0x985
github.com/mitchellh/mapstructure.(*Decoder).decode(0xc0004a4760, {0x0, 0x0}, {0x1e27c40?, 0xc000163ea8?}, {0x1e2c020?, 0xc000163ec0?, 0x50?})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:488 +0x247
github.com/mitchellh/mapstructure.(*Decoder).Decode(0xc0004a4760, {0x1e27c40, 0xc000163ea8})
	github.com/mitchellh/mapstructure@v1.5.0/mapstructure.go:417 +0xa7
github.com/compose-spec/compose-go/v2/loader.Transform({0x1e27c40, 0xc000163ea8}, {0x1e2bfe0?, 0xc000163ec0})
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:735 +0x18a
github.com/compose-spec/compose-go/v2/loader.loadIncludeConfig({0x1e27c40, 0xc000163ea8})
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/include.go:46 +0x1cd
github.com/compose-spec/compose-go/v2/loader.ApplyInclude({0x26c38e0, 0xc000477090}, {{0x0, 0x0}, {0xc00040fa00, 0x2a}, {0xc00022b080, 0x1, 0x1}, 0xc00022a7e0}, ...)
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/include.go:51 +0x87
github.com/compose-spec/compose-go/v2/loader.loadYamlModel.func1({0x1f70c80?, 0xc0006ea780?}, {0xc00034ea90, 0x1, 0x1})
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:402 +0x377
github.com/compose-spec/compose-go/v2/loader.loadYamlModel({0x26c38e0?, 0xc000477090}, {{0x0, 0x0}, {0xc00040fa00, 0x2a}, {0xc00022b080, 0x1, 0x1}, 0xc00022a7e0}, ...)
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:444 +0x958
github.com/compose-spec/compose-go/v2/loader.load({0x26c38e0, 0xc000477090}, {{0x0, 0x0}, {0xc00040fa00, 0x2a}, {0xc00022b080, 0x1, 0x1}, 0xc00022a7e0}, ...)
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:504 +0x38b
github.com/compose-spec/compose-go/v2/loader.loadModelWithContext({0x26c38e0, 0xc000477090}, 0xc00049eb80, 0xc0006db290)
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:333 +0x265
github.com/compose-spec/compose-go/v2/loader.LoadWithContext({0x26c38e0, 0xc000477090}, {{0x0, 0x0}, {0xc00040fa00, 0x2a}, {0xc00022b080, 0x1, 0x1}, 0xc00022a7e0}, ...)
	github.com/compose-spec/compose-go/v2@v2.0.2/loader/loader.go:301 +0xd8
github.com/compose-spec/compose-go/v2/cli.(*ProjectOptions).LoadProject(0xc0006db200, {0x26c38e0, 0xc000477090})
	github.com/compose-spec/compose-go/v2@v2.0.2/cli/options.go:440 +0x12a
github.com/docker/compose/v2/cmd/compose.(*ProjectOptions).ToProject(0xc0003fc6e0, {0x26c38e0, 0xc000477090}, {0x26d72e0, 0xc0001ff500}, {0x38ecd20, 0x0, 0x0}, {0xc00022a030, 0x6, ...})
	github.com/docker/compose/v2/cmd/compose/compose.go:274 +0x54e
github.com/docker/compose/v2/cmd/compose.(*configOptions).ToProject(0xc00034f7b8, {0x26c38e0, 0xc000477090}, {0x26d72e0, 0xc0001ff500}, {0x38ecd20, 0x0, 0x0}, {0x0, 0x0, ...})
	github.com/docker/compose/v2/cmd/compose/config.go:61 +0x16a
github.com/docker/compose/v2/cmd/compose.runConfig({0x26c38e0?, 0xc000477090?}, {0x26d72e0?, 0xc0001ff500?}, {0xc0003fc6e0, {0x232be68, 0x4}, {0x0, 0x0}, 0x0, ...}, ...)
	github.com/docker/compose/v2/cmd/compose/config.go:167 +0x165
github.com/docker/compose/v2/cmd/compose.configCommand.func2({0x26c38e0?, 0xc000477090?}, {0x38ecd20?, 0xc0000061a0?, 0x1cf69d9?})
	github.com/docker/compose/v2/cmd/compose/config.go:122 +0xe5
github.com/docker/compose/v2/cmd/compose.configCommand.Adapt.func4({0x26c38e0?, 0xc000477090?}, 0x2?, {0x38ecd20?, 0x0?, 0x0?})
	github.com/docker/compose/v2/cmd/compose/compose.go:121 +0x30
github.com/docker/compose/v2/cmd/compose.configCommand.Adapt.AdaptCmd.func7(0x0?, {0x38ecd20, 0x0, 0x0})
	github.com/docker/compose/v2/cmd/compose/compose.go:100 +0x14e
github.com/docker/compose/v2/cmd/cmdtrace.Setup.wrapRunE.func2(0xc0001ffe00?, {0x38ecd20?, 0x0?, 0x0?})
	github.com/docker/compose/v2/cmd/cmdtrace/cmd_span.go:84 +0x65
github.com/spf13/cobra.(*Command).execute(0xc00025e600, {0xc000266630, 0x0, 0x0})
	github.com/spf13/cobra@v1.8.0/command.go:983 +0xabc
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002f1500)
	github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/docker/cli/cli-plugins/plugin.RunPlugin(0x1d1f053?, 0xc000178900, {{0x232c990, 0x5}, {0x233679d, 0xb}, {0x269d680, 0x11}, {0x0, 0x0}, ...})
	github.com/docker/cli@v26.0.0+incompatible/cli-plugins/plugin/plugin.go:64 +0x10e
github.com/docker/cli/cli-plugins/plugin.Run(0x2479ba8, {{0x232c990, 0x5}, {0x233679d, 0xb}, {0x269d680, 0x11}, {0x0, 0x0}, {0x0, ...}})
	github.com/docker/cli@v26.0.0+incompatible/cli-plugins/plugin/plugin.go:77 +0xe5
main.pluginMain()
	github.com/docker/compose/v2/cmd/main.go:38 +0xa5
main.main()
	github.com/docker/compose/v2/cmd/main.go:98 +0x19c

Compose Version

clement@fedora:~/work/temp/docker-compose/bug_compose$ docker compose version
Docker Compose version v2.26.1-desktop.1
clement@fedora:~/work/temp/docker-compose/bug_compose$ docker-compose version
Docker Compose version v2.26.1

Docker Environment

docker info
clement@fedora:~/work/temp/docker-compose/bug_compose$ docker info
Client: Docker Engine - Community
 Version:    26.0.2
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.1-desktop.1
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.26.1-desktop.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.27
    Path:     /usr/lib/docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /usr/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.23
    Path:     /usr/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /usr/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.1.0
    Path:     /usr/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.6.3
    Path:     /usr/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 18
  Running: 18
  Paused: 0
  Stopped: 0
 Images: 32
 Server Version: 26.0.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.22-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.442GiB
 Name: docker-desktop
 ID: 7fdd91d8-1880-4324-885c-0d28875b2e73
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///home/clement/.docker/desktop/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Anything else?

No response

@glours
Copy link
Contributor

glours commented Apr 26, 2024

Hey @clementgoclock
For now the env_file property of the include attribute only support a list of env files, you can't specify if the env files are mandatory or not, see here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants