Skip to content

Commit

Permalink
Merge pull request #29 from avirshup/late_binding_base
Browse files Browse the repository at this point in the history
Fix #28 and related issues
  • Loading branch information
avirshup authored Sep 26, 2017
2 parents 9a0b73c + 969444b commit 6349612
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions dockermake/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ class MissingFileError(UserException):

class ExternalBuildError(UserException):
CODE = 48


class InvalidRequiresList(UserException):
CODE = 49
12 changes: 8 additions & 4 deletions dockermake/imagedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def generate_build(self, image, targetname, rebuilds=None):
rebuilds (List[str]): list of image layers to rebuild (i.e., without docker's cache)
"""
from_image = self.get_external_base_image(image)
if from_image is None:
raise errors.NoBaseError("No base image found in %s's dependencies" % image)
if isinstance(from_image, ExternalDockerfile):
build_first = from_image
base_image = from_image.tag
Expand Down Expand Up @@ -170,7 +172,6 @@ def sort_dependencies(self, image, dependencies=None):
return

requires = self.ymldefs[image].get('requires', [])
assert type(requires) == list, 'Requirements for %s are not a list' % image

for dep in requires:
self.sort_dependencies(dep, dependencies)
Expand Down Expand Up @@ -206,7 +207,12 @@ def get_external_base_image(self, image, stack=None):
else:
externalbase = None

for base in mydef.get('requires', []):
requires = mydef.get('requires', [])
for base in requires:
if not isinstance(requires, list):
raise errors.InvalidRequiresList('Requirements for image "%s" are not a list'
% image)

try:
otherexternal = self.get_external_base_image(base, stack)
except ValueError:
Expand All @@ -222,8 +228,6 @@ def get_external_base_image(self, image, stack=None):
' %s (FROM: %s), and\n' % (image, externalbase) +
' %s (FROM: %s).' % (base, otherexternal))

if not externalbase:
raise errors.NoBaseError("No base image found in %s's dependencies" % image)
assert stack.pop() == image
return externalbase

Expand Down
5 changes: 5 additions & 0 deletions test/data/invalid_requires.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target:
description: this build should fail because its 'requires' field is not a list
FROM: debian:jessie
requires: yabsdfa
build: z
22 changes: 22 additions & 0 deletions test/data/multibase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
base3:
FROM: continuumio/miniconda3

base2:
FROM: continuumio/miniconda

install_something:
description: "Not really java :)"
build: |
RUN mkdir -p /opt/java8
RUN touch /opt/java8/java
target3:
requires:
- install_something
FROM: continuumio/miniconda3

target2:
requires:
- install_something
- base2

3 changes: 2 additions & 1 deletion test/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
'data/unrecognized.yml': errors.UnrecognizedKeyError,
'data/nobase.yml': errors.NoBaseError,
'data/missingfile.yml': errors.MissingFileError,
'data/baddockerfile.yml': errors.ExternalBuildError
'data/baddockerfile.yml': errors.ExternalBuildError,
'data/invalid_requires.yml': errors.InvalidRequiresList,
}


Expand Down
6 changes: 6 additions & 0 deletions test/test_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import subprocess


def test_multiple_bases():
subprocess.check_call(['docker-make', '-f', 'data/multibase.yml', 'target2', 'target3'])

0 comments on commit 6349612

Please sign in to comment.