langflow-ai / langflow

⛓️ Langflow is a visual framework for building multi-agent and RAG applications. It's open-source, Python-powered, fully customizable, model and vector store agnostic.
http://www.langflow.org
MIT License
20.22k stars 2.99k forks source link

I'm having issues setting up langflow through docker-compose #2377

Open chibexme opened 1 week ago

chibexme commented 1 week ago

I'm trying to deploy langflow on ubuntu staging server through docker-compose

every other services starts successful except - backend, celeryworker and flower as shown in the below screenshot.

With error message - /usr/local/bin/python: No module named langflow

Screenshot 2024-06-26 141841

when i access the frontend through the browser, i only see the loading image and javascript error as shown on the below screenshot Screenshot 2024-06-26 143020

dosubot[bot] commented 1 week ago

To resolve the issues with the backend, celeryworker, and flower services not starting due to a missing langflow module, and the frontend showing a loading image with a JavaScript error, follow these steps:

  1. Ensure langflow Module is Installed: Make sure the langflow module is installed in the Docker image used by the backend, celeryworker, and flower services. Add the installation command in the Dockerfile or the startup script.

  2. Check Dockerfile and Startup Script: Verify that the Dockerfile or the startup script used in the backend, celeryworker, and flower services includes the installation of the langflow module.

  3. Update docker-compose.yml: Ensure that the docker-compose.yml file correctly references the Docker images and paths. Here is an example configuration:

