Hello, I'm following this <guide> to connect prefe...
# ask-community
r
Hello, I'm following this guide to connect prefect to Google Cloud Run using github actions. When i follow the guide everything works well, but when copy-paste the actions to my repository i need to update the dockerfile to build it
FROM prefecthq/prefect:2-python3.10-conda
(I need a conda env to install all the deps my code need). My Dockerfile is:
Copy code
FROM prefecthq/prefect:2-python3.10-conda

COPY environment.yml .
COPY requirements.txt .
COPY setup.cfg .
COPY setup.py .
COPY my-logic .

RUN apt-get update && apt-get install -y libarchive13
RUN conda install -c conda-forge mamba
RUN mamba env update --prefix /opt/conda/envs/prefect -f environment.yml
RUN pip install --upgrade pip setuptools --no-cache-dir
RUN pip install --trusted-host <http://pypi.python.org|pypi.python.org> --no-cache-dir .

ARG PREFECT_API_KEY
ENV PREFECT_API_KEY=$PREFECT_API_KEY

ARG PREFECT_API_URL
ENV PREFECT_API_URL=$PREFECT_API_URL

ENV PYTHONUNBUFFERED True

COPY flows/ /opt/prefect/flows/

ENTRYPOINT ["/bin/bash", "--login", "-c", "prefect agent start -q default"]
The action build goes well, but when i run the deploy from prefect cloud, the VM on GCP creates the job in CloudRun but it returns
/opt/conda/bin/python: Error while finding module specification for 'prefect.engine' (ModuleNotFoundError: No module named 'prefect')
What I'm doing wrong? I still do not understand if I have to change also the
action/deploy-flows/action.yml
to make it create a conda env; in any case I tried both and nothing changed. The modified action.yml is
Copy code
runs:
  using: "composite"
  steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.10
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.10'
    - name: Install dependencies
      shell: bash
        python-version: "${{ inputs.python_version }}"
        cache: 'pip'

    - id: install-myenv
      run: |
        conda install -c conda-forge mamba
        mamba env update --file environment.yml
        ${{ inputs.install_command }}
      shell: bash

    - id: login-prefect
      run: |

        prefect config set PREFECT_API_KEY=${{ inputs.prefect_api_key }}
        prefect config set PREFECT_API_URL=${{ inputs.prefect_api_url }}
      shell: bash
If i switch my dockerfile back to a non conda image (
FROM prefecthq/prefect:2-python3.10
), everything goes fine, but my deps are not fully covered.
z
Are you sure things are installing in the right environment?
r
the link you sent me returns a 404
z
Ah sorry I’m on a different branch
r
I'm not sure what really happens when deploying on Cloud Run, does it deploy the image built from the Dockerfile? If yes why the agent on VM runs well and the serverless does not? Do I need to only install deps into Dockerfile or also into action.yml? I have not created any new env, just updated current ones just to be sure to not create problems
Should I add this line to my dockerfile?
RUN echo "conda activate prefect" >> ~/.bashrc
z
Well are you sure when you’re updating the env that it’s running in the
prefect
one?
r
yes, this line ensures that:
RUN mamba env update --prefix /opt/conda/envs/prefect -f environment.yml
z
I see. Hm. I’m not sure what’s going on then
r
Seems like an incompatibility with conda image
Do you have some example working with conda I can explore and compare with?
I have now run the medium's tutorial code passing conda image as base image to dockerfile and it crashes. So the Dockerfile becames:
Copy code
FROM prefecthq/prefect:2-python3.10-conda

COPY requirements.txt .
COPY setup.py .
COPY prefect_utils .

RUN pip install --upgrade pip setuptools --no-cache-dir
RUN pip install --trusted-host <http://pypi.python.org|pypi.python.org> --no-cache-dir .

ARG PREFECT_API_KEY
ENV PREFECT_API_KEY=$PREFECT_API_KEY

ARG PREFECT_API_URL
ENV PREFECT_API_URL=$PREFECT_API_URL

ENV PYTHONUNBUFFERED True

COPY flows/ /opt/prefect/flows/

ENTRYPOINT ["/bin/bash", "--login", "-c", "prefect agent start -q default"]
Am I doing something wrong?