File size: 1,648 Bytes
5577464
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

# --- 1. Handle .env.local ---
ENV_LOCAL_PATH=/app/.env.local
if test -z "${DOTENV_LOCAL}" ; then
    if ! test -f "${ENV_LOCAL_PATH}" ; then
        echo "DOTENV_LOCAL was not found in the ENV variables and .env.local is not set using a bind volume. Make sure to set environment variables properly. "
    fi;
else
    echo "DOTENV_LOCAL was found in the ENV variables. Creating .env.local file."
    cat <<< "$DOTENV_LOCAL" > ${ENV_LOCAL_PATH}
fi;

# --- 2. Create MongoDB Data Directory ---
echo "Ensuring MongoDB data directory exists and has correct permissions ON PERSISTENT VOLUME..."
mkdir -p /data/db
chown -R user:user /data/db
echo "MongoDB data directory setup complete."

# --- 3. Create Models Directory (NEW FIX) ---
# This directory is expected by the app even when using remote endpoints.
echo "Ensuring models directory exists and has correct permissions ON PERSISTENT VOLUME..."
mkdir -p /data/models # <--- ADD THIS LINE
chown -R user:user /data/models # <--- ADD THIS LINE
echo "Models directory setup complete."

# --- 4. Start MongoDB ---
echo "Starting local MongoDB instance..."
nohup mongod &
echo "MongoDB started in background. Waiting a few seconds for it to initialize..."
sleep 5

# --- 5. Handle PUBLIC_VERSION (Patch for base image's bug) ---
echo "Setting PUBLIC_VERSION (patching base image's package.json lookup bug)..."
if [ -z "$PUBLIC_VERSION" ]; then
    export PUBLIC_VERSION="0.0.1"
fi
echo "PUBLIC_VERSION set to: $PUBLIC_VERSION"

# --- 6. Start ChatUI Application ---
echo "Starting ChatUI application..."
exec dotenv -e /app/.env -c -- node /app/build/index.js -- --host 0.0.0.0 --port 3000