Skip to content

Commit

Permalink
Merge pull request #13 from datmo/tests-environment
Browse files Browse the repository at this point in the history
adding more tests for docker build with requirements file
  • Loading branch information
shabazpatel committed Apr 20, 2018
2 parents b5dcede + e078c63 commit 5aadbf6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 20 deletions.
5 changes: 3 additions & 2 deletions datmo/core/controller/environment/driver/dockerenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def build_image(self, tag, definition_path="Dockerfile"):
# Passing path of Dockerfile
docker_shell_cmd_list.append("-f")
docker_shell_cmd_list.append(definition_path)
docker_shell_cmd_list.append(str(self.filepath))
dockerfile_dirpath = os.path.split(definition_path)[0]
docker_shell_cmd_list.append(str(dockerfile_dirpath))

# Remove intermediate containers after a successful build
docker_shell_cmd_list.append("--rm")
Expand Down Expand Up @@ -532,7 +533,7 @@ def create_default_dockerfile(self, requirements_filepath, language):
destination_dockerfile = os.path.join(self.filepath, "Dockerfile")
destination = open(destination_dockerfile, "w")
shutil.copyfileobj(open(base_dockerfile_filepath, "r"), destination)
destination.write(str("ADD %s /tmp/requirements.txt\n" % requirements_filepath))
destination.write(str("COPY %s /tmp/requirements.txt\n") % os.path.split(requirements_filepath)[-1])
destination.write(str("RUN pip install --no-cache-dir -r /tmp/requirements.txt\n"))
destination.close()

Expand Down
23 changes: 23 additions & 0 deletions datmo/core/controller/environment/driver/test/test_dockerenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,29 @@ def test_build(self):
# teardown
self.docker_environment_manager.remove(name, force=True)

# test
os.remove(path)
script_path = os.path.join(self.docker_environment_manager.filepath,
"script.py")

with open(script_path, "w") as f:
f.write("import numpy\n")
f.write("import sklearn\n")

success, path, output_path, requirements_filepath = \
self.docker_environment_manager.create(language="python3")

assert success and \
os.path.isfile(path) and \
"datmo" in open(output_path, "r").read()
assert requirements_filepath and os.path.isfile(requirements_filepath) and \
"numpy" in open(requirements_filepath, "r").read()

result = self.docker_environment_manager.build(name, path)
assert result == True
# teardown
self.docker_environment_manager.remove(name, force=True)

def test_run(self):
# TODO: add more options for run w/ volumes etc
image_name = str(uuid.uuid1())
Expand Down
1 change: 1 addition & 0 deletions datmo/core/controller/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def create(self, dictionary):
# Delete temporary files created once transfered into file collection
if requirements_filepath:
os.remove(requirements_filepath)
os.remove(original_definition_filepath)
os.remove(datmo_definition_filepath)
os.remove(hardware_info_filepath)
# Create new unique hash or find existing from the file collection above
Expand Down
17 changes: 17 additions & 0 deletions datmo/core/controller/environment/test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def test_create(self):
environment_obj_4 = self.environment.create(input_dict)
assert environment_obj_4.id
assert environment_obj_4.id != environment_obj_3.id
assert not os.path.isfile(definition_filepath)
assert not os.path.isfile(os.path.join(self.environment.home, "requirements.txt"))

def test_build(self):
self.project.init("test5", "test description")
Expand All @@ -129,6 +131,21 @@ def test_build(self):
# teardown
self.environment.delete(environment_obj.id)

# Test for building dockerfile when there exists not
os.remove(definition_filepath)

input_dict = {}

# Create environment in the project
environment_obj_1 = self.environment.create(input_dict)

# Build environment
result = self.environment.build(environment_obj_1.id)

assert result
# teardown
self.environment.delete(environment_obj_1.id)

def test_run(self):
self.project.init("test5", "test description")

Expand Down
37 changes: 19 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
'Topic :: Scientific/Engineering :: Artificial Intelligence'
],
install_requires=[
"future>=0.16.0",
"enum34>=1.1.6",
"sh>=1.12.11",
"glob2>=0.5",
"docker>=2.2.1",
"pyyaml>=3.12",
"requests>=2.11.1",
"prettytable>=0.7.2",
"rsfile>=2.1",
"humanfriendly>=3.6.1",
"python-slugify>=1.2.4",
"giturlparse.py>=0.0.5",
"blitzdb>=0.2.12",
"kids.cache>=0.0.7",
"pymongo>=3.6.0",
"checksumdir>=1.1.4",
"semver>=2.7.8",
"pipreqs>=0.4.9"
"future==0.16.0",
"enum34==1.1.6",
"sh==1.12.11",
"glob2==0.5",
"docker==2.2.1",
"pyyaml==3.12",
"requests==2.11.1",
"prettytable==0.7.2",
"rsfile==2.1",
"humanfriendly==3.6.1",
"python-slugify==1.2.4",
"giturlparse.py==0.0.5",
"blitzdb==0.2.12",
"kids.cache==0.0.7",
"pymongo==3.6.0",
"checksumdir==1.1.4",
"semver==2.7.8",
"pipreqs==0.4.9",
"backports.ssl-match-hostname==3.5.0.1"
],
tests_require=[
"pytest==3.0.4"
Expand Down

0 comments on commit 5aadbf6

Please sign in to comment.