version: "3.8"
services:
  backend: &backend
    image: "ogabrielluiz/langflow:latest"
    build:
      context: ../
      dockerfile: base.Dockerfile
    depends_on:
      - db
      - broker
      - result_backend
    env_file:
      - .env
    volumes:
      - ../:/app
      - ./startup-backend.sh:/startup-backend.sh
    command: /startup-backend.sh
    healthcheck:
      test: "exit 0"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api/v1`) || PathPrefix(`/docs`) || PathPrefix(`/health`)
        - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=7860

  celeryworker:
    <<: *backend
    env_file:
      - .env
    build:
      context: ../
      dockerfile: base.Dockerfile
    command: celery -A langflow.worker.celery_app worker --loglevel=DEBUG --concurrency=1 -n lf-worker@%h
    healthcheck:
      test: "exit 0"
    deploy:
      replicas: 1

  flower:
    <<: *backend
    env_file:
      - .env
    networks:
      - default
    build:
      context: ../
      dockerfile: base.Dockerfile
    environment:
      - FLOWER_PORT=5555
    command: /bin/sh -c "celery -A langflow.worker.celery_app --broker=${BROKER_URL?Variable not set} flower --port=5555"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555

  frontend:
    image: "ogabrielluiz/langflow_frontend:latest"
    env_file:
      - .env
    build:
      context: ../src/frontend
      dockerfile: Dockerfile
      args:
        - BACKEND_URL=http://backend:7860
    restart: on-failure
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
        - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
  1. Frontend JavaScript Error: Ensure that the BACKEND_URL is correctly set in the frontend service. The error SyntaxError: Unexpected token '<' usually indicates that the frontend is trying to load an HTML page instead of a JavaScript file, often due to an incorrect backend URL.

  2. Common Installation Issues: If you encounter the error No module named 'langflow.__main__', try the following steps:

    • Run python -m langflow run instead of langflow run.
    • Reinstall Langflow with python -m pip install langflow --pre -U.
    • Reinstall Langflow and its dependencies with python -m pip install langflow --pre -U --force-reinstall.

    If you encounter the error Something went wrong running migrations. Please, run 'langflow migration --fix', clear the cache by deleting the contents of the cache folder located at:

    • Linux or WSL2 on Windows: home/<username>/.cache/langflow/
    • MacOS: /Users/<username>/Library/Caches/langflow/

    This error can occur during Langflow upgrades when the new version can't override langflow-pre.db in .cache/langflow/. Clearing the cache removes this file but will also erase your settings. Back up your files before clearing the folder if you wish to retain them [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

chibexme commented 1 week ago

@dosu, the docker-compose you got your suggestion from was last updated 9months ago, meaning that it doesn't reflect the current way of deploy langflow with docker.

I've tried your suggestions they didn't work.

dosubot[bot] commented 1 week ago

To deploy Langflow correctly using Docker Compose, you can use the following updated docker-compose.yml configuration:

version: "3.8"
services:
  proxy:
    image: traefik:v3.0
    env_file:
      - .env
    networks:
      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
      - default
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command:
      - --providers.docker
      - --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
      - --providers.docker.exposedbydefault=false
      - --accesslog
      - --log
      - --api
    deploy:
      placement:
        constraints:
          - node.role == manager
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
        - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect

  backend:
    image: "langflowai/langflow:latest"
    depends_on:
      - db
      - broker
      - result_backend
    env_file:
      - .env
    volumes:
      - ../:/app
      - ./startup-backend.sh:/startup-backend.sh
    command: /startup-backend.sh
    healthcheck:
      test: "exit 0"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api/v1`) || PathPrefix(`/docs`) || PathPrefix(`/health`)
        - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=7860

  db:
    image: postgres:15.4
    volumes:
      - app-db-data:/var/lib/postgresql/data/pgdata
    environment:
      - PGDATA=/var/lib/postgresql/data/pgdata
    deploy:
      placement:
        constraints:
          - node.labels.app-db-data == true
    healthcheck:
      test: "exit 0"
    env_file:
      - .env

  pgadmin:
    image: dpage/pgadmin4
    networks:
      - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
      - default
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    env_file:
      - .env
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-pgadmin.loadbalancer.server.port=5050

  result_backend:
    image: redis:6.2.5
    env_file:
      - .env
    ports:
      - 6379:6379
    healthcheck:
      test: "exit 0"

  celeryworker:
    image: "langflowai/langflow:latest"
    env_file:
      - .env
    command: celery -A langflow.worker.celery_app worker --loglevel=INFO --concurrency=1 -n lf-worker@%h -P eventlet
    healthcheck:
      test: "exit 0"
    deploy:
      replicas: 1

  flower:
    image: "langflowai/langflow:latest"
    env_file:
      - .env
    networks:
      - default
    environment:
      - FLOWER_PORT=5555
    command: /bin/sh -c "celery -A langflow.worker.celery_app --broker=${BROKER_URL?Variable not set} flower --port=5555"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555

  frontend:
    image: "ogabrielluiz/langflow_frontend:latest"
    env_file:
      - .env
    build:
      context: ../src/frontend
      dockerfile: Dockerfile
      args:
        - BACKEND_URL=http://backend:7860
    restart: on-failure
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
        - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80

  broker:
    image: rabbitmq:3-management
    environment:
      - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER:-admin}
      - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS:-admin}
    volumes:
      - rabbitmq_data:/etc/rabbitmq/
      - rabbitmq_data:/var/lib/rabbitmq/
      - rabbitmq_log:/var/log/rabbitmq/
    ports:
      - 5672:5672
      - 15672:15672

  prometheus:
    image: prom/prometheus:v2.37.9
    env_file:
      - .env
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - "--config.file=/etc/prometheus/prometheus.yml"
    healthcheck:
      test: "exit 0"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-prometheus-http.rule=PathPrefix(`/metrics`)
        - traefik.http.services.${STACK_NAME?Variable not set}-prometheus.loadbalancer.server.port=9090

  grafana:
    image: grafana/grafana:8.2.6
    env_file:
      - .env
    volumes:
      - grafana_data:/var/lib/grafana
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-grafana-http.rule=PathPrefix(`/grafana`)
        - traefik.http.services.${STACK_NAME?Variable not set}-grafana.loadbalancer.server.port=3000

volumes:
  grafana_data:
  app-db-data:
  rabbitmq_data:
  rabbitmq_log:
  pgadmin-data:

networks:
  traefik-public:
    external: false

To deploy Langflow:

  1. Clone the LangFlow repository:

    git clone https://github.com/langflow-ai/langflow.git
  2. Navigate to the docker_example directory:

    cd langflow/docker_example
  3. Run the Docker Compose file:

    docker compose up

LangFlow will now be accessible at http://localhost:7860/ [1][2].

To continue talking to Dosu, mention @dosu.

chibexme commented 1 week ago

@Dosu, for celeryworker and flower services am now getting the below errors:

