Hello. Can someone probably tell me if there is a ...
# ask-community
v
Hello. Can someone probably tell me if there is a feature to have setup task for flow to run by default before starting the flow tasks? I see that I can use add_task, but how to make it root task?
a
@Vadym Dytyniak can you just add it as a normal task that runs first? you could then specify that it should run first via task dependencies
v
Sure, but I am wondering if there is a chance to avoid adding the same task in each flow
a
if you need a setup and cleanup, you could have a look at resource manager: https://docs.prefect.io/core/idioms/resource-manager.html
k
If you don’t need observability around it, you can use a State Handler for the Flow and then create some kind of
DefaultFlow
class that contains your defaults.
v
@Kevin Kho Thanks. Will have a look. Are the async?
k
No it’s not. Async support is native in Orion though (Prefect 2.0)
v
So, Can I catch the moment before running flow task and do some setup?
k
Yeah you can. You can put whatever Python code in the state transition from Submitted to Running, which is before the tasks run. It’s just not async.
Well, you can try but I’m not confident the async will work
v
That is what I need actually
thanks
Do you have probably ubuntu16.04 based prefect images?
k
We only have the one on DockerHub. I don’t know the base OS of that.
I guess only Debian.
v
Yes. that is what we see. We have libraries that work only in Ubuntu
We are trying to build own image, but we have few issues
we installed dependencies, but still on unpickling receiving no module found
k
What is your error? Is the module a normal Python module or custom one? Or the Prefect module?
v
custom one
but we are using prefect entrypoint to install EXTRA_PIP_PACKAGES, running image locally I am able to import this library. We are not sure what command prefect is using to unpickle the flow
k
Do you have multiple Python installations in the image?
v
yes, we set python3 to use what we need (3.9), but we actually not sure what prefect is using to start the flow
k
It uses the cli command
prefect execute flow
v
@Kevin Kho Have a problem to run. Downloading flow file from s3 storage and what should be the command to run it?
a
@Vadym Dytyniak not sure I understood the question- you don't need to set any command in your Dockerfile to run your flow, Prefect does it automatically when you schedule or start a flow run. Can you share your storage and run configuration, as well as Dockerfile?
v
Storage:
Copy code
return S3(
    bucket=Secret('PREFECT_BUCKET').get(),
    key=f'{self.name}/{self.serialized_hash()}',
    secrets=['AWS_CREDENTIALS'],
)
Run config:
Copy code
ECSRun(
    image='custom_image',
    env={
        'PIP_EXTRA_INDEX_URL': os.environ['PIP_EXTRA_INDEX_URL'],
        'EXTRA_PIP_PACKAGES': ' '.join(self.dependencies),
    },
)
Custom image: FROM base image # install tini ENV TINI_VERSION v0.19.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini RUN chmod +x /tini ENTRYPOINT ["/tini", "--"] # install prefect ENV PREFECT_VERSION 0.15.10 RUN python3.9 -m pip install prefect[aws]==${PREFECT_VERSION} # update alternatives RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 10 RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 10 # prepare entrypoint script COPY prefect_entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh CMD ["entrypoint.sh"] entrypoint.sh copied from pure prefect image
@Anna Geller I don't want to run prefect execute in Dockerfile, I am trying to debug locally why this image can't start the flow
because all deps are installed
a
I would strongly recommend using an official Prefect image from Dockerhub. You shouldn’t have to add this:
Copy code
# prepare entrypoint script
COPY prefect_entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
CMD ["entrypoint.sh"]
Some additional notes: I usually see the ENV defined with = sign e.g.
Copy code
ENV PREFECT_VERSION=0.15.10
And then I think this may need to be in quotation marks (not 100% sure):
Copy code
pip install "prefect[aws]"
If you need some dependencies from this custom image, you can do a multi-stage build, and in the last part use:
Copy code
FROM prefecthq/prefect:latest
v
@Anna Geller Main problem that we have to use Ubuntu instead of Debian
a
@Vadym Dytyniak I think this contains a good answer https://stackoverflow.com/a/62414670/9509388
v
hmm, currently don't understand how this concept works. Do you see it is possible to finally have prefect installed on ubuntu?
a
yes, this should be possible for sure
v
Do you have idea how to get output of docker run command in ECS?
a
yes, you could go to CloudWatch logs. You can navigate from your ECS task directly to the logs for this task
v
The first log I see there it is "Downloading flow from s3..."
how about docker run command log?
a
it looks good then. Docker run is simply the output of whatever the container is doing. This should be the same what you see in Prefect Cloud UI.
v
But I am installing dependencies as part of docker run and I don't see these logs
a
not sure whether installing dependencies generates any specific logs.
v
We finally found the problem. We used CMD ["entrypoint.sh"] that was replaced with prefect execute flow-run during docker run
a
thanks for sharing @Vadym Dytyniak. Is everything resolved now?
v
yes, @Anna Geller and @Kevin Kho thanks for the support!
🙌 1