pipelines icon indicating copy to clipboard operation
pipelines copied to clipboard

Add PIPELINES_ENV

Open azdolinski opened this issue 1 year ago • 6 comments

Enhance the start.sh script to recognize and utilize the PIPELINES_ENV environment variable as follows:

  • Development Mode:

    • If PIPELINES_ENV=development, execute uvicorn with the --reload option. This will streamline the development process of Python pipelines by automatically reloading the server upon code changes.
  • Production Mode:

    • If PIPELINES_ENV=production or if PIPELINES_ENV is unset or undefined, run uvicorn in its standard mode without the --reload option.

This change will accommodate both development and production environments seamlessly.

azdolinski avatar Nov 03 '24 01:11 azdolinski

is it possible to add env for uvicorn options? It could be useful to increase the number of workers like this fastapi with workers

sir3mat avatar Nov 07 '24 13:11 sir3mat

@sir3mat - yes... it should be possible... env like PIPELINES_WORKERS

based on docs - https://github.com/defunkt/unicorn/blob/master/README "unicorn can spawn and manage any number of worker processes you choose to scale to your backend." https://www.engineyard.com/blog/everything-you-need-to-know-about-unicorn/

it could be somthing like this...

if [ "$PIPELINES_ENV" = "production" ] || [ -z "$PIPELINES_ENV" ]; then
    if [ "$PIPELINES_WORKERS" = "auto" ]; then
        CPU_COUNT=$(nproc)
        WORKERS=$((2 * CPU_COUNT + 1))
    else
        WORKERS="${PIPELINES_WORKERS:-1}"
    fi
    
    uvicorn main:app --host "$HOST" --port "$PORT" --workers "$WORKERS" --forwarded-allow-ips '*'
else
    echo "INFO:     Running in development mode"
    # "workers" flag will be ignored when reloading is enabled.
    uvicorn main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' --reload
fi

i will try to check that later... but now i need also support venv for requirments and that is on my top task list

azdolinski avatar Nov 07 '24 15:11 azdolinski

New Environment Variables for start.sh

  1. PIPELINES_ENV (string)

    • Description: Specifies the environment mode in which the application should run. It typically toggles between configurations optimized for development or production. If set to any value other than "production", uvicorn will be configured to run with 1 worker and the --reload flag. Information about this flag can be found in the uvicorn development documentation.
    • Default Value: production
    • Default Usage: Often not set, it defaults to production mode if not explicitly defined.
  2. PIPELINES_WORKERS (number|auto)

    • Description: Determines the number of worker processes to handle tasks. It helps in managing parallel processes to optimize resource usage.
    • Default Value: uvicorn starts by default only with 1 worker.
    • Default Usage: In some setups, this might switch to auto, which calculates the ideal number of workers based on available CPU cores.
  3. PIPELINES_VENV (boolean)

    • Description: Controls whether a virtual environment should be used for executing pipelines.
    • Default Value: False
    • Example Usage: Setting this to True will ensure that the pipelines run within a specified virtual environment.
  4. PIPELINES_VENV_AUTOUPGRADE (boolean)

    • Description: Indicates if automatic upgrades should occur for pip and package dependencies defined in requirements.txt when using a virtual environment. This parameter makes sense only if you are using a permanent volume for the venv folder.
    • Default Value: False
    • Example Usage: Set to True to enable the automatic pip and package upgrade process during start.
  5. PIPELINES_VENV_PATH (os path string)

    • Description: Defines the path where the virtual environment is stored or should be created.
    • Default Value: Typically set to ${PIPELINES_DIR}/venv, aligning with the directory structure of the pipelines.
    • Example Usage: Customizing this path allows for alternate locations of the virtual environment if needed.

azdolinski avatar Nov 09 '24 00:11 azdolinski

Is it possible to enable also the "workers" params in openwebui interface?

sir3mat avatar Nov 12 '24 17:11 sir3mat

@sir3mat Pipelines is a separate, dedicated container and project. The number of pipeline workers is a parameter set at the start of the pipelines container and needs to be predefined at startup. Settings such as env parameters SHOULD NOT be influenced or driven by other projects from the outside; instead, they should be defined by the administrator during the startup process, as these env parameters impact how the entire system behaves.

azdolinski avatar Nov 12 '24 19:11 azdolinski

This is exactly the functionality I was looking for in Pipelines. It seems good practise to ensure that the pipeline dependencies are installed in a separate venv. Glad to see there is a PR, what is the status on this?

Maleya avatar Jan 29 '25 08:01 Maleya