-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
Β·133 lines (113 loc) Β· 4.29 KB
/
deploy
File metadata and controls
executable file
Β·133 lines (113 loc) Β· 4.29 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# OmniChat 1-Click Deploy Script
# This script handles everything from dependency installation to finished deployment.
set -e
echo "π Starting Complete OmniChat Deployment..."
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# 1. Check system requirements
echo "π Checking system requirements..."
if ! command_exists docker; then
echo "β Docker is not installed. Please install Docker first."
echo "Visit: https://docs.docker.com/get-docker/"
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "β Docker Compose is not available. Installing..."
sudo apt update && sudo apt install -y docker-compose-plugin
fi
if ! command_exists npm; then
echo "β Node.js/npm is not installed. Please install Node.js first."
echo "Visit: https://nodejs.org/"
exit 1
fi
# 2. Install local dependencies
echo "π¦ Installing local dependencies..."
npm install --legacy-peer-deps
# 3. Check for .env file
if [ ! -f .env ]; then
echo "β οΈ No .env file found. Creating template from .env.example..."
if [ -f .env.example ]; then
cp .env.example .env
echo "β
Created .env from .env.example"
echo "β οΈ Please edit the .env file with your Gemini API Key before proceeding."
echo " Current GEMINI_API_KEY is set to placeholder value."
# Check if API key is still placeholder
if grep -q "your_gemini_api_key_here" .env; then
echo "β You must update GEMINI_API_KEY in .env file before deploying."
echo " Get your key from: https://aistudio.google.com/app/apikey"
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
else
echo "β No .env.example file found. Creating basic .env..."
echo "GEMINI_API_KEY=your_key_here" > .env
echo "NODE_ENV=production" >> .env
echo "DATABASE_URL=\"file:./prisma/data/dev.db\"" >> .env
echo "JWT_SECRET=your_jwt_secret_key_here" >> .env
echo "Please edit the .env file with your Gemini API Key before proceeding."
exit 1
fi
fi
# 4. Load and validate environment variables
echo "π Loading environment variables..."
export $(grep -v '^#' .env | grep -v '^$' | xargs)
if [ -z "$GEMINI_API_KEY" ] || [ "$GEMINI_API_KEY" = "your_gemini_api_key_here" ]; then
echo "β οΈ WARNING: GEMINI_API_KEY is not set or still placeholder!"
echo "Please update your .env file with a real Gemini API key."
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# 5. Create necessary directories
echo "π Creating necessary directories..."
mkdir -p prisma/data
# 6. Add user to docker group (if not already)
if ! groups $USER | grep -q docker; then
echo "π€ Adding user to docker group..."
sudo usermod -aG docker $USER
echo "β οΈ You may need to logout and login again for docker group changes to take effect."
fi
# 7. Stop any existing containers
echo "οΏ½ Stopping existing containers..."
docker compose down || true
# 8. Build and start containers
echo "π¨ Building Docker containers..."
docker compose build --no-cache
echo "π’ Starting OmniChat in production mode..."
docker compose up -d
# 9. Wait for containers to be ready
echo "β³ Waiting for application to start..."
sleep 10
# 10. Health check
echo "π₯ Performing health check..."
if curl -f http://localhost:3000 >/dev/null 2>&1; then
echo "β
Health check passed!"
else
echo "β οΈ Health check failed. Check logs with: docker compose logs -f"
fi
# 11. Show final status
echo ""
echo "π Deployment Complete!"
echo "=================================="
echo "π App URL: http://localhost:3000"
echo "π οΈ Logs: docker compose logs -f"
echo "π Stop: docker compose down"
echo "π Restart: docker compose restart"
echo "π Status: docker compose ps"
echo "=================================="
echo ""
echo "οΏ½ Database is stored in: ./prisma/data/"
echo "π Environment variables loaded from: .env"
echo ""
echo "π― Next steps:"
echo "1. Open http://localhost:3000 in your browser"
echo "2. If you see issues, check logs with: docker compose logs -f"
echo "3. To update after code changes: ./deploy"