Repository: PrefectHQ/prefect

Issue:
DockerEnvironment prefect version
Currently, `DockerEnvironment`s pull the bleeding edge version of Prefect from git, which might not agree with a user's local version, or might not be stable.  I think we should have a "prefect_version" init kwarg that (optionally) specifies a specific Prefect version to pull (defaults to pulling bleeding edge).


Discussion:
Maybe default to whatever version the user is currently running?
We currently can provide this https://github.com/PrefectHQ/prefect/blob/master/src/prefect/environments/storage/docker.py#L54 however we just don't default to user's local version
@joshmeek only question I have is: what is the "right" thing to do if someone's version is `'0.5.3+114.g35bc7ba4.dirty'` (for example).  Should I:
- default to `0.5.3`
- assume that because they are ahead of `0.5.3`, default to `master`
- some third option I'm not seeing?

Really good question. My first thought is to use the truncated version of `0.5.3`. I'm not sure of an argument in either direction but truncating feels _safer_ to me
Yea that makes sense; however, counterpoint: if someone has a `+` version, it means they necessarily installed directly from GitHub.  Which makes me think they could be utilizing some new tasks or something.  I think now that I've said that out loud I vote that particular situation defaults to `master` - what do you think?

Wait wait, there might be a third option... give me a minute.

Resolving patch:
diff --git a/src/prefect/environments/storage/docker.py b/src/prefect/environments/storage/docker.py
--- a/src/prefect/environments/storage/docker.py
+++ b/src/prefect/environments/storage/docker.py
@@ -38,7 +38,8 @@ class Docker(Storage):
         - 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"`
+            you want installed into the container; defaults to the version you are currently using or `"master"` if your version is ahead of
+            the latest tag
     """
 
     def __init__(
@@ -71,7 +72,12 @@ 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"
+
+        version = prefect.__version__.split("+")
+        if prefect_version is None:
+            self.prefect_version = "master" if len(version) > 1 else version[0]
+        else:
+            self.prefect_version = prefect_version
 
         not_absolute = [
             file_path for file_path in self.files if not os.path.isabs(file_path)


Test patch:
diff --git a/tests/environments/storage/test_docker_storage.py b/tests/environments/storage/test_docker_storage.py
--- a/tests/environments/storage/test_docker_storage.py
+++ b/tests/environments/storage/test_docker_storage.py
@@ -42,7 +42,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.prefect_version
     assert storage.base_url == "unix://var/run/docker.sock"
 
 
@@ -54,6 +54,20 @@ def test_docker_init_responds_to_python_version(monkeypatch, version_info):
     assert storage.base_image == "python:{}.{}".format(*version_info)
 
 
+@pytest.mark.parametrize(
+    "version",
+    [
+        ("0.5.3", "0.5.3"),
+        ("0.5.3+114.g35bc7ba4", "master"),
+        ("0.5.2+999.gr34343.dirty", "master"),
+    ],
+)
+def test_docker_init_responds_to_prefect_version(monkeypatch, version):
+    monkeypatch.setattr(prefect, "__version__", version[0])
+    storage = Docker()
+    assert storage.prefect_version == version[1]
+
+
 def test_initialized_docker_storage():
     storage = Docker(
         registry_url="test1",
@@ -63,7 +77,7 @@ def test_initialized_docker_storage():
         image_tag="test5",
         env_vars={"test": "1"},
         base_url="test_url",
-        prefect_version="master",
+        prefect_version="my-branch",
     )
 
     assert storage.registry_url == "test1"
@@ -73,7 +87,7 @@ def test_initialized_docker_storage():
     assert storage.python_dependencies == ["test"]
     assert storage.env_vars == {"test": "1"}
     assert storage.base_url == "test_url"
-    assert storage.prefect_version == "master"
+    assert storage.prefect_version == "my-branch"
 
 
 def test_files_not_absolute_path():