Skip to content

Commit

Permalink
fix: No module named '__prefect_loader__'
Browse files Browse the repository at this point in the history
move deployments into their own module so the flow module name can be
determined

see PrefectHQ/prefect#5984 (comment)
  • Loading branch information
tekumara committed Jul 10, 2022
1 parent 7ee8b85 commit a9c6d35
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 47 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
FROM prefecthq/prefect:2.0b8-python3.9

# used by the file-packager deployment to fetch flow
# from the remote file system using fsspec
RUN pip install s3fs

# point fsspec at minio inside the cluster
COPY config/fsspec-minio.json config/fsspec.json
ENV FSSPEC_CONFIG_DIR=/opt/prefect/config

# add flows so they can be referenced by import path
# by the orion-packager-import deployment
COPY flows flows
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ kubes-flow: export PREFECT_API_URL=http://localhost:4200/api
kubes-flow: $(venv)
docker compose build app && docker compose push app
# use minio as the s3 remote file system
set -e && . config/fsspec-env.sh && $(venv)/bin/prefect deployment create flows/kubes_flow.py
$(venv)/bin/prefect deployment inspect kubes-flow/kubes-deployment-orion-packager
$(venv)/bin/prefect deployment run kubes-flow/kubes-deployment-orion-packager
$(venv)/bin/prefect deployment inspect kubes-flow/kubes-deployment-file-packager
$(venv)/bin/prefect deployment run kubes-flow/kubes-deployment-file-packager
$(venv)/bin/prefect deployment inspect kubes-flow/kubes-deployment-orion-packager-import
$(venv)/bin/prefect deployment run kubes-flow/kubes-deployment-orion-packager-import
set -e && . config/fsspec-env.sh && $(venv)/bin/prefect deployment create flows/kubes_deployments.py
$(venv)/bin/prefect deployment ls --flow-name kubes-flow
for deployment in orion-packager orion-packager-import file-packager; do $(venv)/bin/prefect deployment run kubes-flow/$$deployment; done
$(venv)/bin/prefect flow-run ls
@echo Visit http://localhost:4200

Expand Down
42 changes: 42 additions & 0 deletions flows/kubes_deployments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from prefect.deployments import Deployment
from prefect.filesystems import RemoteFileSystem
from prefect.flow_runners import KubernetesFlowRunner
from prefect.packaging.file import FilePackager
from prefect.packaging.orion import OrionPackager
from prefect.packaging.serializers import ImportSerializer

from flows.kubes_flow import kubes_flow

# use the default packager (OrionPackager) to store the flow's source file
# as an anonymous JSON block in the Orion database. The block is encrypted.
Deployment(
name="orion-packager",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
),
)

# use the OrionPackager with the ImportSerializer to store the flow's import path
# as a JSON block in the database, for import at runtime. Requires the flow be
# baked into the the docker image.
Deployment(
name="orion-packager-import",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
),
packager=OrionPackager(serializer=ImportSerializer()),
)

# use the FilePackager to store the flow's source file in S3 using fsspec
Deployment(
name="file-packager",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
# use to read the stored flow from minio when the flow executes
env={"AWS_ACCESS_KEY_ID": "minioadmin", "AWS_SECRET_ACCESS_KEY": "minioadmin"},
),
packager=FilePackager(filesystem=RemoteFileSystem(basepath="s3://minio-flows/")),
)
40 changes: 0 additions & 40 deletions flows/kubes_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
from prefect import flow, get_run_logger
from prefect.deployments import Deployment
from prefect.filesystems import RemoteFileSystem
from prefect.flow_runners import KubernetesFlowRunner
from prefect.packaging.file import FilePackager
from prefect.packaging.orion import OrionPackager
from prefect.packaging.serializers import ImportSerializer


@flow
Expand All @@ -14,37 +8,3 @@ def kubes_flow() -> None:
# show in prefect ui
logger = get_run_logger()
logger.info("Hello Prefect UI from Kubernetes!")


# use the default packager (OrionPackager) to store the flow's source file
# as an anonymous JSON block in the Orion database. The block is encrypted.
Deployment(
name="kubes-deployment-orion-packager",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
),
)

# use the FilePackager to store the flow's source file in S3 using fsspec
Deployment(
name="kubes-deployment-file-packager",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
# use to read the stored flow from minio when the flow executes
env={"AWS_ACCESS_KEY_ID": "minioadmin", "AWS_SECRET_ACCESS_KEY": "minioadmin"},
),
packager=FilePackager(filesystem=RemoteFileSystem(basepath="s3://minio-flows/")),
)

# use the OrionPackager with the ImportSerializer to store the flow's import path
# as a JSON block in the database, for import at runtime from inside the docker image.
Deployment(
name="kubes-deployment-orion-packager-import",
flow=kubes_flow,
flow_runner=KubernetesFlowRunner(
image="orion-registry:5000/flow:latest",
),
packager=OrionPackager(serializer=ImportSerializer()),
)

0 comments on commit a9c6d35

Please sign in to comment.