Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PIPELINES_ENV #316

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add PIPELINES_ENV #316

wants to merge 6 commits into from

Conversation

azdolinski
Copy link
Contributor

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.

Add option run in ENV=development mode
@sir3mat
Copy link

sir3mat commented Nov 7, 2024

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

@azdolinski
Copy link
Contributor Author

@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

add support env:
PIPELINES_VENV 
PIPELINES_VENV_AUTOUPGRADE
PIPELINES_VENV_PATH
+
PIPELINES_WORKERS
@azdolinski
Copy link
Contributor Author

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.

@sir3mat
Copy link

sir3mat commented Nov 12, 2024

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

@azdolinski
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants