Skip to content

Commit

Permalink
Pass cwd to DockerCreateRunner, conan-io#447
Browse files Browse the repository at this point in the history
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'))
  • Loading branch information
theirix committed Nov 17, 2020
1 parent c0a3165 commit 96303de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ def run_builds(self, curpage=None, total_pages=None, base_profile_name=None):
lockfile=self.lockfile,
force_selinux=self.force_selinux,
skip_recipe_export=skip_recipe_export,
update_dependencies=self.update_dependencies)
update_dependencies=self.update_dependencies,
cwd=self.cwd)

r.run(pull_image=not pulled_docker_images[docker_image],
docker_entry_script=self.docker_entry_script)
Expand Down
6 changes: 4 additions & 2 deletions cpt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
force_selinux=None,
skip_recipe_export=False,
update_dependencies=False,
lockfile=None):
lockfile=None,
cwd=None):

self.printer = printer or Printer()
self._upload = upload
Expand Down Expand Up @@ -219,6 +220,7 @@ def __init__(self, profile_text, base_profile_text, base_profile_name, reference
self._force_selinux = force_selinux
self._skip_recipe_export = skip_recipe_export
self._update_dependencies = update_dependencies
self._cwd = cwd or os.getcwd()

def _pip_update_conan_command(self):
commands = []
Expand Down Expand Up @@ -298,7 +300,7 @@ def run(self, pull_image=True, docker_entry_script=None):
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._cwd,
self._docker_conan_home,
volume_options,
env_vars_text,
Expand Down
16 changes: 16 additions & 0 deletions cpt/test/unit/packager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,19 @@ def test_lockfile(self):
builder.add_common_builds()
builder.run()
self.assertEquals("couse.lock", self.conan_api.calls[-1].kwargs["lockfile"])

def test_docker_cwd(self):
cwd = os.path.join(os.getcwd(), 'subdir')
self.packager = ConanMultiPackager(username="lasote",
channel="mychannel",
runner=self.runner,
conan_api=self.conan_api,
gcc_versions=["9"],
use_docker=True,
reference="zlib/1.2.11",
ci_manager=self.ci_manager,
cwd=cwd)

self._add_build(1, "gcc", "9")
self.packager.run_builds(1, 1)
self.assertIn('docker run --rm -v "%s:/home/conan/project"' % cwd, self.runner.calls[4])

0 comments on commit 96303de

Please sign in to comment.