Skip to content

Commit 24ebe32

Browse files
committed
Fix docker build script paths for subdirectory node sources
1 parent a283177 commit 24ebe32

2 files changed

Lines changed: 60 additions & 27 deletions

File tree

mkconcore.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -785,33 +785,37 @@ def cleanup_script_files():
785785
fcopy.write('CMD ["./a.out"]\n') # 7/02/21
786786

787787
fbuild.write('#!/bin/bash' + "\n")
788-
for node in nodes_dict:
789-
containername,sourcecode = nodes_dict[node].split(':')
790-
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
791-
dockername,langext = sourcecode.rsplit(".", 1)
792-
fbuild.write("mkdir docker-"+dockername+"\n")
793-
fbuild.write("cd docker-"+dockername+"\n")
794-
fbuild.write("cp ../src/Dockerfile."+dockername+" Dockerfile\n")
795-
#copy sourcefiles from ./src into corresponding directories
796-
fbuild.write("cp ../src/"+sourcecode+" .\n")
797-
if langext == "py": #4/29/21
798-
fbuild.write("cp ../src/concore.py .\n")
799-
elif langext == "cpp": #6/22/21
800-
fbuild.write("cp ../src/concore.hpp .\n")
801-
elif langext == "v": #6/25/21
802-
fbuild.write("cp ../src/concore.v .\n")
803-
if langext == "m":
804-
fbuild.write("cp ../src/concore_*.m .\n")
805-
fbuild.write("cp ../src/import_concore.m .\n")
806-
if langext == "sh": #5/27/21
807-
fbuild.write("chmod u+x "+sourcecode+"\n")
808-
fbuild.write("cp ../src/"+dockername+".iport concore.iport\n")
809-
fbuild.write("cp ../src/"+dockername+".oport concore.oport\n")
810-
#include data files in here if they exist
811-
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
812-
fbuild.write("cp -r ../src/"+dockername+".dir/* .\n")
813-
fbuild.write(DOCKEREXE+" build -t docker-"+dockername+" .\n")
814-
fbuild.write("cd ..\n")
788+
for node in nodes_dict:
789+
containername,sourcecode = nodes_dict[node].split(':')
790+
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
791+
dockername,langext = sourcecode.rsplit(".", 1)
792+
# dockername can include subdirectories (e.g. subdir/script).
793+
# Compute a stable prefix to reach study root from docker build dir.
794+
docker_subpath_depth = dockername.count("/") + dockername.count("\\")
795+
docker_rel_prefix = "../" * (docker_subpath_depth + 1)
796+
fbuild.write("mkdir docker-"+dockername+"\n")
797+
fbuild.write("cd docker-"+dockername+"\n")
798+
fbuild.write("cp "+docker_rel_prefix+"src/Dockerfile."+dockername+" Dockerfile\n")
799+
#copy sourcefiles from ./src into corresponding directories
800+
fbuild.write("cp "+docker_rel_prefix+"src/"+sourcecode+" .\n")
801+
if langext == "py": #4/29/21
802+
fbuild.write("cp "+docker_rel_prefix+"src/concore.py .\n")
803+
elif langext == "cpp": #6/22/21
804+
fbuild.write("cp "+docker_rel_prefix+"src/concore.hpp .\n")
805+
elif langext == "v": #6/25/21
806+
fbuild.write("cp "+docker_rel_prefix+"src/concore.v .\n")
807+
if langext == "m":
808+
fbuild.write("cp "+docker_rel_prefix+"src/concore_*.m .\n")
809+
fbuild.write("cp "+docker_rel_prefix+"src/import_concore.m .\n")
810+
if langext == "sh": #5/27/21
811+
fbuild.write("chmod u+x "+sourcecode+"\n")
812+
fbuild.write("cp "+docker_rel_prefix+"src/"+dockername+".iport concore.iport\n")
813+
fbuild.write("cp "+docker_rel_prefix+"src/"+dockername+".oport concore.oport\n")
814+
#include data files in here if they exist
815+
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
816+
fbuild.write("cp -r "+docker_rel_prefix+"src/"+dockername+".dir/* .\n")
817+
fbuild.write(DOCKEREXE+" build -t docker-"+dockername+" .\n")
818+
fbuild.write("cd "+docker_rel_prefix+"\n")
815819

816820
fbuild.close()
817821

tests/test_cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ def test_run_command_subdir_source(self):
153153
self.assertEqual(result.exit_code, 0)
154154
self.assertTrue(Path('out/src/subdir/script.py').exists())
155155

156+
def test_run_command_docker_subdir_source_build_paths(self):
157+
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
158+
result = self.runner.invoke(cli, ['init', 'test-project'])
159+
self.assertEqual(result.exit_code, 0)
160+
161+
subdir = Path('test-project/src/subdir')
162+
subdir.mkdir(parents=True, exist_ok=True)
163+
shutil.move('test-project/src/script.py', subdir / 'script.py')
164+
165+
workflow_path = Path('test-project/workflow.graphml')
166+
content = workflow_path.read_text()
167+
content = content.replace('N1:script.py', 'N1:subdir/script.py')
168+
workflow_path.write_text(content)
169+
170+
result = self.runner.invoke(cli, [
171+
'run',
172+
'test-project/workflow.graphml',
173+
'--source', 'test-project/src',
174+
'--output', 'out',
175+
'--type', 'docker'
176+
])
177+
self.assertEqual(result.exit_code, 0)
178+
179+
build_script = Path('out/build').read_text()
180+
self.assertIn('cp ../../src/Dockerfile.subdir/script Dockerfile', build_script)
181+
self.assertIn('cp ../../src/subdir/script.py .', build_script)
182+
self.assertIn('cp ../../src/subdir/script.iport concore.iport', build_script)
183+
self.assertIn('cd ../../', build_script)
184+
156185
def test_run_command_shared_source_specialization_merges_edge_params(self):
157186
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
158187
Path('src').mkdir()

0 commit comments

Comments
 (0)