Tony
02/19/2021, 6:59 PMflow not found
when using Docker storage, but having mixed results.
I’m working on a CICD script for any arbitrary repo to loop through a directory of flow files, build container storage (can be many containers or a single one, i’m fine with either), and then register them. It starts by copying and building my repo into a container, then hopefully builds that container with all the prefect goodies, and sets the run_config
:
image_name = f"{git_repo}/prefect-{Path(flow_file).stem.lower()}"
image_tag = f"githash-{git_commit}"
# built by cicd agent
base_image = f"{REGISTRY_URL}/{git_repo}/flows:{image_tag}"
# second image built
base_image_plus_prefect = f"{REGISTRY_URL}/{image_name}:{image_tag}"
flow.storage = Docker(
registry_url=REGISTRY_URL,
base_image=base_image,
image_name=image_name,
image_tag=image_tag,
env_vars=fetch_env_vars(os.environ["GIT_BRANCH"]),
# here be the trouble
# same path as my Dockerfile???
path=f"/repo/{flow_file}",
stored_as_script=True,
)
flow.storage.build()
flow.run_config = DockerRun(
image=base_image_plus_prefect,
labels=fetch_agent_labels(os.environ["GIT_BRANCH"]),
)
... cicd stuff ...
flow.register()
I’m getting: ValueError('Flow is not contained in this Storage')
when running this currently.
First option I see is specifying Docker(…, files={…})
yet some repos might have dozens or hundreds of extra files that they need to include, any chance files
takes in wildcard pathing?
Second option I see is [multi-flow storage], but then I run into CICD problems:
File "/opt/prefect/healthcheck.py", line 151, in <module>
flows = cloudpickle_deserialization_check(flow_file_paths)
File "/opt/prefect/healthcheck.py", line 44, in cloudpickle_deserialization_check
flows.append(cloudpickle.loads(flow_bytes))
ModuleNotFoundError: No module named 'flows.<my flow name>'
Anyone have some better ideas?Zanie
Zanie
files
can take a folder so you can copy a bunch of files that way. For wildcarding you'd need to traverse the tree yourself.Zanie
Tony
02/19/2021, 7:09 PMDocker
I have that’s resulting in the ValueError()
?Zanie
LocalStorage
that points to the path it each flow and a DockerRun
using that single base image.Zanie
Zanie
flow.storage.build()
before storage.add_flow(flow)
has been calledZanie
flow.register
to build the storage for you, it takes care of adding the flow to the storage.Tony
03/02/2021, 2:03 PMflow.register()
it's not possible 😞Zanie
flow.storage.add_flow(flow)
before build()
🙂Tony
03/02/2021, 4:20 PMprefect execute flow-run
. Can you help me understand what flow-run
is here? I pulled down the container that prefect "created" and can get python my_flow.py
to run, but can't seem to get it to run this execute thing:
root@c8ece762e0cf:/repo# prefect execute flow-run
Not currently executing a flow within a Cloud context.
Traceback (most recent call last):
File "/usr/local/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/cli/execute.py", line 37, in flow_run
raise Exception("Not currently executing a flow within a Cloud context.")
Exception: Not currently executing a flow within a Cloud context.
Zanie
Agent
when it creates the container (using environment variables PREFECT__CONTEXT__FLOW_RUN_ID...
)Zanie
DockerAgent
and the UI or the create_flow_run
mutation to run the stored flow. I would not recommend downloading the generated container and trying to run the flow manually.