From 940ad15ac39c0cf064b7ededbbe79f300266c7b1 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 5 Nov 2019 09:53:28 -0500 Subject: [PATCH 1/2] install prefect in base image (unless already installed) --- CHANGELOG.md | 1 + src/prefect/environments/storage/docker.py | 17 ++++++++++------- .../environments/storage/test_docker_storage.py | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fd33ec65f22..5b10c70697e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ - Add an informative version header to all Cloud client requests - [#1690](https://github.com/PrefectHQ/prefect/pull/1690) - Auto-label Flow environments when using Local storage - [#1696](https://github.com/PrefectHQ/prefect/pull/1696) - Batch upload logs to Cloud in a background thread for improved performance - [#1691](https://github.com/PrefectHQ/prefect/pull/1691) +- Attempt to install prefect in any docker image (if it is not already installed) - [#1704](https://github.com/PrefectHQ/prefect/pull/1704) ### Task Library diff --git a/src/prefect/environments/storage/docker.py b/src/prefect/environments/storage/docker.py index ef108236bab9..57cb075a01a3 100644 --- a/src/prefect/environments/storage/docker.py +++ b/src/prefect/environments/storage/docker.py @@ -102,17 +102,20 @@ def __init__( else: # create an image from python:*-slim directly self.base_image = "python:{}-slim".format(python_version) - self.extra_commands.extend( - [ - "apt update && apt install -y gcc git && rm -rf /var/lib/apt/lists/*", - "pip install git+https://github.com/PrefectHQ/prefect.git@{}#egg=prefect[kubernetes]".format( - self.prefect_version - ), - ] + self.extra_commands.append( + "apt update && apt install -y gcc git && rm -rf /var/lib/apt/lists/*", ) else: self.base_image = base_image + # we should always try to install prefect, unless it is already installed. We can't determine this until + # image build time. + self.extra_commands.append( + "pip show prefect || pip install git+https://github.com/PrefectHQ/prefect.git@{}#egg=prefect[kubernetes]".format( + self.prefect_version + ), + ) + not_absolute = [ file_path for file_path in self.files if not os.path.isabs(file_path) ] diff --git a/tests/environments/storage/test_docker_storage.py b/tests/environments/storage/test_docker_storage.py index 3ab72d83f5a6..37ec585353e2 100644 --- a/tests/environments/storage/test_docker_storage.py +++ b/tests/environments/storage/test_docker_storage.py @@ -316,7 +316,7 @@ def test_create_dockerfile_from_base_image(): "master", ( "FROM python:3.6-slim", - "pip install git+https://github.com/PrefectHQ/prefect.git@master", + "pip show prefect || pip install git+https://github.com/PrefectHQ/prefect.git@master", ), ), ( @@ -324,7 +324,7 @@ def test_create_dockerfile_from_base_image(): ( "FROM python:3.6-slim", "apt update && apt install -y gcc git && rm -rf /var/lib/apt/lists/*", - "pip install git+https://github.com/PrefectHQ/prefect.git@424be6b5ed8d3be85064de4b95b5c3d7cb665510#egg=prefect[kubernetes]", + "pip show prefect || pip install git+https://github.com/PrefectHQ/prefect.git@424be6b5ed8d3be85064de4b95b5c3d7cb665510#egg=prefect[kubernetes]", ), ), ], From 04d5a7348d54ac15de43c1ce89cc919e83a78a14 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 5 Nov 2019 10:28:18 -0500 Subject: [PATCH 2/2] move changelog message to fixes --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e47accded30..c1706129e11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,6 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ - Add an informative version header to all Cloud client requests - [#1690](https://github.com/PrefectHQ/prefect/pull/1690) - Auto-label Flow environments when using Local storage - [#1696](https://github.com/PrefectHQ/prefect/pull/1696) - Batch upload logs to Cloud in a background thread for improved performance - [#1691](https://github.com/PrefectHQ/prefect/pull/1691) -- Attempt to install prefect in any docker image (if it is not already installed) - [#1704](https://github.com/PrefectHQ/prefect/pull/1704) - Include agent labels within each flow's configuration environment - [#1671](https://github.com/PrefectHQ/prefect/issues/1671) ### Task Library @@ -26,6 +25,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ ### Fixes - Fix Fargate Agent access defaults and environment variable support - [#1687](https://github.com/PrefectHQ/prefect/pull/1687) +- Attempt to install prefect in any docker image (if it is not already installed) - [#1704](https://github.com/PrefectHQ/prefect/pull/1704) ### Deprecations