Skip to content

Commit a5c35b0

Browse files
committed
Fix docker build script paths for subdirectory node sources
1 parent 8582910 commit a5c35b0

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
@@ -779,33 +779,37 @@ def cleanup_script_files():
779779
fcopy.write('CMD ["./a.out"]\n') # 7/02/21
780780

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

810814
fbuild.close()
811815

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)