Skip to content

Commit

Permalink
Merge pull request #1010 from PrefectHQ/docker-version
Browse files Browse the repository at this point in the history
Docker prefect version
  • Loading branch information
cicdw committed May 8, 2019
2 parents 2926d4f + 3115528 commit da57dd1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/

### Enhancements

- None
- Add `prefect_version` kwarg to `Docker` storage for controlling the version of prefect installed into your containers - [#1010](https://github.com/PrefectHQ/prefect/pull/1010)

### Task Library

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ click >= 7.0, < 8.0
cloudpickle >= 0.6.0, < 0.7
croniter >= 0.3, < 0.4
cryptography >= 2.2.2, < 3.0
dask >= 0.18, < 2.0
dask >= 0.18, < 1.2.2
distributed >= 1.26.1, < 2.0
docker >= 3.4.1, < 4.0
idna < 2.8, >= 2.5
Expand Down
7 changes: 6 additions & 1 deletion src/prefect/environments/storage/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Docker(Storage):
- env_vars (dict, optional): a dictionary of environment variables to use when building
- files (dict, optional): a dictionary of files to copy into the image when building
- base_url: (str, optional): a URL of a Docker daemon to use when for Docker related functionality
- prefect_version (str, optional): an optional branch, tag, or commit specifying the version of prefect
you want installed into the container; defaults to `"0.5.3"`
"""

def __init__(
Expand All @@ -48,6 +50,7 @@ def __init__(
env_vars: dict = None,
files: dict = None,
base_url: str = "unix://var/run/docker.sock",
prefect_version: str = None,
) -> None:
self.registry_url = registry_url
self.base_image = base_image
Expand All @@ -59,6 +62,7 @@ def __init__(
self.flows = dict() # type: Dict[str, str]
self._flows = dict() # type: Dict[str, "prefect.core.flow.Flow"]
self.base_url = base_url
self.prefect_version = prefect_version or "0.5.3"

not_absolute = [
file_path for file_path in self.files if not os.path.isabs(file_path)
Expand Down Expand Up @@ -334,7 +338,7 @@ def create_dockerfile_object(self, directory: str = None) -> None:
ENV PREFECT__USER_CONFIG_PATH="/root/.prefect/config.toml"
{env_vars}
RUN pip install git+https://github.com/PrefectHQ/prefect.git@master#egg=prefect[kubernetes]
RUN pip install git+https://github.com/PrefectHQ/prefect.git@{version}#egg=prefect[kubernetes]
# RUN pip install prefect
RUN python /root/.prefect/healthcheck.py
Expand All @@ -344,6 +348,7 @@ def create_dockerfile_object(self, directory: str = None) -> None:
copy_flows=copy_flows,
copy_files=copy_files,
env_vars=env_vars,
version=self.prefect_version,
)
)

Expand Down
1 change: 1 addition & 0 deletions src/prefect/serialization/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Meta:
image_name = fields.String(allow_none=True)
image_tag = fields.String(allow_none=True)
flows = fields.Dict(key=fields.Str(), values=fields.Str())
prefect_version = fields.String(allow_none=False)

@post_load
def create_object(self, data: dict) -> Docker:
Expand Down
15 changes: 15 additions & 0 deletions tests/environments/storage/test_docker_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_empty_docker_storage():
assert not storage.python_dependencies
assert not storage.env_vars
assert not storage.files
assert storage.prefect_version == "0.5.3"
assert storage.base_url == "unix://var/run/docker.sock"


Expand All @@ -53,6 +54,7 @@ def test_empty_docker_storage():
image_tag="test5",
env_vars={"test": "1"},
base_url="test_url",
prefect_version="master",
)

assert storage.registry_url == "test1"
Expand All @@ -62,6 +64,7 @@ def test_empty_docker_storage():
assert storage.python_dependencies == ["test"]
assert storage.env_vars == {"test": "1"}
assert storage.base_url == "test_url"
assert storage.prefect_version == "master"


def test_files_not_absolute_path():
Expand Down Expand Up @@ -185,6 +188,18 @@ def test_create_dockerfile_from_base_image():
assert "FROM python:3.6" in output


def test_create_dockerfile_from_prefect_version():
storage = Docker(prefect_version="master")

with tempfile.TemporaryDirectory() as tempdir:
storage.create_dockerfile_object(directory=tempdir)

with open(os.path.join(tempdir, "Dockerfile"), "r") as dockerfile:
output = dockerfile.read()

assert "prefect.git@master" in output


def test_create_dockerfile_with_weird_flow_name():
with tempfile.TemporaryDirectory() as tempdir_outside:

Expand Down
6 changes: 5 additions & 1 deletion tests/serialization/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_docker_empty_serialize():

assert serialized
assert serialized["__version__"] == prefect.__version__
assert "prefect_version" in serialized
assert not serialized["image_name"]
assert not serialized["image_tag"]
assert not serialized["registry_url"]
Expand All @@ -48,7 +49,9 @@ def test_memory_roundtrip():


def test_docker_full_serialize():
docker = storage.Docker(registry_url="url", image_name="name", image_tag="tag")
docker = storage.Docker(
registry_url="url", image_name="name", image_tag="tag", prefect_version="0.5.2"
)
serialized = DockerSchema().dump(docker)

assert serialized
Expand All @@ -57,6 +60,7 @@ def test_docker_full_serialize():
assert serialized["image_tag"] == "tag"
assert serialized["registry_url"] == "url"
assert serialized["flows"] == dict()
assert serialized["prefect_version"] == "0.5.2"


def test_docker_serialize_with_flows():
Expand Down

0 comments on commit da57dd1

Please sign in to comment.