@gv-sh/specgen-app 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -232
- package/package.json +2 -7
- package/scripts/deploy-8080.sh.bak +104 -0
- package/scripts/deploy.sh +265 -173
- package/scripts/make-executable.sh +1 -5
- package/scripts/{production-low-memory.sh → production-low-memory.sh.bak} +23 -13
- package/scripts/production.sh +115 -25
- package/scripts/{setup-low-memory.sh → setup-low-memory.sh.bak} +0 -0
- package/scripts/setup.sh +119 -45
package/scripts/deploy.sh
CHANGED
@@ -1,189 +1,281 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
#
|
3
|
+
# SpecGen Deploy Script - Self-Contained Deployment on Port 8080
|
4
4
|
set -e
|
5
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
|
-
echo
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
echo
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
echo "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
echo "
|
65
|
-
echo "
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
6
|
+
echo "🚀 Deploying SpecGen to production on port 8080..."
|
7
|
+
echo "📦 This is a complete deployment - no separate setup needed!"
|
8
|
+
|
9
|
+
# Function to check if port is available
|
10
|
+
check_port() {
|
11
|
+
local port=$1
|
12
|
+
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
|
13
|
+
return 1 # Port in use
|
14
|
+
else
|
15
|
+
return 0 # Port available
|
16
|
+
fi
|
17
|
+
}
|
18
|
+
|
19
|
+
# ========================================
|
20
|
+
# FULL CLEANUP
|
21
|
+
# ========================================
|
22
|
+
|
23
|
+
echo "🧹 Cleaning up existing installations..."
|
24
|
+
|
25
|
+
# Stop and remove all PM2 processes
|
26
|
+
npx pm2 stop all 2>/dev/null || true
|
27
|
+
npx pm2 delete all 2>/dev/null || true
|
28
|
+
npx pm2 kill 2>/dev/null || true
|
29
|
+
|
30
|
+
# Remove old PM2 config files
|
31
|
+
rm -f ecosystem.config.js 2>/dev/null || true
|
32
|
+
|
33
|
+
# Kill processes on all relevant ports
|
34
|
+
for port in 8080 3000 3001 3002; do
|
35
|
+
if ! check_port $port; then
|
36
|
+
echo "Killing processes on port $port..."
|
37
|
+
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
38
|
+
sleep 1
|
39
|
+
fi
|
40
|
+
done
|
41
|
+
|
42
|
+
# Clean up old files
|
43
|
+
rm -rf logs/* 2>/dev/null || true
|
44
|
+
|
45
|
+
# ========================================
|
46
|
+
# VERIFY PREREQUISITES
|
47
|
+
# ========================================
|
48
|
+
|
49
|
+
echo "🔍 Checking prerequisites..."
|
50
|
+
|
51
|
+
# Check Node.js version
|
52
|
+
NODE_VERSION=$(node --version | sed 's/v//' | cut -d. -f1)
|
53
|
+
if [ "$NODE_VERSION" -lt 20 ]; then
|
54
|
+
echo "❌ Node.js 20+ required. Current version: $(node --version)"
|
55
|
+
echo "Install with: curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs"
|
56
|
+
exit 1
|
57
|
+
fi
|
58
|
+
|
59
|
+
# Check if we have the required directories and files
|
60
|
+
echo "📂 Checking project structure..."
|
61
|
+
if [ ! -f "package.json" ]; then
|
62
|
+
echo "❌ package.json not found. This script must be run from the SpecGen project directory."
|
63
|
+
echo "💡 Create a directory and run this script from there:"
|
64
|
+
echo " mkdir specgen && cd specgen"
|
65
|
+
echo " npx @gv-sh/specgen-app deploy"
|
66
|
+
exit 1
|
67
|
+
fi
|
68
|
+
|
69
|
+
# ========================================
|
70
|
+
# SETUP OPENAI API KEY
|
71
|
+
# ========================================
|
72
|
+
|
73
|
+
echo "🔑 Setting up OpenAI API key..."
|
74
|
+
|
75
|
+
# Check if .env exists and has API key
|
76
|
+
if [ ! -f "server/.env" ] || grep -q "your_openai_api_key_here" server/.env 2>/dev/null; then
|
77
|
+
if [ "$CI" = "true" ]; then
|
78
|
+
echo "CI mode - using test API key"
|
79
|
+
mkdir -p server
|
80
|
+
echo "OPENAI_API_KEY=sk-test1234" > server/.env
|
81
|
+
echo "NODE_ENV=production" >> server/.env
|
82
|
+
echo "PORT=8080" >> server/.env
|
83
|
+
else
|
84
|
+
echo "⚠️ OpenAI API key required for SpecGen to work."
|
85
|
+
echo "Enter your OpenAI API key: "
|
86
|
+
read -r OPENAI_KEY
|
87
|
+
|
88
|
+
if [ -z "$OPENAI_KEY" ]; then
|
89
|
+
echo "❌ No API key provided. SpecGen needs an OpenAI API key to function."
|
90
|
+
exit 1
|
91
|
+
fi
|
92
|
+
|
93
|
+
mkdir -p server
|
94
|
+
echo "OPENAI_API_KEY=$OPENAI_KEY" > server/.env
|
95
|
+
echo "NODE_ENV=production" >> server/.env
|
96
|
+
echo "PORT=8080" >> server/.env
|
97
|
+
echo "✅ API key saved"
|
98
|
+
fi
|
99
|
+
fi
|
100
|
+
|
101
|
+
# ========================================
|
102
|
+
# BUILD APPLICATION
|
103
|
+
# ========================================
|
104
|
+
|
105
|
+
echo "🏗️ Building application components..."
|
106
|
+
|
107
|
+
# Install and build server
|
108
|
+
if [ ! -d "server" ] || [ ! -d "server/node_modules" ]; then
|
109
|
+
echo "📦 Setting up server..."
|
110
|
+
npm pack @gv-sh/specgen-server
|
111
|
+
tar -xzf gv-sh-specgen-server-*.tgz
|
112
|
+
mv package server
|
113
|
+
rm gv-sh-specgen-server-*.tgz
|
114
|
+
|
115
|
+
cd server
|
116
|
+
echo "engine-strict=false" > .npmrc
|
117
|
+
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
118
|
+
cd ..
|
119
|
+
fi
|
120
|
+
|
121
|
+
# Install and build admin
|
122
|
+
if [ ! -d "admin/build" ]; then
|
123
|
+
echo "📱 Building admin interface..."
|
124
|
+
if [ ! -d "admin" ]; then
|
125
|
+
npm pack @gv-sh/specgen-admin
|
126
|
+
tar -xzf gv-sh-specgen-admin-*.tgz
|
127
|
+
mv package admin
|
128
|
+
rm gv-sh-specgen-admin-*.tgz
|
129
|
+
fi
|
130
|
+
|
131
|
+
cd admin
|
132
|
+
echo "engine-strict=false" > .npmrc
|
133
|
+
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
134
|
+
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true PUBLIC_URL=/admin npm run build
|
135
|
+
cd ..
|
136
|
+
fi
|
137
|
+
|
138
|
+
# Install and build user
|
139
|
+
if [ ! -d "user/build" ]; then
|
140
|
+
echo "👤 Building user interface..."
|
141
|
+
if [ ! -d "user" ]; then
|
142
|
+
npm pack @gv-sh/specgen-user
|
143
|
+
tar -xzf gv-sh-specgen-user-*.tgz
|
144
|
+
mv package user
|
145
|
+
rm gv-sh-specgen-user-*.tgz
|
146
|
+
fi
|
147
|
+
|
148
|
+
cd user
|
149
|
+
echo "engine-strict=false" > .npmrc
|
150
|
+
npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
|
151
|
+
GENERATE_SOURCEMAP=false SKIP_PREFLIGHT_CHECK=true REACT_APP_API_URL=/api PUBLIC_URL=/app npm run build
|
152
|
+
cd ..
|
153
|
+
fi
|
154
|
+
|
155
|
+
# ========================================
|
156
|
+
# VERIFY BUILDS
|
157
|
+
# ========================================
|
158
|
+
|
159
|
+
echo "✅ Verifying builds..."
|
160
|
+
if [ ! -d "admin/build" ]; then
|
161
|
+
echo "❌ Admin build failed"
|
162
|
+
exit 1
|
163
|
+
fi
|
164
|
+
|
165
|
+
if [ ! -d "user/build" ]; then
|
166
|
+
echo "❌ User build failed"
|
167
|
+
exit 1
|
168
|
+
fi
|
169
|
+
|
170
|
+
echo "📁 Build verification:"
|
171
|
+
echo " Admin build: $(ls -la admin/build/ | wc -l) files"
|
172
|
+
echo " User build: $(ls -la user/build/ | wc -l) files"
|
173
|
+
echo " Server: $(ls -la server/ | wc -l) files"
|
174
|
+
|
175
|
+
# ========================================
|
176
|
+
# PM2 DEPLOYMENT
|
177
|
+
# ========================================
|
178
|
+
|
179
|
+
echo "🚀 Starting PM2 deployment..."
|
180
|
+
|
181
|
+
# Create PM2 ecosystem configuration
|
78
182
|
cat > ecosystem.config.js << 'EOF'
|
79
183
|
module.exports = {
|
80
184
|
apps: [{
|
81
|
-
name: 'specgen
|
185
|
+
name: 'specgen',
|
82
186
|
script: './server/index.js',
|
83
|
-
|
84
|
-
autorestart: true,
|
85
|
-
watch: false,
|
86
|
-
max_memory_restart: '512M',
|
187
|
+
cwd: process.cwd(),
|
87
188
|
env: {
|
88
189
|
NODE_ENV: 'production',
|
89
|
-
PORT:
|
90
|
-
}
|
190
|
+
PORT: 8080
|
191
|
+
},
|
192
|
+
instances: 1,
|
193
|
+
exec_mode: 'fork',
|
194
|
+
max_memory_restart: '500M',
|
195
|
+
error_file: './logs/err.log',
|
196
|
+
out_file: './logs/out.log',
|
197
|
+
log_file: './logs/combined.log',
|
198
|
+
time: true,
|
199
|
+
watch: false,
|
200
|
+
ignore_watch: ['node_modules', 'logs', '*.log'],
|
201
|
+
restart_delay: 1000,
|
202
|
+
max_restarts: 10,
|
203
|
+
min_uptime: '10s'
|
91
204
|
}]
|
92
|
-
};
|
93
|
-
EOF
|
94
|
-
|
95
|
-
# Start server with PM2
|
96
|
-
echo -e "${YELLOW}Starting server with PM2...${NC}"
|
97
|
-
pm2 start ecosystem.config.js
|
98
|
-
pm2 startup
|
99
|
-
pm2 save
|
100
|
-
|
101
|
-
# Configure Nginx
|
102
|
-
echo -e "${YELLOW}Configuring Nginx...${NC}"
|
103
|
-
sudo tee /etc/nginx/sites-available/specgen << 'EOF'
|
104
|
-
server {
|
105
|
-
listen 80 default_server;
|
106
|
-
server_name _;
|
107
|
-
|
108
|
-
# API
|
109
|
-
location /api/ {
|
110
|
-
proxy_pass http://localhost:3000/api/;
|
111
|
-
proxy_http_version 1.1;
|
112
|
-
proxy_set_header Upgrade $http_upgrade;
|
113
|
-
proxy_set_header Connection 'upgrade';
|
114
|
-
proxy_set_header Host $host;
|
115
|
-
proxy_set_header X-Real-IP $remote_addr;
|
116
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
117
|
-
proxy_set_header X-Forwarded-Proto $scheme;
|
118
|
-
proxy_cache_bypass $http_upgrade;
|
119
|
-
}
|
120
|
-
|
121
|
-
# Admin UI
|
122
|
-
location /admin/ {
|
123
|
-
alias /opt/specgen-app/admin/build/;
|
124
|
-
try_files $uri $uri/ /admin/index.html;
|
125
|
-
}
|
126
|
-
|
127
|
-
# User UI (default)
|
128
|
-
location / {
|
129
|
-
root /opt/specgen-app/user/build;
|
130
|
-
try_files $uri $uri/ /index.html;
|
131
|
-
}
|
132
|
-
|
133
|
-
# Security headers
|
134
|
-
add_header X-Frame-Options DENY;
|
135
|
-
add_header X-Content-Type-Options nosniff;
|
136
|
-
add_header X-XSS-Protection "1; mode=block";
|
137
|
-
|
138
|
-
# Gzip compression
|
139
|
-
gzip on;
|
140
|
-
gzip_comp_level 5;
|
141
|
-
gzip_min_length 256;
|
142
|
-
gzip_proxied any;
|
143
|
-
gzip_vary on;
|
144
|
-
gzip_types
|
145
|
-
application/javascript
|
146
|
-
application/json
|
147
|
-
application/x-javascript
|
148
|
-
application/xml
|
149
|
-
application/xml+rss
|
150
|
-
text/css
|
151
|
-
text/javascript
|
152
|
-
text/plain
|
153
|
-
text/xml;
|
154
205
|
}
|
155
206
|
EOF
|
156
207
|
|
157
|
-
#
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
# Configure firewall
|
166
|
-
echo -e "${YELLOW}Configuring firewall...${NC}"
|
167
|
-
sudo ufw allow ssh
|
168
|
-
sudo ufw allow 'Nginx Full'
|
169
|
-
sudo ufw --force enable
|
170
|
-
|
171
|
-
# Initialize database
|
172
|
-
echo -e "${YELLOW}Initializing database...${NC}"
|
173
|
-
cd server && npm run init-db
|
174
|
-
|
175
|
-
echo -e "${GREEN}Deployment complete!${NC}"
|
176
|
-
echo -e "${GREEN}Access your application at:${NC}"
|
177
|
-
echo -e " User Interface: http://your-server-ip/"
|
178
|
-
echo -e " Admin Interface: http://your-server-ip/admin/"
|
179
|
-
echo -e " API: http://your-server-ip/api/"
|
180
|
-
|
181
|
-
# Setup SSL (optional)
|
182
|
-
read -p "Would you like to set up SSL with Let's Encrypt? (y/n): " setup_ssl
|
183
|
-
if [[ $setup_ssl == "y" ]]; then
|
184
|
-
read -p "Enter your domain name: " domain_name
|
185
|
-
sudo apt install -y certbot python3-certbot-nginx
|
186
|
-
sudo certbot --nginx -d $domain_name
|
208
|
+
# Create logs directory
|
209
|
+
mkdir -p logs
|
210
|
+
|
211
|
+
# Final port check
|
212
|
+
if ! check_port 8080; then
|
213
|
+
echo "Port 8080 occupied, force cleaning..."
|
214
|
+
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
215
|
+
sleep 2
|
187
216
|
fi
|
188
217
|
|
189
|
-
|
218
|
+
# Start with PM2
|
219
|
+
echo "▶️ Starting SpecGen with PM2..."
|
220
|
+
NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
|
221
|
+
|
222
|
+
# Wait for startup and verify
|
223
|
+
sleep 5
|
224
|
+
|
225
|
+
# ========================================
|
226
|
+
# DEPLOYMENT VERIFICATION
|
227
|
+
# ========================================
|
228
|
+
|
229
|
+
echo "🔍 Verifying deployment..."
|
230
|
+
|
231
|
+
if npx pm2 list | grep -q "online"; then
|
232
|
+
# Test endpoints
|
233
|
+
echo "Testing endpoints:"
|
234
|
+
|
235
|
+
# Test health endpoint
|
236
|
+
if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
|
237
|
+
echo "✅ Health endpoint: OK"
|
238
|
+
else
|
239
|
+
echo "❌ Health endpoint: FAILED"
|
240
|
+
fi
|
241
|
+
|
242
|
+
# Test main page
|
243
|
+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/ | grep -q "200"; then
|
244
|
+
echo "✅ Main page: OK"
|
245
|
+
else
|
246
|
+
echo "⚠️ Main page: Check logs"
|
247
|
+
fi
|
248
|
+
|
249
|
+
# Test admin
|
250
|
+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin | grep -q "200"; then
|
251
|
+
echo "✅ Admin page: OK"
|
252
|
+
else
|
253
|
+
echo "⚠️ Admin page: Check logs"
|
254
|
+
fi
|
255
|
+
|
256
|
+
PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
|
257
|
+
|
258
|
+
echo ""
|
259
|
+
echo "🎉 SpecGen deployment completed successfully!"
|
260
|
+
echo ""
|
261
|
+
echo "🌐 Access your application at:"
|
262
|
+
echo " - Main page: http://$PUBLIC_IP:8080/"
|
263
|
+
echo " - User app: http://$PUBLIC_IP:8080/app"
|
264
|
+
echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
|
265
|
+
echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
|
266
|
+
echo " - Health check: http://$PUBLIC_IP:8080/api/health"
|
267
|
+
echo ""
|
268
|
+
echo "📊 Management:"
|
269
|
+
echo " npx pm2 status # Check status"
|
270
|
+
echo " npx pm2 logs # View logs"
|
271
|
+
echo " npx pm2 restart specgen # Restart"
|
272
|
+
echo ""
|
273
|
+
|
274
|
+
else
|
275
|
+
echo ""
|
276
|
+
echo "❌ Deployment failed!"
|
277
|
+
echo "📝 Check logs: npx pm2 logs specgen"
|
278
|
+
echo "📊 Check status: npx pm2 status"
|
279
|
+
npx pm2 logs specgen --lines 10
|
280
|
+
exit 1
|
281
|
+
fi
|
@@ -9,8 +9,4 @@ find scripts -name "*.sh" -exec chmod +x {} \;
|
|
9
9
|
# Make CLI executable
|
10
10
|
chmod +x bin/cli.js
|
11
11
|
|
12
|
-
|
13
|
-
chmod +x scripts/setup-low-memory.sh
|
14
|
-
chmod +x scripts/production-low-memory.sh
|
15
|
-
|
16
|
-
echo "✅ All scripts are now executable"
|
12
|
+
echo "✅ All scripts are now executable"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
# SpecGen Production Script - Low Memory Version
|
3
|
+
# SpecGen Production Script - Port 8080 Low Memory Version
|
4
4
|
set -e
|
5
5
|
|
6
|
-
echo "🚀 Starting SpecGen in production mode (Low Memory)..."
|
6
|
+
echo "🚀 Starting SpecGen in production mode on port 8080 (Low Memory)..."
|
7
7
|
|
8
8
|
# Function to check if port is available
|
9
9
|
check_port() {
|
@@ -94,26 +94,36 @@ if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
|
|
94
94
|
fi
|
95
95
|
fi
|
96
96
|
|
97
|
+
# Update server .env to use port 8080
|
98
|
+
if [ -f "server/.env" ]; then
|
99
|
+
# Update or add PORT=8080 to .env
|
100
|
+
if grep -q "^PORT=" server/.env; then
|
101
|
+
sed -i.bak "s/^PORT=.*/PORT=8080/" server/.env
|
102
|
+
else
|
103
|
+
echo "PORT=8080" >> server/.env
|
104
|
+
fi
|
105
|
+
rm -f server/.env.bak
|
106
|
+
fi
|
107
|
+
|
97
108
|
# Create production-ready .env for server
|
98
109
|
cat > server/.env.production << EOF
|
99
110
|
$(cat server/.env)
|
100
111
|
NODE_ENV=production
|
112
|
+
PORT=8080
|
101
113
|
EOF
|
102
114
|
|
103
|
-
# Kill existing processes on
|
104
|
-
echo "Checking
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
fi
|
111
|
-
done
|
115
|
+
# Kill existing processes on port 8080 if needed
|
116
|
+
echo "Checking port 8080..."
|
117
|
+
if ! check_port 8080; then
|
118
|
+
echo "Port 8080 is in use. Attempting to free it..."
|
119
|
+
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
120
|
+
sleep 2
|
121
|
+
fi
|
112
122
|
|
113
123
|
# Start production server
|
114
|
-
echo "Starting production server..."
|
124
|
+
echo "Starting production server on port 8080..."
|
115
125
|
if [ "$CI" = "true" ]; then
|
116
126
|
echo "CI mode detected - skipping server start"
|
117
127
|
else
|
118
|
-
cd server && NODE_ENV=production npm start
|
128
|
+
cd server && NODE_ENV=production PORT=8080 npm start
|
119
129
|
fi
|