Skip to content

Commit

Permalink
Rename image -> base_image
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin committed Dec 12, 2018
1 parent d87e3db commit cb5ecf2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
14 changes: 8 additions & 6 deletions src/prefect/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ContainerEnvironment(Environment):
and is subject to change.
Args:
- image (str): The image to pull that is used as a base for the Docker container
- base_image (str): The image to pull that is used as a base for the Docker container
*Note*: Images must include Python 3.4+ and `pip`.
- registry_url (str, optional): The registry to push the image to
- python_dependencies (list, optional): The list of pip installable python packages
Expand All @@ -82,12 +82,12 @@ class ContainerEnvironment(Environment):

def __init__(
self,
image: str,
base_image: str,
registry_url: str = None,
python_dependencies: list = None,
secrets: list = None,
) -> None:
self.image = image
self.base_image = base_image
self.registry_url = registry_url
self.python_dependencies = python_dependencies or []
self.secrets = secrets or []
Expand Down Expand Up @@ -192,7 +192,7 @@ def pull_image(self) -> None:
the environment variables.
"""
client = docker.from_env()
client.images.pull(self.image)
client.images.pull(self.base_image)

def create_dockerfile(self, directory: str = None) -> None:
"""Creates a dockerfile to use as the container.
Expand Down Expand Up @@ -230,7 +230,7 @@ def create_dockerfile(self, directory: str = None) -> None:

file_contents = textwrap.dedent(
"""\
FROM {image}
FROM {base_image}
RUN apt-get -qq -y update && apt-get -qq -y install --no-install-recommends --no-install-suggests git
Expand All @@ -250,7 +250,9 @@ def create_dockerfile(self, directory: str = None) -> None:
RUN git clone https://$PERSONAL_ACCESS_TOKEN@github.com/PrefectHQ/prefect.git
RUN pip install ./prefect
""".format(
image=self.image, pip_installs=pip_installs, env_vars=env_vars
base_image=self.base_image,
pip_installs=pip_installs,
env_vars=env_vars,
)
)

Expand Down
2 changes: 1 addition & 1 deletion src/prefect/serialization/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContainerEnvironmentSchema(VersionedSchema):
class Meta:
object_class = prefect.environments.ContainerEnvironment

image = fields.String(required=True)
base_image = fields.String(required=True)
registry_url = fields.String(allow_none=True)
python_dependencies = fields.List(fields.String(), allow_none=True)
secrets = fields.List(fields.String(), allow_none=True)
Expand Down
13 changes: 8 additions & 5 deletions tests/serialization/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ def test_deserialize_local_environment():

def test_serialize_container_environment():
env = environments.ContainerEnvironment(
image="a", python_dependencies=["b", "c"], secrets=["d", "e"], registry_url="f"
base_image="a",
python_dependencies=["b", "c"],
secrets=["d", "e"],
registry_url="f",
)
serialized = ContainerEnvironmentSchema().dump(env)
assert serialized["image"] == "a"
assert serialized["base_image"] == "a"
assert serialized["python_dependencies"] == ["b", "c"]
assert serialized["secrets"] == ["d", "e"]
assert serialized["registry_url"] == "f"
Expand All @@ -42,7 +45,7 @@ def test_serialize_container_environment():

def test_deserialize_container_environment():
env = environments.ContainerEnvironment(
image="a", python_dependencies=["b", "c"], secrets=["d", "e"]
base_image="a", python_dependencies=["b", "c"], secrets=["d", "e"]
)
serialized = ContainerEnvironmentSchema().dump(env)
deserialized = ContainerEnvironmentSchema().load(serialized)
Expand All @@ -61,12 +64,12 @@ def test_environment_schema_with_local_environment():

def test_environment_schema_with_container_environment():
env = environments.ContainerEnvironment(
image="a", python_dependencies=["b", "c"], secrets=["d", "e"]
base_image="a", python_dependencies=["b", "c"], secrets=["d", "e"]
)
serialized = EnvironmentSchema().dump(env)
deserialized = EnvironmentSchema().load(serialized)
assert isinstance(deserialized, environments.ContainerEnvironment)
assert deserialized.python_dependencies == env.python_dependencies
assert deserialized.secrets == env.secrets
assert deserialized.registry_url == env.registry_url
assert deserialized.image == env.image
assert deserialized.base_image == env.base_image
7 changes: 5 additions & 2 deletions tests/serialization/test_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,16 @@ def test_serialize_no_environment():

def test_serialize_container_environment():
env = prefect.environments.ContainerEnvironment(
image="a", python_dependencies=["b", "c"], secrets=["d", "e"], registry_url="f"
base_image="a",
python_dependencies=["b", "c"],
secrets=["d", "e"],
registry_url="f",
)
deserialized = FlowSchema().load(FlowSchema().dump(Flow(environment=env)))
assert isinstance(
deserialized.environment, prefect.environments.ContainerEnvironment
)
assert deserialized.environment.image == env.image
assert deserialized.environment.base_image == env.base_image
assert deserialized.environment.python_dependencies == env.python_dependencies
assert deserialized.environment.secrets == env.secrets
assert deserialized.environment.registry_url == env.registry_url
Expand Down
4 changes: 2 additions & 2 deletions tests/test_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def test_environment_build_error():

class TestContainerEnvironment:
def test_create_container_environment(self):
container = ContainerEnvironment(image=None)
container = ContainerEnvironment(base_image=None)
assert container

@pytest.mark.skip("Circle will need to handle container building")
def test_build_image_process(self):

container = ContainerEnvironment(image="python:3.6", tag="tag")
container = ContainerEnvironment(base_image="python:3.6", tag="tag")
image = container.build(Flow())
assert image

Expand Down

0 comments on commit cb5ecf2

Please sign in to comment.