jason
03/27/2024, 2:52 PMprefect.exceptions.ScriptError: Script at 'pipeline.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')After some research it seems like managed compute only supports using referenced git repos at this time. Our team uses a private bitbucket repo. Is this setup possible? Thanks!
Alexander Azzam
03/27/2024, 3:34 PMJake Kaplan
03/27/2024, 4:08 PMjason
03/27/2024, 4:10 PMJake Kaplan
03/27/2024, 5:36 PMfrom prefect import flow
from prefect.runner.storage import GitRepository
if __name__ == "__main__":
flow.from_source(
source=GitRepository(
url="your bitbucket url"
credentials={
"access_token": "..."
}
),
entrypoint="my_gh_workflow.py:repo_info",
).deploy(
name="my-first-deployment",
work_pool_name="my-managed-pool",
cron="0 1 * * *",
)
jason
03/27/2024, 8:46 PMFile "/Users/jasonwilson/Library/Caches/pypoetry/virtualenvs/ml-analytics-dev-MZJlIWH2-py3.12/lib/python3.12/site-packages/prefect/deployments/runner.py", line 876, in deploy
await deployment.apply(image=image_ref, work_pool_name=work_pool_name)
File "/Users/jasonwilson/Library/Caches/pypoetry/virtualenvs/ml-analytics-dev-MZJlIWH2-py3.12/lib/python3.12/site-packages/prefect/deployments/runner.py", line 272, in apply
[self.storage.to_pull_step()] if self.storage else []
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jasonwilson/Library/Caches/pypoetry/virtualenvs/ml-analytics-dev-MZJlIWH2-py3.12/lib/python3.12/site-packages/prefect/runner/storage.py", line 550, in to_pull_step
raise BlockNotSavedError(
prefect.blocks.core.BlockNotSavedError: Block must be saved withCode:before it can be converted to a pull step..save()
if name == "__main__":
flow.from_source(
source=BitBucketRepository(
repository="https://bitbucket.org/REDACTED.git",
reference="jwil/add-prefect-setup",
bitbucket_credentials = BitBucketCredentials.load("prefect-bitbucket-creds")
),
entrypoint="./workflows/src/workflows/pipeline.py:jwil_test",
).deploy(
name="jason-deploy-from-git",
work_pool_name="ManagedPrefectTestWorkPool",
cron="0 1 * * *",
)
Jake Kaplan
03/27/2024, 11:12 PMprefect-bitbucket-creds
?
if not if you run the following you'll create a block in your workspace:
BitBucketCredentials(
token="...",
username="...",
password="...",
url="...",
).save(name="prefect-bitbucket-creds")
or create one in the UI on the blocks pagejason
03/27/2024, 11:14 PMjason
03/27/2024, 11:34 PMJake Kaplan
03/27/2024, 11:42 PMJake Kaplan
03/27/2024, 11:42 PMBitBucketRepository
as well with the BitBucketCredentials
Jake Kaplan
03/27/2024, 11:46 PMmy_flow.from_source(
BitBucketRepository.load("my-bitbucket-repo"),
entrypoint="my_flow.py:my_flow"
).deploy(
name="my-first-deployment",
work_pool_name="my-modal-pool"
)
Jake Kaplan
03/27/2024, 11:47 PMjason
03/28/2024, 2:02 AMreference
param in the provided sample. When I try adding back I get:
TypeError: Flow.from_source() got an unexpected keyword argument 'reference'
Jake Kaplan
03/28/2024, 2:06 AMmian
because I typoed it 😅jason
03/28/2024, 2:08 AMjason
03/28/2024, 2:17 AMjason
03/28/2024, 2:18 AMJake Kaplan
03/28/2024, 2:20 AMJake Kaplan
03/28/2024, 2:21 AMjason
03/28/2024, 4:38 AMThe following packages are already present in the pyproject.toml and will be skipped:
- prefect-bitbucket
Jake Kaplan
03/28/2024, 1:26 PMjason
03/28/2024, 3:02 PMFlow could not be retrieved from deployment.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 154, in run_steps
step_output = await run_step(step, upstream_outputs)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 125, in run_step
result = await from_async.call_soon_in_new_thread(
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 327, in aresult
return await asyncio.wrap_future(self.future)
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 389, in _run_async
result = await coro
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/pull.py", line 182, in pull_with_block
block = await Block.load(full_slug)
File "/usr/local/lib/python3.10/site-packages/prefect/client/utilities.py", line 78, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/blocks/core.py", line 841, in load
return cls._from_block_document(block_document)
File "/usr/local/lib/python3.10/site-packages/prefect/blocks/core.py", line 634, in _from_block_document
else cls.get_block_class_from_schema(block_document.block_schema)
File "/usr/local/lib/python3.10/site-packages/prefect/blocks/core.py", line 688, in get_block_class_from_schema
return cls.get_block_class_from_key(block_schema_to_key(schema))
File "/usr/local/lib/python3.10/site-packages/prefect/blocks/core.py", line 699, in get_block_class_from_key
return lookup_type(cls, key)
File "/usr/local/lib/python3.10/site-packages/prefect/utilities/dispatch.py", line 185, in lookup_type
raise KeyError(
KeyError: "No class found for dispatch key 'bitbucket-repository' in registry for type 'Block'."
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/engine.py", line 426, in retrieve_flow_then_begin_flow_run
else await load_flow_from_flow_run(flow_run, client=client)
File "/usr/local/lib/python3.10/site-packages/prefect/client/utilities.py", line 78, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/deployments.py", line 282, in load_flow_from_flow_run
output = await run_steps(deployment.pull_steps)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 182, in run_steps
raise StepExecutionError(f"Encountered error while running {fqn}") from exc
prefect.deployments.steps.core.StepExecutionError: Encountered error while running prefect.deployments.steps.pull_with_block
081637 PM
prefect.flow_runs
INFO
Process for flow run 'adept-slug' exited cleanly.
jason
03/28/2024, 3:02 PMjason
03/28/2024, 3:03 PMJake Kaplan
03/28/2024, 3:04 PMJake Kaplan
03/28/2024, 3:04 PMprefect-bitbucket
is not installed on the container but there a ways to get it installedjason
03/28/2024, 3:05 PMJake Kaplan
03/28/2024, 3:13 PMjason
03/28/2024, 3:14 PMjason
03/28/2024, 3:43 PMjason
03/28/2024, 4:01 PMJake Kaplan
03/28/2024, 4:50 PMJake Kaplan
03/28/2024, 4:50 PMprefect deploy
and add it to your pull steps in prefect.yaml
jason
03/28/2024, 4:51 PMjason
03/28/2024, 4:51 PMJake Kaplan
03/28/2024, 5:27 PM# Welcome to your prefect.yaml file! You can use this file for storing and managing
# configuration for deploying your flows. We recommend committing this file to source
# control along with your flow code.
# Generic metadata about this project
name: myproject
prefect-version: v2.14.6
# build section allows you to manage and build docker images
build:
# push section allows you to manage if and how this project is uploaded to remote locations
push:
# pull section allows you to provide instructions for cloning this project in remote locations
pull:
- prefect.deployments.steps.git_clone:
repository: <https://bitbucket.org/jakesworkspace/myproject.git>
branch: mian
access_token: # <your-access-token>
- prefect.deployments.steps.run_shell_script:
id: install-poetry
script: pip install poetry
- prefect.deployments.steps.run_shell_script:
id: install-dependencies
script: # your poetry command here
# the deployments section allows you to provide configuration for deploying flows
deployments:
- name: my-bitbucket-deploy
version:
tags: []
description:
entrypoint: my_flow.py:my_bitbucket_flow
parameters: {}
work_pool:
name: my-managed-pool
work_queue_name:
job_variables: {}
schedule:
Jake Kaplan
03/28/2024, 5:27 PMprefect deploy
you should see those pull steps on your deploymentJake Kaplan
03/28/2024, 5:29 PMjason
03/28/2024, 5:40 PMjason
03/28/2024, 6:16 PM- prefect.deployments.steps.git_clone:
repository: https://bitbucket.org/REDACTED.git
branch: jwil-add-prefect-setup
credentials: "{{ prefect.blocks.bitbucket-credentials.prefect-bitbucket-creds }}"
jason
03/28/2024, 6:30 PMFlow could not be retrieved from deployment.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 154, in run_steps
step_output = await run_step(step, upstream_outputs)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 125, in run_step
result = await from_async.call_soon_in_new_thread(
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 327, in aresult
return await asyncio.wrap_future(self.future)
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 352, in _run_sync
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 259, in coroutine_wrapper
return call()
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 432, in call
return self.result()
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 318, in result
return self.future.result(timeout=timeout)
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 179, in result
return self.__get_result()
File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/usr/local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 389, in _run_async
result = await coro
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/pull.py", line 123, in git_clone
await storage.pull_code()
File "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 233, in pull_code
await self._clone_repo()
File "/usr/local/lib/python3.10/site-packages/prefect/runner/storage.py", line 261, in _clone_repo
raise RuntimeError(
RuntimeError: Failed to clone repository 'https://bitbucket.org/redacted.git' with exit code 128.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/prefect/engine.py", line 426, in retrieve_flow_then_begin_flow_run
else await load_flow_from_flow_run(flow_run, client=client)
File "/usr/local/lib/python3.10/site-packages/prefect/client/utilities.py", line 78, in with_injected_client
return await fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/deployments.py", line 282, in load_flow_from_flow_run
output = await run_steps(deployment.pull_steps)
File "/usr/local/lib/python3.10/site-packages/prefect/deployments/steps/core.py", line 182, in run_steps
raise StepExecutionError(f"Encountered error while running {fqn}") from exc
prefect.deployments.steps.core.StepExecutionError: Encountered error while running prefect.deployments.steps.git_clone
122855 PM
prefect.flow_runs
INFO
Process for flow run 'illustrious-whippet' exited cleanly.
jason
03/28/2024, 6:31 PMJake Kaplan
03/28/2024, 6:44 PM- prefect.deployments.steps.git_clone:
repository: <https://bitbucket.org/jakesworkspace/myproject.git>
branch: mian
credentials: "{{ prefect.blocks.bitbucket-credentials.bitbucket-creds }}"
and the access token directly:
- prefect.deployments.steps.git_clone:
repository: <https://bitbucket.org/jakesworkspace/myproject.git>
branch: mian
access_token: "{{ prefect.blocks.bitbucket-credentials.bitbucket-creds.token }}"
Jake Kaplan
03/28/2024, 6:44 PMjason
03/28/2024, 6:44 PMJake Kaplan
03/28/2024, 6:45 PMjason
03/28/2024, 6:45 PMmian
?Jake Kaplan
03/28/2024, 6:45 PMJake Kaplan
03/28/2024, 6:45 PMjason
03/28/2024, 6:48 PMJake Kaplan
03/28/2024, 6:49 PMJake Kaplan
03/28/2024, 6:49 PMjason
03/28/2024, 6:50 PMjason
03/28/2024, 6:51 PMjason
03/28/2024, 6:59 PMjason
03/28/2024, 7:00 PMjason
03/28/2024, 7:01 PMjason
03/28/2024, 7:03 PMjason
03/28/2024, 7:05 PMPoetry could not find a pyproject.toml file in /opt/prefect or its parents
Jake Kaplan
03/28/2024, 7:09 PM/opt/prefect
I think is the current dir, so your poetry command should reference the cloned repo inside of that.
for example how it's done w/ the pip install step:
pull:
- prefect.deployments.steps.git_clone:
id: clone-step # needed in order to be referenced in subsequent steps
repository: <https://github.com/org/repo.git>
- prefect.deployments.steps.pip_install_requirements:
directory: {{ clone-step.directory }} # `clone-step` is a user-provided `id` field
requirements_file: requirements.txt
Jake Kaplan
03/28/2024, 7:10 PMJake Kaplan
03/28/2024, 7:11 PMjason
03/28/2024, 7:11 PMjason
03/28/2024, 7:21 PM- prefect.deployments.steps.run_shell_script:
directory: "{{ clone-step.directory }}/workflows/src"
id: install-dependencies
script: poetry installThis is evaluating to just "workflows/src", no directory prefix. Does that look correct?
jason
03/28/2024, 7:21 PMJake Kaplan
03/28/2024, 7:25 PMJake Kaplan
03/28/2024, 7:26 PM- prefect.deployments.steps.git_clone:
id: clone-step
Jake Kaplan
03/28/2024, 7:26 PM{{ clone-step.directory }}
can resolve correctlyjason
03/28/2024, 7:26 PMJake Kaplan
03/28/2024, 7:27 PMjason
03/28/2024, 7:41 PMFailed due to a- The configured memory limit was reached during the flow run, causing a non-zero status code.RuntimeError
jason
03/28/2024, 7:42 PMJake Kaplan
03/28/2024, 7:48 PMJake Kaplan
03/28/2024, 7:49 PMjason
03/28/2024, 7:51 PMjason
03/28/2024, 7:55 PMJake Kaplan
03/28/2024, 8:30 PMmanaged_pool
- prefect takes care of both the deployment and execution of your code (inside of prefect cloud)
• push_pool
- prefect cloud is handling the deployment (by creating runs in your infra). your infra handles code execution.
• hybrid_pools
- you run a worker in your infra env to poll for work to deploy. your infra handles code execution.
depending on what you choose it might translate to less scrutiny.
• heres a guide for getting started with push pools
• and for using a hybrid pool with a worker