/app/.venv/lib/python3.12/site-packages/langchain/agents/json_chat/base.py:22: SyntaxWarning: invalid escape sequence '\ ' """Create an agent that uses JSON to format its logic, build for Chat Models.

Usage: python -m langflow run [OPTIONS] Try 'python -m langflow run --help' for help.

No such option: --upgrade

dosubot[bot] commented 1 week ago

The errors you're encountering suggest a couple of issues with the celeryworker and flower services. Let's address them step-by-step:

  1. SyntaxWarning: invalid escape sequence: This warning is related to the langchain library and is not critical. However, it can be fixed by ensuring that the string literals in the base.py file use raw strings (prefixing with r) or by escaping the backslashes properly.

  2. No such option: --upgrade: This error indicates that the --upgrade option is not recognized by the langflow command. It seems like there might be a misconfiguration in the command being run.

Steps to Resolve:

  1. Update Dockerfile and Startup Script: Ensure that the Dockerfile and startup script for the backend, celeryworker, and flower services are correctly set up to install and run langflow without the --upgrade option.

  2. Correct Docker Compose Configuration: Verify that the docker-compose.yml file does not include the --upgrade option in the command for the backend, celeryworker, and flower services.

Here is an updated example configuration for the docker-compose.yml:

version: "3.8"
services:
  backend:
    image: "langflowai/langflow:latest"
    depends_on:
      - db
      - broker
      - result_backend
    env_file:
      - .env
    volumes:
      - ../:/app
      - ./startup-backend.sh:/startup-backend.sh
    command: /startup-backend.sh
    healthcheck:
      test: "exit 0"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api/v1`) || PathPrefix(`/docs`) || PathPrefix(`/health`)
        - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=7860

  celeryworker:
    image: "langflowai/langflow:latest"
    env_file:
      - .env
    command: celery -A langflow.worker.celery_app worker --loglevel=INFO --concurrency=1 -n lf-worker@%h -P eventlet
    healthcheck:
      test: "exit 0"
    deploy:
      replicas: 1

  flower:
    image: "langflowai/langflow:latest"
    env_file:
      - .env
    networks:
      - default
    environment:
      - FLOWER_PORT=5555
    command: /bin/sh -c "celery -A langflow.worker.celery_app --broker=${BROKER_URL?Variable not set} flower --port=5555"
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
        - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
        - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
        - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555
  1. Ensure Correct Environment Variables: Make sure the .env file includes the necessary environment variables for celeryworker and flower services:

    BROKER_URL=amqp://admin:admin@broker:5672//
    FLOWER_PORT=5555
  2. Verify Installation of langflow: Ensure that the langflow module is correctly installed in the Docker image. You can add the installation command in the Dockerfile if it's not already included:

    RUN pip install langflow

By following these steps, you should be able to resolve the issues with the celeryworker and flower services. If the problem persists, please provide more details or logs for further assistance.

To continue talking to Dosu, mention @dosu.

chibexme commented 1 week ago

Please can someone in the core team update the docker-compose.yml in deploy folder as it was last updated 2months? which definitely doesn't conform to current version 1 deployment requirements. @ogabrielluiz

nicoloboschi commented 1 week ago

@chibexme this is going to be fixed in 1.0.6. The current issue is "latest" image doesn't point to 1.x release. Plus, there's a problem with the endpoint that has been already fixed in the main branch but not released yet

cc @ogabrielluiz

chibexme commented 6 days ago

@chibexme this is going to be fixed in 1.0.6. The current issue is "latest" image doesn't point to 1.x release. Plus, there's a problem with the endpoint that has been already fixed in the main branch but not released yet

cc @ogabrielluiz

Alright, will be waiting for the 1.0.6 release.

Thanks.

chibexme commented 19 hours ago

@ogabrielluiz I can see that version 1.0.6 has been release with many bug fixed, that's impressive.

Regard my concern about docker-compose.yml file in the deploy folder, it still has not been updated as can be seen in the screenshot below Screenshot 2024-07-04 160238

I checked the docker image the frontend is point to, it was updated 9months ago Screenshot 2024-07-04 160411

Kindly point me to the right working docker-compose file to deploy langflow from.

Expecting your speedy response.