Repository: PrefectHQ/prefect

Issue:
Allow nocache option for building docker storage
## Opened from the [Prefect Public Slack Community](https://join.slack.com/t/prefect-public/shared_invite/enQtNzE5OTU3OTQwNzc1LTQ5M2FkZmQzZjI0ODg1ZTBmOTc0ZjVjYWFjMWExZDAyYzBmYjVmMTE1NTQ1Y2IxZTllOTc4MmI3NzYxMDlhYWU)

**will**: is there anyway to force prefect to not use docker cache when building flows using docker storage?

**zachary**: Hi <@U012VDP6V3N>! It doesn't look like we support that at the moment, but it definitely looks doable! Let me open an issue for that.

**zachary**: <@ULVA73B9P> open "Allow nocache option for building docker storage"

Original thread can be found [here](https://prefect-community.slack.com/archives/CL09KU1K7/p1590510689004100?thread_ts=1590510689.004100&cid=CL09KU1K7).




Discussion:

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
@@ -67,10 +67,12 @@ class Docker(Storage):
             are included.
         - secrets (List[str], optional): a list of Prefect Secrets which will be used to populate `prefect.context`
             for each flow run.  Used primarily for providing authentication credentials.
-        - base_url: (str, optional): a URL of a Docker daemon to use when for
+        - base_url (str, optional): a URL of a Docker daemon to use when for
             Docker related functionality.  Defaults to DOCKER_HOST env var if not set
-        - tls_config: (Union[bool, docker.tls.TLSConfig], optional): a TLS configuration to pass to the Docker
-            client. https://docker-py.readthedocs.io/en/stable/tls.html#docker.tls.TLSConfig
+        - tls_config (Union[bool, docker.tls.TLSConfig], optional): a TLS configuration to pass to the Docker
+            client. [Documentation](https://docker-py.readthedocs.io/en/stable/tls.html#docker.tls.TLSConfig)
+        - build_kwargs (dict, optional): Additional keyword arguments to pass to Docker's build step.
+            [Documentation](https://docker-py.readthedocs.io/en/stable/api.html#docker.api.build.BuildApiMixin.build)
 
     Raises:
         - ValueError: if both `base_image` and `dockerfile` are provided
@@ -93,6 +95,7 @@ def __init__(
         secrets: List[str] = None,
         base_url: str = None,
         tls_config: Union[bool, "docker.tls.TLSConfig"] = False,
+        build_kwargs: dict = None,
     ) -> None:
         self.registry_url = registry_url
         if sys.platform == "win32":
@@ -118,6 +121,7 @@ def __init__(
 
         self.base_url = base_url or os.environ.get("DOCKER_HOST", default_url)
         self.tls_config = tls_config
+        self.build_kwargs = build_kwargs or {}
 
         version = prefect.__version__.split("+")
         if prefect_version is None:
@@ -344,6 +348,7 @@ def _build_image(self, push: bool = True) -> tuple:
                 dockerfile=dockerfile_path,
                 tag="{}:{}".format(full_name, self.image_tag),
                 forcerm=True,
+                **self.build_kwargs,
             )
             self._parse_generator_output(output)
 


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
@@ -75,6 +75,7 @@ def test_empty_docker_storage(monkeypatch, platform, url, no_docker_host_var):
     assert storage.prefect_version
     assert storage.base_url == url
     assert storage.tls_config == False
+    assert storage.build_kwargs == {}
     assert not storage.local_image
     assert not storage.ignore_healthchecks
 
@@ -142,6 +143,7 @@ def test_initialized_docker_storage(no_docker_host_var):
         tls_config={"tls": "here"},
         prefect_version="my-branch",
         local_image=True,
+        build_kwargs={"nocache": True},
     )
 
     assert storage.registry_url == "test1"
@@ -155,6 +157,7 @@ def test_initialized_docker_storage(no_docker_host_var):
     }
     assert storage.base_url == "test_url"
     assert storage.tls_config == {"tls": "here"}
+    assert storage.build_kwargs == {"nocache": True}
     assert storage.prefect_version == "my-branch"
     assert storage.local_image