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

os.getcwd() is used in DockerCreateRunner #447

Closed
gomons opened this issue Feb 4, 2020 · 6 comments
Closed

os.getcwd() is used in DockerCreateRunner #447

gomons opened this issue Feb 4, 2020 · 6 comments
Assignees

Comments

@gomons
Copy link

gomons commented Feb 4, 2020

  • Conan Package Tools Version: 0.30.4
  • Operating System: Linux

Additional info

Class DockerCreateRunner uses os.getcwd():

command = ('%s docker run --rm -v "%s:%s/project%s" %s %s %s %s %s '
            '"%s cd project && '
            '%s run_create_in_docker "' % (self._sudo_docker_command,
                                            os.getcwd(),
                                            self._docker_conan_home,
                                            volume_options,
                                            env_vars_text,
                                            self._docker_run_options,
                                            self._docker_platform_param,
                                            self._docker_image,
                                            self._docker_shell,
                                            self._lcow_user_workaround,
                                            update_command))

I think it should use cwd parameter from ConanMultiPackager class

@uilianries uilianries self-assigned this Feb 4, 2020
@uilianries
Copy link
Member

Not actually. The idea behind is loading a conanfile according cwd, which is executed before to run DockerCreateRunner.

https://github.com/conan-io/conan-package-tools/blob/develop/cpt/packager.py#L212

self.cwd also is used with chdir, before calling Conan API. But it is useless on Docker context, because we use Docker volume before mounting:

command = ('%s docker run --rm -v "%s:%s/project%s" %s %s %s %s %s '

@gomons
Copy link
Author

gomons commented Feb 4, 2020

@uilianries Thanks for the quick response!

Maybe I'm doing something wrong. Is it possible to run build.py from a directory where there is no recipe? My configuration:

foo/build.py
bar/conanfile.py

And I run build.py from foo directory. This is why I use the cwd argument for ConanMultiPackager, which is bar in this case, and it works without docker. But with docker os.getcwd() returns foo directory. Therefore, the foo folder is mounted to docker but I expect bar folder.

@theirix
Copy link
Contributor

theirix commented Oct 8, 2020

Has been hit this issue too. This really makes sense when you have multiple directories with recipes (like in CCI with recipes/libfoo/all, recipes/libbar/1.0). If conanfile is loaded from self.cwd for introspection, then mounted Docker volume should be at self.cwd too. For now non-flat directory structure does not work with Docker.

A possible fix is to pass cwd to DockerCreateRunner and replace os.getcwd() with self.cwd.

@theirix
Copy link
Contributor

theirix commented Oct 20, 2020

@uilianries what do you think? I can make a PR so new behaviour can be checked for typical scenarios.

@uilianries
Copy link
Member

@theirix Go ahead, let's see if is possible adding it without breaking the current behavior.

theirix added a commit to theirix/conan-package-tools that referenced this issue Oct 21, 2020
Patch allows to build packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
theirix added a commit to theirix/conan-package-tools that referenced this issue Oct 21, 2020
The patch allows building packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
theirix added a commit to theirix/conan-package-tools that referenced this issue Oct 30, 2020
theirix added a commit to theirix/conan-package-tools that referenced this issue Oct 31, 2020
The patch allows building packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
theirix added a commit to theirix/conan-package-tools that referenced this issue Oct 31, 2020
theirix added a commit to theirix/conan-package-tools that referenced this issue Nov 1, 2020
The patch allows building packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
theirix added a commit to theirix/conan-package-tools that referenced this issue Nov 1, 2020
theirix added a commit to theirix/conan-package-tools that referenced this issue Nov 17, 2020
The patch allows building packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
theirix added a commit to theirix/conan-package-tools that referenced this issue Nov 17, 2020
@uilianries
Copy link
Member

fixed by #528

boussaffawalid pushed a commit to boussaffawalid/conan-package-tools that referenced this issue Feb 11, 2022
The patch allows building packages using Docker in non-flat repositories
with specifying cwd.

Example:

    builder = ConanMultiPackager(cwd=os.path.join(os.getcwd(), 'recipes', 'foobar'))
boussaffawalid pushed a commit to boussaffawalid/conan-package-tools that referenced this issue Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants