This guide provides detailed instructions for deploying the Movie Chatbot application to Cloud Foundry, with a focus on configuration options and service bindings.
- Prerequisites
- Configuration Options
- Deployment Scenarios
- Required vs. Optional Configuration
- Service Binding Details
- Troubleshooting
Before deploying the application, ensure you have:
- Cloud Foundry CLI installed (
cfcommand available) - Access to a Tanzu Platform for Cloud Foundry environment
- Proper permissions to create and bind services
- The application code from the repository
The application supports multiple configuration sources, with the following priority order:
-
Service Bindings (highest priority)
- GenAI tile service bindings for LLM configuration
- User-defined services for other required/optional configuration
-
Environment Variables (second priority)
- Set via
cf set-envor in manifest.yml - Used when service bindings are not available
- Set via
-
config.json (third priority)
- Used as a fallback when neither service bindings nor environment variables are available
- Particularly useful for local development or simplified deployment
This is the recommended approach for production deployments when the GenAI tile is available.
-
Deploy the application:
# Clone the repository if you haven't already git clone https://github.com/cf-toolsuite/tanzu-genai-showcase cd tanzu-genai-showcase/py-django-crewai # Deploy to Cloud Foundry ./deploy-on-tp4cf.sh
-
Create and bind a GenAI service instance:
# Discover available GenAI tile service offering plans cf marketplace -e genai # Create a GenAI service instance cf create-service genai PLAN_NAME movie-chatbot-llm # Bind the application to the service cf bind-service movie-chatbot movie-chatbot-llm
-
Set required non-LLM configuration:
cf set-env movie-chatbot DJANGO_SECRET_KEY "your_secret_key" cf set-env movie-chatbot TMDB_API_KEY "your_tmdb_api_key"
-
Start the application:
cf start movie-chatbot
This approach is useful when the GenAI tile is not available, but you still want to use service bindings for configuration.
-
Deploy the application:
./deploy-on-tp4cf.sh
-
Create a user-defined service for LLM configuration:
cf create-user-provided-service movie-chatbot-llm -p '{ "api_key": "your_llm_api_key", "api_base": "your_llm_base_url", "model_name": "your_model_name", "model_provider": "openai" }'
-
Create a user-defined service for other required configuration:
cf create-user-provided-service movie-chatbot-config -p '{ "DJANGO_SECRET_KEY": "your_secret_key", "TMDB_API_KEY": "your_tmdb_api_key", "SERPAPI_API_KEY": "your_serpapi_key" }'
-
Bind the services to the application:
cf bind-service movie-chatbot movie-chatbot-llm cf bind-service movie-chatbot movie-chatbot-config
-
Start the application:
cf start movie-chatbot
This approach uses environment variables for all configuration.
-
Deploy the application:
./deploy-on-tp4cf.sh
-
Set LLM configuration:
cf set-env movie-chatbot OPENAI_API_KEY "your_llm_api_key" cf set-env movie-chatbot LLM_BASE_URL "your_llm_base_url" cf set-env movie-chatbot LLM_MODEL "your_model_name"
-
Set other required configuration:
cf set-env movie-chatbot DJANGO_SECRET_KEY "your_secret_key" cf set-env movie-chatbot TMDB_API_KEY "your_tmdb_api_key"
-
Set optional configuration (if needed):
cf set-env movie-chatbot SERPAPI_API_KEY "your_serpapi_key" cf set-env movie-chatbot MOVIE_RESULTS_LIMIT "5" cf set-env movie-chatbot MAX_RECOMMENDATIONS "3"
-
Start the application:
cf start movie-chatbot
This approach uses a config.json file for configuration, which is included in the deployment.
-
Create a config.json file:
{ "DJANGO_SECRET_KEY": "your_secret_key", "TMDB_API_KEY": "your_tmdb_api_key", "OPENAI_API_KEY": "your_llm_api_key", "LLM_BASE_URL": "your_llm_base_url", "LLM_MODEL": "your_model_name", "SERPAPI_API_KEY": "your_serpapi_key", "MOVIE_RESULTS_LIMIT": "5", "MAX_RECOMMENDATIONS": "3" } -
Deploy the application with the config.json file:
./deploy-on-tp4cf.sh
-
Start the application:
cf start movie-chatbot
These settings are essential for the application to function:
- DJANGO_SECRET_KEY: Required for Django security features
- TMDB_API_KEY: Required for movie data retrieval
These settings are specifically for the LLM service:
- LLM API Key: Required for LLM access (via
OPENAI_API_KEYorLLM_API_KEY) - LLM Base URL: Optional, defaults to OpenAI's API endpoint
- LLM Model: Optional, defaults to 'gpt-4o-mini'
These settings have defaults but can be overridden:
- SERPAPI_API_KEY: Optional, for theater showtimes (enhances functionality)
- MOVIE_RESULTS_LIMIT: Optional, defaults to 5
- MAX_RECOMMENDATIONS: Optional, defaults to 3
- THEATER_SEARCH_RADIUS_MILES: Optional, defaults to 15
- DEFAULT_SEARCH_START_YEAR: Optional, defaults to 1900
- Other API request configuration parameters (timeouts, retries, etc.)
When using the GenAI tile, the application automatically extracts the following from the service binding:
- api_key: The API key for the LLM service
- api_base: The base URL for the LLM service
- model_name: The name of the model to use
- model_provider: The provider of the model (e.g., 'openai')
The application looks for services with the 'genai' tag or label, or specifically named 'movie-chatbot-llm'.
When using user-defined services, you can create two types of services:
-
LLM Service (named 'movie-chatbot-llm'):
- Contains LLM-specific configuration (api_key, api_base, model_name, model_provider)
-
Config Service (named 'movie-chatbot-config'):
- Contains other required and optional configuration (DJANGO_SECRET_KEY, TMDB_API_KEY, etc.)
-
Missing Required Configuration:
- Check that DJANGO_SECRET_KEY and TMDB_API_KEY are set
- Verify that LLM API key is available (via service binding or environment variable)
-
Service Binding Issues:
- Verify that services are correctly bound to the application
- Check service binding credentials with
cf env movie-chatbot
-
Configuration Priority:
- Remember that service bindings take precedence over environment variables
- Environment variables take precedence over config.json
To enable debug logging:
cf set-env movie-chatbot DEBUG True
cf set-env movie-chatbot LOG_LEVEL DEBUG
cf restage movie-chatbotView logs:
cf logs movie-chatbot --recent