Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Local Images for Docker Storage #1052

Merged
merged 3 commits into from May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/
- Allow for `SlackTask` to pull the Slack webhook URL from a custom named Secret - [#1023](https://github.com/PrefectHQ/prefect/pull/1023)
- Raise informative errors when Docker storage push / pull fails - [#1029](https://github.com/PrefectHQ/prefect/issues/1029)
- Standardized `__repr__`s for various classes, to remove inconsistencies - [#617](https://github.com/PrefectHQ/prefect/issues/617)
- Allow for use of local images in Docekr storage - [#1052](https://github.com/PrefectHQ/prefect/pull/1052)

### Task Library

Expand Down
5 changes: 4 additions & 1 deletion src/prefect/environments/storage/docker.py
Expand Up @@ -40,6 +40,7 @@ class Docker(Storage):
- prefect_version (str, optional): an optional branch, tag, or commit specifying the version of prefect
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
- local_image(bool, optional): an optional flag whether or not to use a local docker image, if True then a pull will not be attempted
"""

def __init__(
Expand All @@ -53,6 +54,7 @@ def __init__(
files: dict = None,
base_url: str = "unix://var/run/docker.sock",
prefect_version: str = None,
local_image: bool = False,
) -> None:
self.registry_url = registry_url

Expand All @@ -72,6 +74,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.local_image = local_image

version = prefect.__version__.split("+")
if prefect_version is None:
Expand Down Expand Up @@ -214,7 +217,7 @@ def build_image(self, push: bool = True) -> tuple:
with tempfile.TemporaryDirectory() as tempdir:

# Build the dockerfile
if self.base_image:
if self.base_image and not self.local_image:
self.pull_image()

self.create_dockerfile_object(directory=tempdir)
Expand Down
3 changes: 3 additions & 0 deletions tests/environments/storage/test_docker_storage.py
Expand Up @@ -44,6 +44,7 @@ def test_empty_docker_storage():
assert not storage.files
assert storage.prefect_version
assert storage.base_url == "unix://var/run/docker.sock"
assert not storage.local_image


@pytest.mark.parametrize("version_info", [(3, 5), (3, 6), (3, 7)])
Expand Down Expand Up @@ -78,6 +79,7 @@ def test_initialized_docker_storage():
env_vars={"test": "1"},
base_url="test_url",
prefect_version="my-branch",
local_image=True,
)

assert storage.registry_url == "test1"
Expand All @@ -88,6 +90,7 @@ def test_initialized_docker_storage():
assert storage.env_vars == {"test": "1"}
assert storage.base_url == "test_url"
assert storage.prefect_version == "my-branch"
assert storage.local_image


def test_files_not_absolute_path():
Expand Down