Skip to content
Snippets Groups Projects
Commit df6bc06f authored by AxelCarayon's avatar AxelCarayon
Browse files

Utilise le Dockerfile si présent pour reproduire une expérimentation

parent f45ac970
No related branches found
No related tags found
1 merge request!21Ajout docker
...@@ -17,6 +17,7 @@ instructionFile = None ...@@ -17,6 +17,7 @@ instructionFile = None
inputFiles = [] inputFiles = []
outputFiles = [] outputFiles = []
dockerfileIsPresent = False
beforeHash = None beforeHash = None
def init(repository,branch) -> None : def init(repository,branch) -> None :
...@@ -39,7 +40,7 @@ def init(repository,branch) -> None : ...@@ -39,7 +40,7 @@ def init(repository,branch) -> None :
os.chdir(folder) os.chdir(folder)
def getParameters() -> None : def getParameters() -> None :
global commandsFile, inputFiles, outputFiles, beforeHash, instructionFile global commandsFile, inputFiles, outputFiles, beforeHash, instructionFile, dockerfileIsPresent
if not (os.path.exists('experimentResume.yaml')): if not (os.path.exists('experimentResume.yaml')):
raise Exception("No exeperimentResume.yaml file found, the branch is not an exeperiment") raise Exception("No exeperimentResume.yaml file found, the branch is not an exeperiment")
with open('experimentResume.yaml', 'r') as stream: with open('experimentResume.yaml', 'r') as stream:
...@@ -49,6 +50,7 @@ def getParameters() -> None : ...@@ -49,6 +50,7 @@ def getParameters() -> None :
inputFiles = parameters.get('inputs') inputFiles = parameters.get('inputs')
beforeHash = parameters.get('checksums') beforeHash = parameters.get('checksums')
instructionFile = parameters.get('instructions') instructionFile = parameters.get('instructions')
dockerfileIsPresent = parameters.get('dockerfile')
def runExperiment() -> None : def runExperiment() -> None :
...@@ -94,16 +96,44 @@ def compareChecksums() -> bool: ...@@ -94,16 +96,44 @@ def compareChecksums() -> bool:
return changes return changes
def buildDockerImage() -> None:
print("Building the docker image ...")
try :
subprocess.run(f"docker build -t experimentreproduction ./",shell=True).check_returncode()
except :
subprocess.run(f"sudo docker build -t experimentreproduction ./",shell=True).check_returncode()
def getWorkir() -> str :
workdir = "/"
with open("Dockerfile","r") as file:
for line in file.read().splitlines():
if line.startswith("WORKDIR"):
workdir = line.split(" ")[1]
return workdir
def runDockerImage() -> None:
print("binding docker image to the current directory and running it...")
try:
subprocess.run(f"docker run -it --mount type=bind,source=\"$PWD\",target={getWorkir()} experimentreproduction",shell=True).check_returncode()
except :
subprocess.run(f"sudo docker run -it --mount type=bind,source=\"$PWD\",target={getWorkir()} experimentreproduction",shell=True).check_returncode()
def run(repository, branch) -> None : def run(repository, branch) -> None :
print("Initializing the experiment repository ...") print("Initializing the experiment repository ...")
init(repository, branch) init(repository, branch)
print("Getting the experiment parameters ...") print("Getting the experiment parameters ...")
getParameters() getParameters()
print("Running the experiment ...") print("Running the experiment ...")
if (commandsFile != None) : if (dockerfileIsPresent) :
runExperiment() print("Dockerimage was found ! Using it to run the experiment...")
else : buildDockerImage()
checkForInstructions() runDockerImage()
else:
if (commandsFile != None) :
runExperiment()
else :
checkForInstructions()
print("Comparing checksums of the outputs ...") print("Comparing checksums of the outputs ...")
if (compareChecksums()) : if (compareChecksums()) :
print("The exepriment was reproduced with succes but some output files are differents.") print("The exepriment was reproduced with succes but some output files are differents.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment