ploomber / soopervisor

☁️ Export Ploomber pipelines to Kubernetes (Argo), Airflow, AWS Batch, SLURM, and Kubeflow.
https://soopervisor.readthedocs.io
Apache License 2.0
45 stars 18 forks source link

problem when building docker image from requirements.lock.txt #67

Closed edublancas closed 2 years ago

edublancas commented 2 years ago

If you use conda to create your virtual env, but generate a requirements.lock.txt, you'll end up with entries like this:

pygraphviz @ file:///Users/runner/miniforge3/conda-bld/pygraphviz_1642787936965/work

That happens if pygraphviz wasn't installed via pip install but via conda install

The problem is that once you wanna generate the docker image, it'll break:

===================================================== Building image: docker build . --tag demo:latest ======================================================
[+] Building 2.8s (7/11)
 => [internal] load build definition from Dockerfile                                                                                                    0.0s
 => => transferring dockerfile: 37B                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                         0.0s
 => [internal] load metadata for docker.io/condaforge/mambaforge:4.10.1-0                                                                               0.4s
 => [internal] load build context                                                                                                                       0.0s
 => => transferring context: 276.59kB                                                                                                                   0.0s
 => [1/7] FROM docker.io/condaforge/mambaforge:4.10.1-0@sha256:0afe653d5d0af8269e221009c88f378b4d5662967114d91de6b38171985d9637                         0.0s
 => CACHED [2/7] COPY requirements.lock.txt project/requirements.lock.txt                                                                               0.0s
 => ERROR [3/7] RUN pip install --requirement project/requirements.lock.txt && rm -rf /root/.cache/pip/                                                 2.2s
------
 > [3/7] RUN pip install --requirement project/requirements.lock.txt && rm -rf /root/.cache/pip/:
#7 1.548 WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>
#7 1.548 distutils: /opt/conda/include/python3.9/UNKNOWN
#7 1.548 sysconfig: /opt/conda/include/python3.9
#7 1.549 WARNING: Additional context:
#7 1.549 user = False
#7 1.549 home = None
#7 1.549 root = None
#7 1.549 prefix = None
#7 1.746 Processing /Users/runner/miniforge3/conda-bld/pygraphviz_1642787936965/work
#7 1.748 ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/Users/runner/miniforge3/conda-bld/pygraphviz_1642787936965/work'
#7 1.748
------
executor failed running [/bin/sh -c pip install --requirement project/requirements.lock.txt && rm -rf /root/.cache/pip/]: exit code: 1

The relevant error is:

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/Users/runner/miniforge3

Docker is trying to pull the file, but it doesn't exist.

Fix: before image building, check the contents of requirements.lock.txt using a regex to see if it has the {name} @ file:{some_path}.

If so, raise an exception with an informative error and instructions to fix it.

Not sure what the informative error and instructions could be, we can discuss that.

edublancas commented 2 years ago

To reproduce:

conda create --name test-env -y
conda activate test-env

# install some package with conda that is also available via pip 
conda install pygraphviz -c conda-forge -y

pip freeze

On my laptop, it looks like this:

pygraphviz @ file:///Users/runner/miniforge3/conda-bld/pygraphviz_1642787954737/work

I think we should have a function that looks for these entries and raises an error with some meaningful message. the solution would be to ask the user to generate conda lock files - I'm still thinking what's the best error message here

for testing, we just need to generate some fake requirements.lock.txt with entries like that and then ensure the docker.build functions throws some error if it finds anything like that