podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

podman-compose config should expand relative path

Open loynoir opened this issue 2 years ago • 2 comments

Describe the bug vscode devcontainer build failed when using podman-compose instead of docker-compose

Debug

  • docker-compose expand relative path './xxx' '../xxx' to abosolute path, while podman-compose doesn't. And vscode devcontainer builder cwd is not parent dir of compose file. So, BOOM!
  • Above inffect .services.XXX.build.context, .services.XXX.volumes[XXX]

To Reproduce Steps to reproduce the behavior:

vscode settings ~/.config/Code/User/settings.json

    "dev.containers.dockerPath": "/tmp/podman-devcontainer-wrapper",
    "dev.containers.dockerComposePath": "/tmp/podman-compose-devcontainer-wrapper"
$ cat /tmp/podman-devcontainer-wrapper                                             
#!/bin/bash
BUILDAH_FORMAT=docker \
PODMAN_USERNS=keep-id \
podman "$@"
$ cat /tmp/podman-compose-devcontainer-wrapper 
#!/bin/bash
BUILDAH_FORMAT=docker \
PODMAN_USERNS=keep-id \
~/.local/bin/podman-compose "$@"

reproduce

$ pip3 install https://github.com/containers/podman-compose/archive/devel.tar.gz 
$ cd /tmp/reproduce
$ cat .devcontainer/docker-compose.yml
version: '3'

services:
  devcontainer:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ..:/repo:cached
      - ../../dotfiles:/dotfiles:cached
    command: sleep infinity

Expected behavior

$  docker-compose -f ./.devcontainer/docker-compose.yml config
name: devcontainer
services:
  devcontainer:
    build:
      context: /tmp/reproduce/.devcontainer
      dockerfile: Dockerfile
    command:
    - sleep
    - infinity
    networks:
      default: null
    volumes:
    - type: bind
      source: /tmp/reproduce
      target: /repo
      bind:
        create_host_path: true
    - type: bind
      source: /tmp/dotfiles
      target: /dotfiles
      bind:
        create_host_path: true
networks:
  default:
    name: devcontainer_default

Actual behavior

$ BUILDAH_FORMAT=docker PODMAN_USERNS=keep-id ~/.local/bin/podman-compose -f ./.devcontainer/docker-compose.yml config
podman-compose version: 1.0.4
['podman', '--version', '']
using podman version: 4.3.1
services:
  devcontainer:
    build:
      context: .
      dockerfile: Dockerfile
    command: sleep infinity
    volumes:
    - ..:/repo:cached
    - ../../dotfiles:/dotfiles:cached
version: '3'

Output

Grab from real world case error output

[2257 ms] Start: Run: /tmp/podman-compose-devcontainer-wrapper -f /path/to/.devcontainer/docker-compose.yml config
...
[2337 ms] Error: ENOENT: no such file or directory, open '/home/xxx/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/Dockerfile'
...

Environment:

  • OS: Linux / WSL / Mac
  • podman version:
  • podman compose version: (git hex)

Additional context

Rewrite podman-compose in golang https://github.com/containers/podman-compose/issues/621

loynoir avatar Jan 19 '23 13:01 loynoir

I was also annoyed that I cannot run pre-existing devcontainers. So I'm looking into implementing a fix for this one.

But. docker compose will convert relative paths to absolute paths during normalization, only if the path does not contain letters, ie ., ../, ../../ and so on will be converted to absolute paths. However, ./a, ./dev, ../dev, and so on will stay relative.

Would we want to convert all of them to absolute paths, keep them all as is in compose file (so users can change that manually), or would we want to follow docker compose approach? Personally, I would go with the option of normalising everything to absolute paths, not sure if there are any cases where local paths are needed. What are your thoughts @muayyad-alsadi ?

Evedel avatar Apr 22 '23 11:04 Evedel

I wrote a script to work around this problem as a stopgap.

https://github.com/zyzhu2000/podman-compose-fix

zyzhu2000 avatar Mar 16 '25 18:03 zyzhu2000