Ruben Sik
12/10/2021, 8:23 AMRuben Sik
12/10/2021, 8:32 AMFROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt ./requirements.txt
RUN pip install "prefect[azure, gitlab]"
RUN pip install -r requirements.txt
COPY . .
ENV PYTHONPATH "${PYTHONPATH}:/app"
Furthermore we are using gitlab storage and our folder structure looks like:
|__app
| └── __init__.py
| └── flows
| └── └── __init__.py
| └── └── test_flow.py
| └── └── helper_script.py
| └── └── utils
| └── └── └── __init__.py
| └── └── └── helper_script.py
| └── utils
| └── └── __init__.py
| └── └── helper_script.py
We've copied the helper_script.py to test multiple location to try various imports.
When we run os.listdir() in our flow script "test_flow.py", the logger seems to show our utils folder is in the current working directory. This os.listdir() results in [utils, flows] which should mean an import possibily of
"import utils.helper_script" (whichs works on command line of the docker image but not when running the flow via a docker agent).
Are we overlooking something?Anna Geller
setup.py
and make utils
a package. This way your package will be importable anywhere (in a virtual environment, Docker image etc) and you don’t have to manually add directories to the PYTHONPATH and it makes your code much cleaner. This post explains how to do it.
I also have an example Dockerfile and setup.py in this repo.Ruben Sik
12/10/2021, 1:37 PMAnna Geller
app
directory also on your local, right?Anna Geller
COPY app/. .
Anna Geller
/app/app/utils
so the import would have to be:
from app.app.utils import ...
Anna Geller
FROM prefecthq/prefect:0.15.10-python3.8
RUN /usr/local/bin/python -m pip install --upgrade pip
WORKDIR /opt/prefect
COPY utils/ /opt/prefect/utils/
COPY requirements.txt .
COPY setup.py .
RUN pip install .
COPY flows/ /opt/prefect/flows/
Anna Geller
stored_as_script=True
. If you wanna use this pattern, check out this exampleRuben Sik
12/10/2021, 3:02 PM