Zheng Xie
12/02/2021, 10:52 AMprefect register --project yourproject -p yourflow.py
It seems that perfect creates a tmp{randomNumber}
folder and puts healthcheck.py and a Dockerfile, which participate the docker build.
But I accidentally deleted the tmp
folder, even after I recovered it, it still throws the following error. What happened was that Prefect expected a tmp
folder with a new random_number as the suffix. How can I recover from it?
https://stackoverflow.com/questions/70198040/error-in-prefect-when-build-docker-image-what-triggers-prefect-to-create-the-tmAnna Geller
from prefect.storage import Docker
Docker(ignore_healthchecks=True)
In general, it looks like you run the registration itself in a Docker container, and this is why the health checks are failing. The registration step is building an image and right now you are building Docker images from a Docker container rather than from a local process. You could in theory solve it with docker.sock, but there is a much easier way.
You can create a virtual environment for the registration process. Within that environment, you can register all flows at once using CLI rather than doing that with a custom code:
prefect register --project yourproject -p /path/to/flows/dir/
All flows in the dir
directory, will then be registered one by one, and for each of them, Prefect will build its own Docker image.Zheng Xie
12/02/2021, 11:37 AMStep 10/10 : COPY ./tmpl5xqtl1e/healthcheck.py /opt/prefect/healthcheck.py
), while I have deleted that previoud tmp folder and seems this triggers Prefect to create a random number to append after “tmp” to use as the folder name.
I call register
from Mac terminal in the virtual env of the Python project. There is no “register” called in the flow.py file.
I can’t figure out how I build the image inside of the container. Thus looking for some clue.
This is the structure of my flow.py file
with Flow("My First Flow") as flow:
# steps of the flow
flow.storage = Docker(registry_url="<http://de.icr.io/cogssm-dev/|de.icr.io/cogssm-dev/>", image_name="train_flow", dockerfile="./Dockerfile", ignore_healthchecks=True)
flow.storage.build()
This is my .dockerfile
FROM prefecthq/prefect:0.7.1-python3.7
WORKDIR /app
ADD . .
RUN pip install --no-cache-dir -r requirements.txt
Then in the CLI, I do:
prefect register --project yourproject -p yourflow.pyAnna Geller
flow.storage.build()
#2 Where did you get this line from? Could it be that it’s from some old tutorial? Prefect is by now in version 0.15.9 and this image is using a very old version.
FROM prefecthq/prefect:0.7.1-python3.7
So it would be better to use e.g.:
FROM prefecthq/prefect:0.15.9-python3.9
Then, you could use:
prefect register --project yourproject -p yourflow.py
Anna Geller
Zheng Xie
12/02/2021, 11:48 AMFROM prefecthq/prefect:0.15.9-python3.7
would it be ok for the latest Prefect with python 3.7?Anna Geller
Zheng Xie
12/02/2021, 12:17 PMZheng Xie
12/02/2021, 12:20 PMAnna Geller
UserWarning: Could not import the lzma module.
Can you share your flow file and Dockerfile? you can share it via DM to keep it private. It looks like the COPY command failed in the build. What files are you trying to copy to the image? I know you meant tmp folder, but maybe you can make it more explicit in your Dockerfile and only COPY or ADD things that are relevant for your flow?
In general, the Docker storage build typically fails when there is something in your flow that cannot be serialized with cloudpickle - can it be you use some database connection or HTTP client outside of a @task?Zheng Xie
12/02/2021, 12:34 PMZheng Xie
12/02/2021, 12:35 PMAnna Geller
RUN pip show prefect || pip install git+<https://github.com/PrefectHQ/prefect.git@0.15.6#egg=prefect[all_orchestration_extras]>
RUN mkdir -p /opt/prefect/
COPY ./tmpctfg2vxw/healthcheck.py /opt/prefect/healthcheck.py
RUN python /opt/prefect/healthcheck.py '[]' '(3, 7)'
The Docker image already has all extras afaik, so no need to install it explicitly. The /opt/prefect will be created automatically too. And those healthchecks don’t need to be set in the Dockerfile.
Btw, this Dockerfile still uses Prefect 0.7.1. Can you perhaps remove all the tmp files and try this Dockerfile? I included all your custom logic:
FROM prefecthq/prefect:0.15.9-python3.7
RUN /usr/local/bin/python -m pip install --upgrade pip
WORKDIR /opt/prefect
COPY your_project_directory_with_only_relevant_files/ /opt/prefect/your_project_directory_with_only_relevant_files/
COPY requirements.txt .
RUN pip install -r requirements.txt
ENV PREFECT__USER_CONFIG_PATH='/opt/prefect/config.toml'
Zheng Xie
12/02/2021, 2:59 PMFROM prefecthq/prefect:0.15.6-python3.7
WORKDIR /app
ADD . .
RUN pip install --no-cache-dir -r requirements.txt
I don’t need any of the following 7 steps as seen in the output of the “register” command.
Where these steps come from?
The “tmp” folder in the zip file was not my files, I think Prefect created it.
It used to work, i could build the image and upload the image to container registry, until I deleted the “tmp” folder.Zheng Xie
12/02/2021, 3:00 PMAnna Geller
docker build -t yourimage .
Zheng Xie
12/02/2021, 3:47 PMdocker build -t yourimage .
There are only my 4 steps in the output.
But when run
prefect register --project yourproject -p yourflow.py
there are 11 steps in the output.Zheng Xie
12/02/2021, 3:48 PMAnna Geller