Patrick Alves
01/14/2022, 2:01 PMimport prefect
from prefect import Flow, task
from prefect.run_configs import DockerRun
from prefect.storage import Docker
logger = prefect.context.get("logger")
@task
def task01():
<http://logger.info|logger.info>("Task 01")
@task
def task02():
<http://logger.info|logger.info>("Task 02")
@task
def task03():
<http://logger.info|logger.info>("Task 03")
with Flow("Check Computers",
storage=Docker(dockerfile="Dockerfile", image_name="check_computers", image_tag="latest"),
run_config=DockerRun(image="check_computers:latest")) as flow:
task01()
task02()
task03()
# Register the flow under the "tutorial" project
flow.register(project_name="CIS")
Then, in the logs I've got: Failed to load and execute Flow's environment: FileNotFoundError(2, 'No such file or directory')
Does anyone know what I am missing?Anna Geller
import prefect
from prefect import Flow, task
from prefect.run_configs import DockerRun
from prefect.storage import Docker
@task
def task01():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Task 01")
@task
def task02():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Task 02")
@task
def task03():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Task 03")
2) Specifying an explicit path to the Dockerfile may help as well.
3) Make sure your Server has Prefect version which is >= registration environment
4) Adding label to your agent may help to make it more explicit as well:
run_config=DockerRun(image="check_computers:latest", labels=["docker"],),
5) Check if your flow uses some custom modules and if so, make sure those are copied into or installed within the image.
If you tried all that and none of this helped, you can share your Dockerfile and the output of “prefect diagnostics” and I will try to reproduce.Patrick Alves
01/14/2022, 3:17 PMPatrick Alves
01/14/2022, 3:21 PMFROM python:3.8-slim
WORKDIR /app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE=true
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir --prefer-binary -r /tmp/requirements.txt \
&& find / -name *.pyc -delete
# Copy all files
COPY . .
Do I need to add a CMD command to run the flow?
ex: CMD _[_ "python"_,_ "flow.py" _]_
Patrick Alves
01/14/2022, 3:25 PMAnna Geller
Anna Geller
Patrick Alves
01/14/2022, 3:26 PMPatrick Alves
01/14/2022, 3:27 PMAlso, you can register using the CLI “prefect register --project xxx -p flow.py” so you don’t need to have it in the flow file@Anna Geller, In that case, should I add a
flow.run()
in the flow.py?Anna Geller