fix: docker prod env variable fix (#1170)
Some checks are pending
Docker Publish / docker-build-publish (push) Waiting to run
Update Stable Branch / prepare-release (push) Waiting to run

* fix: docker prod env variable fix

* lint and typecheck

* removed hardcoded tag
This commit is contained in:
Anirban Kar 2025-01-25 03:52:26 +05:30 committed by GitHub
parent 5a0489f3c3
commit 660353360f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 63 additions and 20 deletions

View File

@ -40,7 +40,7 @@ export default class LMStudioProvider extends BaseProvider {
* Running in Server * Running in Server
* Backend: Check if we're running in Docker * Backend: Check if we're running in Docker
*/ */
const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; const isDocker = process?.env?.RUNNING_IN_DOCKER === 'true' || serverEnv?.RUNNING_IN_DOCKER === 'true';
baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl;
baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl;
@ -58,7 +58,7 @@ export default class LMStudioProvider extends BaseProvider {
} }
getModelInstance: (options: { getModelInstance: (options: {
model: string; model: string;
serverEnv: Env; serverEnv?: Env;
apiKeys?: Record<string, string>; apiKeys?: Record<string, string>;
providerSettings?: Record<string, IProviderSetting>; providerSettings?: Record<string, IProviderSetting>;
}) => LanguageModelV1 = (options) => { }) => LanguageModelV1 = (options) => {
@ -75,8 +75,9 @@ export default class LMStudioProvider extends BaseProvider {
throw new Error('No baseUrl found for LMStudio provider'); throw new Error('No baseUrl found for LMStudio provider');
} }
const isDocker = process.env.RUNNING_IN_DOCKER === 'true' || serverEnv?.RUNNING_IN_DOCKER === 'true';
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
const isDocker = process.env.RUNNING_IN_DOCKER === 'true';
baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl;
baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl;
} }
@ -84,7 +85,7 @@ export default class LMStudioProvider extends BaseProvider {
logger.debug('LMStudio Base Url used: ', baseUrl); logger.debug('LMStudio Base Url used: ', baseUrl);
const lmstudio = createOpenAI({ const lmstudio = createOpenAI({
baseUrl: `${baseUrl}/v1`, baseURL: `${baseUrl}/v1`,
apiKey: '', apiKey: '',
}); });

View File

@ -63,7 +63,7 @@ export default class OllamaProvider extends BaseProvider {
* Running in Server * Running in Server
* Backend: Check if we're running in Docker * Backend: Check if we're running in Docker
*/ */
const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; const isDocker = process?.env?.RUNNING_IN_DOCKER === 'true' || serverEnv?.RUNNING_IN_DOCKER === 'true';
baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl;
baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl;
@ -83,7 +83,7 @@ export default class OllamaProvider extends BaseProvider {
} }
getModelInstance: (options: { getModelInstance: (options: {
model: string; model: string;
serverEnv: Env; serverEnv?: Env;
apiKeys?: Record<string, string>; apiKeys?: Record<string, string>;
providerSettings?: Record<string, IProviderSetting>; providerSettings?: Record<string, IProviderSetting>;
}) => LanguageModelV1 = (options) => { }) => LanguageModelV1 = (options) => {
@ -101,7 +101,7 @@ export default class OllamaProvider extends BaseProvider {
throw new Error('No baseUrl found for OLLAMA provider'); throw new Error('No baseUrl found for OLLAMA provider');
} }
const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; const isDocker = process?.env?.RUNNING_IN_DOCKER === 'true' || serverEnv?.RUNNING_IN_DOCKER === 'true';
baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl;
baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl;

View File

@ -41,11 +41,17 @@ function getProviderInfo(llmManager: LLMManager) {
export async function loader({ export async function loader({
request, request,
params, params,
context,
}: { }: {
request: Request; request: Request;
params: { provider?: string }; params: { provider?: string };
context: {
cloudflare?: {
env: Record<string, string>;
};
};
}): Promise<Response> { }): Promise<Response> {
const llmManager = LLMManager.getInstance(import.meta.env); const llmManager = LLMManager.getInstance(context.cloudflare?.env);
// Get client side maintained API keys and provider settings from cookies // Get client side maintained API keys and provider settings from cookies
const cookieHeader = request.headers.get('Cookie'); const cookieHeader = request.headers.get('Cookie');
@ -63,7 +69,7 @@ export async function loader({
if (provider) { if (provider) {
const staticModels = provider.staticModels; const staticModels = provider.staticModels;
const dynamicModels = provider.getDynamicModels const dynamicModels = provider.getDynamicModels
? await provider.getDynamicModels(apiKeys, providerSettings, import.meta.env) ? await provider.getDynamicModels(apiKeys, providerSettings, context.cloudflare?.env)
: []; : [];
modelList = [...staticModels, ...dynamicModels]; modelList = [...staticModels, ...dynamicModels];
} }
@ -72,7 +78,7 @@ export async function loader({
modelList = await llmManager.updateModelList({ modelList = await llmManager.updateModelList({
apiKeys, apiKeys,
providerSettings, providerSettings,
serverEnv: import.meta.env, serverEnv: context.cloudflare?.env,
}); });
} }

View File

@ -2,15 +2,32 @@
bindings="" bindings=""
while IFS= read -r line || [ -n "$line" ]; do # Function to extract variable names from the TypeScript interface
if [[ ! "$line" =~ ^# ]] && [[ -n "$line" ]]; then extract_env_vars() {
name=$(echo "$line" | cut -d '=' -f 1) grep -o '[A-Z_]\+:' worker-configuration.d.ts | sed 's/://'
value=$(echo "$line" | cut -d '=' -f 2-) }
value=$(echo $value | sed 's/^"\(.*\)"$/\1/')
bindings+="--binding ${name}=${value} " # First try to read from .env.local if it exists
fi if [ -f ".env.local" ]; then
done < .env.local while IFS= read -r line || [ -n "$line" ]; do
if [[ ! "$line" =~ ^# ]] && [[ -n "$line" ]]; then
name=$(echo "$line" | cut -d '=' -f 1)
value=$(echo "$line" | cut -d '=' -f 2-)
value=$(echo $value | sed 's/^"\(.*\)"$/\1/')
bindings+="--binding ${name}=${value} "
fi
done < .env.local
else
# If .env.local doesn't exist, use environment variables defined in .d.ts
env_vars=($(extract_env_vars))
# Generate bindings for each environment variable if it exists
for var in "${env_vars[@]}"; do
if [ -n "${!var}" ]; then
bindings+="--binding ${var}=${!var} "
fi
done
fi
bindings=$(echo $bindings | sed 's/[[:space:]]*$//') bindings=$(echo $bindings | sed 's/[[:space:]]*$//')
echo $bindings echo $bindings

View File

@ -72,3 +72,21 @@ services:
- "5173:5173" - "5173:5173"
command: pnpm run dev --host 0.0.0.0 command: pnpm run dev --host 0.0.0.0
profiles: ["development", "default"] profiles: ["development", "default"]
app-prebuild:
image: ghcr.io/stackblitz-labs/bolt.diy:latest
ports:
- "5173:5173"
environment:
- NODE_ENV=production
- COMPOSE_PROFILES=production
# No strictly needed but serving as hints for Coolify
- PORT=5173
- OLLAMA_API_BASE_URL=http://127.0.0.1:11434
- DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX:-32768}
- RUNNING_IN_DOCKER=true
extra_hosts:
- "host.docker.internal:host-gateway"
command: pnpm run dockerstart
profiles:
- prebuilt

View File

@ -1,5 +1,6 @@
interface Env { interface Env {
DEFAULT_NUM_CTX:Settings; RUNNING_IN_DOCKER: Settings;
DEFAULT_NUM_CTX: Settings;
ANTHROPIC_API_KEY: string; ANTHROPIC_API_KEY: string;
OPENAI_API_KEY: string; OPENAI_API_KEY: string;
GROQ_API_KEY: string; GROQ_API_KEY: string;