@gv-sh/specgen-app 0.5.0 → 0.5.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/scripts/deploy.sh CHANGED
@@ -1,189 +1,180 @@
1
1
  #!/bin/bash
2
2
 
3
- # AWS Ubuntu Deployment Script for SpecGen
3
+ # SpecGen Deploy Script - Simple PM2 Deployment on Port 8080 with Full Cleanup
4
4
  set -e
5
5
 
6
- # Colors for output
7
- RED='\033[0;31m'
8
- GREEN='\033[0;32m'
9
- YELLOW='\033[1;33m'
10
- NC='\033[0m' # No Color
11
-
12
- echo -e "${GREEN}Starting SpecGen deployment...${NC}"
13
-
14
- # Update system
15
- echo -e "${YELLOW}Updating system packages...${NC}"
16
- sudo apt update && sudo apt upgrade -y
17
-
18
- # Install Node.js 18
19
- echo -e "${YELLOW}Installing Node.js 18...${NC}"
20
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
21
- sudo apt-get install -y nodejs
22
-
23
- # Install PM2
24
- echo -e "${YELLOW}Installing PM2...${NC}"
25
- sudo npm install -g pm2
26
-
27
- # Install Nginx
28
- echo -e "${YELLOW}Installing Nginx...${NC}"
29
- sudo apt install -y nginx
30
-
31
- # Create application directory
32
- sudo mkdir -p /opt/specgen-app
33
- cd /opt/specgen-app
34
-
35
- # Download and extract packages
36
- echo -e "${YELLOW}Downloading SpecGen packages...${NC}"
37
- npm pack @gv-sh/specgen-server
38
- npm pack @gv-sh/specgen-admin
39
- npm pack @gv-sh/specgen-user
40
-
41
- # Extract packages
42
- tar -xzf gv-sh-specgen-server-*.tgz && mv package server
43
- tar -xzf gv-sh-specgen-admin-*.tgz && mv package admin
44
- tar -xzf gv-sh-specgen-user-*.tgz && mv package user
45
-
46
- # Install dependencies
47
- echo -e "${YELLOW}Installing dependencies...${NC}"
48
- cd server && npm install --production
49
- cd ../admin && npm install --production
50
- cd ../user && npm install --production
51
- cd ..
52
-
53
- # Setup environment
54
- echo -e "${YELLOW}Setting up environment...${NC}"
55
- read -p "Enter your OpenAI API key: " OPENAI_KEY
56
- read -p "Enter your domain (or IP): " DOMAIN
57
-
58
- # Server .env
59
- echo "OPENAI_API_KEY=$OPENAI_KEY" | sudo tee server/.env
60
- echo "NODE_ENV=production" | sudo tee -a server/.env
61
- echo "PORT=3000" | sudo tee -a server/.env
62
-
63
- # Admin .env.production
64
- echo "REACT_APP_API_URL=http://$DOMAIN" | sudo tee admin/.env.production
65
- echo "GENERATE_SOURCEMAP=false" | sudo tee -a admin/.env.production
66
-
67
- # User .env.production
68
- echo "REACT_APP_API_URL=http://$DOMAIN" | sudo tee user/.env.production
69
- echo "GENERATE_SOURCEMAP=false" | sudo tee -a user/.env.production
70
-
71
- # Build React apps
72
- echo -e "${YELLOW}Building React applications...${NC}"
73
- cd admin && NODE_ENV=production npm run build
74
- cd ../user && NODE_ENV=production npm run build
75
- cd ..
76
-
77
- # Create PM2 ecosystem
6
+ echo "🚀 Deploying SpecGen to production on port 8080..."
7
+ echo "🧹 Performing full cleanup before deployment..."
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
+ # Stop and remove all PM2 processes
24
+ echo "Stopping all PM2 processes..."
25
+ npx pm2 stop all 2>/dev/null || true
26
+ npx pm2 delete all 2>/dev/null || true
27
+ npx pm2 kill 2>/dev/null || true
28
+
29
+ # Remove old PM2 config files
30
+ rm -f ecosystem.config.js 2>/dev/null || true
31
+ rm -f pm2.config.js 2>/dev/null || true
32
+
33
+ # Kill processes on all relevant ports
34
+ echo "Freeing all ports..."
35
+ for port in 8080 3000 3001 3002; do
36
+ if ! check_port $port; then
37
+ echo "Killing processes on port $port..."
38
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
39
+ sleep 1
40
+ fi
41
+ done
42
+
43
+ # Clean up logs
44
+ rm -rf logs/* 2>/dev/null || true
45
+
46
+ # Check for nginx conflicts
47
+ if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
48
+ if nginx -T 2>/dev/null | grep -q ":8080"; then
49
+ echo "⚠️ WARNING: Nginx is configured to use port 8080"
50
+ echo " You may need to stop nginx or reconfigure it"
51
+ echo " Run: sudo systemctl stop nginx"
52
+ fi
53
+ fi
54
+
55
+ # ========================================
56
+ # RUN PRODUCTION SETUP
57
+ # ========================================
58
+
59
+ echo "Running production setup..."
60
+ npm run production &
61
+ SETUP_PID=$!
62
+
63
+ # Wait for setup to complete or timeout
64
+ TIMEOUT=90
65
+ COUNT=0
66
+ while [ $COUNT -lt $TIMEOUT ]; do
67
+ if ! kill -0 $SETUP_PID 2>/dev/null; then
68
+ echo "Production setup completed"
69
+ break
70
+ fi
71
+ sleep 1
72
+ COUNT=$((COUNT + 1))
73
+
74
+ # Show progress every 15 seconds
75
+ if [ $((COUNT % 15)) -eq 0 ]; then
76
+ echo "Setup still running... ($COUNT/$TIMEOUT seconds)"
77
+ fi
78
+ done
79
+
80
+ # Kill setup process if it's still running
81
+ if kill -0 $SETUP_PID 2>/dev/null; then
82
+ echo "Setup taking too long, terminating and continuing with PM2 deployment..."
83
+ kill $SETUP_PID 2>/dev/null || true
84
+ # Force kill any remaining processes
85
+ for port in 8080 3000; do
86
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
87
+ done
88
+ fi
89
+
90
+ # Wait a moment for cleanup
91
+ sleep 3
92
+
93
+ # ========================================
94
+ # PM2 DEPLOYMENT
95
+ # ========================================
96
+
97
+ # Create PM2 ecosystem configuration
98
+ echo "Creating PM2 ecosystem configuration..."
78
99
  cat > ecosystem.config.js << 'EOF'
79
100
  module.exports = {
80
101
  apps: [{
81
- name: 'specgen-server',
102
+ name: 'specgen',
82
103
  script: './server/index.js',
83
- instances: 1,
84
- autorestart: true,
85
- watch: false,
86
- max_memory_restart: '512M',
104
+ cwd: process.cwd(),
87
105
  env: {
88
106
  NODE_ENV: 'production',
89
- PORT: 3000
90
- }
107
+ PORT: 8080
108
+ },
109
+ instances: 1,
110
+ exec_mode: 'fork',
111
+ max_memory_restart: '500M',
112
+ error_file: './logs/err.log',
113
+ out_file: './logs/out.log',
114
+ log_file: './logs/combined.log',
115
+ time: true,
116
+ watch: false,
117
+ ignore_watch: ['node_modules', 'logs', '*.log'],
118
+ restart_delay: 1000,
119
+ max_restarts: 3,
120
+ min_uptime: '10s'
91
121
  }]
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
122
  }
155
123
  EOF
156
124
 
157
- # Enable site
158
- sudo ln -sf /etc/nginx/sites-available/specgen /etc/nginx/sites-enabled/
159
- sudo rm -f /etc/nginx/sites-enabled/default
160
-
161
- # Test and reload Nginx
162
- sudo nginx -t
163
- sudo systemctl restart nginx
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
125
+ # Create logs directory
126
+ mkdir -p logs
127
+
128
+ # Final port check
129
+ echo "Final port check..."
130
+ if ! check_port 8080; then
131
+ echo "Port 8080 still occupied, force cleaning..."
132
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
133
+ sleep 2
187
134
  fi
188
135
 
189
- echo -e "${GREEN}Setup complete!${NC}"
136
+ # Start with PM2
137
+ echo "Starting SpecGen with PM2 on port 8080..."
138
+ NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
139
+
140
+ # Wait for startup and verify
141
+ sleep 5
142
+
143
+ # Check if the process is actually running
144
+ if npx pm2 list | grep -q "online"; then
145
+ echo ""
146
+ echo "✅ SpecGen deployment completed successfully!"
147
+
148
+ # Get public IP
149
+ PUBLIC_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s ipecho.net/plain 2>/dev/null || echo 'your-server')
150
+
151
+ echo ""
152
+ echo "🌐 Access your application at:"
153
+ echo " - Main page: http://$PUBLIC_IP:8080/"
154
+ echo " - User app: http://$PUBLIC_IP:8080/app"
155
+ echo " - Admin panel: http://$PUBLIC_IP:8080/admin"
156
+ echo " - API docs: http://$PUBLIC_IP:8080/api-docs"
157
+ echo " - Health check: http://$PUBLIC_IP:8080/api/health"
158
+ echo ""
159
+ echo "📊 Management commands:"
160
+ echo " - Check status: npx pm2 status"
161
+ echo " - View logs: npx pm2 logs specgen"
162
+ echo " - Restart: npx pm2 restart specgen"
163
+ echo " - Stop: npx pm2 stop specgen"
164
+ echo ""
165
+
166
+ # Test the health endpoint
167
+ echo "🔍 Testing health endpoint..."
168
+ if curl -s http://localhost:8080/api/health >/dev/null 2>&1; then
169
+ echo "✅ Health check passed!"
170
+ else
171
+ echo "⚠️ Health check failed - check logs with: npx pm2 logs specgen"
172
+ fi
173
+
174
+ else
175
+ echo ""
176
+ echo "❌ Deployment failed!"
177
+ echo "📝 Check logs with: npx pm2 logs specgen"
178
+ echo "📊 Check status with: npx pm2 status"
179
+ exit 1
180
+ 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
- # Make sure the low memory scripts are executable
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 required ports if needed
104
- echo "Checking ports..."
105
- for port in 3000 3001 3002; do
106
- if ! check_port $port; then
107
- echo "Port $port is in use. Attempting to free it..."
108
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
109
- sleep 1
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
@@ -1,9 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- # SpecGen Production Script
3
+ # SpecGen Production Script - Low Memory, Port 8080 with Cleanup
4
4
  set -e
5
5
 
6
- echo "🚀 Starting SpecGen in production mode..."
6
+ echo "🚀 Starting SpecGen in production mode on port 8080..."
7
+ echo "🧹 Cleaning up existing processes..."
7
8
 
8
9
  # Function to check if port is available
9
10
  check_port() {
@@ -15,6 +16,37 @@ check_port() {
15
16
  fi
16
17
  }
17
18
 
19
+ # ========================================
20
+ # CLEANUP EXISTING PROCESSES
21
+ # ========================================
22
+
23
+ # Stop and cleanup PM2 processes
24
+ echo "Stopping existing PM2 processes..."
25
+ npx pm2 stop all 2>/dev/null || true
26
+ npx pm2 delete all 2>/dev/null || true
27
+
28
+ # Kill processes on ports we'll use
29
+ echo "Freeing ports..."
30
+ for port in 8080 3000 3001 3002; do
31
+ if ! check_port $port; then
32
+ echo "Port $port is in use. Attempting to free it..."
33
+ lsof -ti:$port | xargs kill -9 2>/dev/null || true
34
+ sleep 1
35
+ fi
36
+ done
37
+
38
+ # Stop nginx if it might interfere
39
+ if command -v nginx &> /dev/null && systemctl is-active --quiet nginx 2>/dev/null; then
40
+ echo "Nginx is running, checking for conflicts..."
41
+ if nginx -T 2>/dev/null | grep -q ":8080"; then
42
+ echo "⚠️ Nginx is configured to use port 8080. You may need to reconfigure nginx."
43
+ fi
44
+ fi
45
+
46
+ # ========================================
47
+ # VERIFY SETUP
48
+ # ========================================
49
+
18
50
  # Verify OpenAI API key
19
51
  if [ -f "server/.env" ]; then
20
52
  # In CI mode, skip API key validation
@@ -48,43 +80,101 @@ for dir in server admin user; do
48
80
  fi
49
81
  done
50
82
 
51
- # Check if dependencies are installed
52
- for dir in server admin user; do
53
- if [ ! -d "$dir/node_modules" ]; then
54
- echo "Installing $dir dependencies..."
55
- cd "$dir" && npm install
56
- cd ..
57
- fi
58
- done
83
+ # ========================================
84
+ # INSTALL DEPENDENCIES
85
+ # ========================================
86
+
87
+ # Make sure node_modules exist in the server directory
88
+ if [ ! -d "server/node_modules" ]; then
89
+ echo "Installing server dependencies..."
90
+ cd server
91
+ # Create a .npmrc file that ignores engine requirements
92
+ echo "engine-strict=false" > .npmrc
93
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
94
+ cd ..
95
+ fi
59
96
 
60
97
  # Set production environment
61
98
  export NODE_ENV=production
62
99
 
63
- echo "Building web interfaces..."
64
- # Build React apps for production
65
- cd admin && npm run build && cd ..
66
- cd user && npm run build && cd ..
100
+ # ========================================
101
+ # BUILD INTERFACES
102
+ # ========================================
103
+
104
+ # Check if we need to build
105
+ if [ ! -d "admin/build" ] || [ ! -d "user/build" ]; then
106
+ echo "Building web interfaces (optimized mode)..."
107
+
108
+ # Admin build
109
+ if [ ! -d "admin/build" ]; then
110
+ echo "Building admin..."
111
+ cd admin
112
+ echo "engine-strict=false" > .npmrc
113
+ # Install only production dependencies
114
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
115
+ # Set environment for smaller build
116
+ export GENERATE_SOURCEMAP=false
117
+ export SKIP_PREFLIGHT_CHECK=true
118
+ npm run build
119
+ cd ..
120
+ fi
121
+
122
+ # User build
123
+ if [ ! -d "user/build" ]; then
124
+ echo "Building user..."
125
+ cd user
126
+ echo "engine-strict=false" > .npmrc
127
+ # Install only production dependencies
128
+ npm install --no-fund --no-audit --production --maxsockets=2 --loglevel=warn
129
+ # Set environment for smaller build
130
+ export GENERATE_SOURCEMAP=false
131
+ export SKIP_PREFLIGHT_CHECK=true
132
+ npm run build
133
+ cd ..
134
+ fi
135
+ fi
136
+
137
+ # ========================================
138
+ # CONFIGURE ENVIRONMENT
139
+ # ========================================
140
+
141
+ # Update server .env to use port 8080
142
+ if [ -f "server/.env" ]; then
143
+ # Update or add PORT=8080 to .env
144
+ if grep -q "^PORT=" server/.env; then
145
+ sed -i.bak "s/^PORT=.*/PORT=8080/" server/.env
146
+ else
147
+ echo "PORT=8080" >> server/.env
148
+ fi
149
+ rm -f server/.env.bak
150
+ fi
67
151
 
68
152
  # Create production-ready .env for server
69
153
  cat > server/.env.production << EOF
70
154
  $(cat server/.env)
71
155
  NODE_ENV=production
156
+ PORT=8080
72
157
  EOF
73
158
 
74
- # Kill existing processes on required ports if needed
75
- echo "Checking ports..."
76
- for port in 3000 3001 3002; do
77
- if ! check_port $port; then
78
- echo "Port $port is in use. Attempting to free it..."
79
- lsof -ti:$port | xargs kill -9 2>/dev/null || true
80
- sleep 1
81
- fi
82
- done
159
+ # Create logs directory
160
+ mkdir -p logs
161
+
162
+ # ========================================
163
+ # START SERVER
164
+ # ========================================
165
+
166
+ # Final port check
167
+ echo "Final check for port 8080..."
168
+ if ! check_port 8080; then
169
+ echo "Port 8080 is still in use after cleanup. Force killing..."
170
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
171
+ sleep 2
172
+ fi
83
173
 
84
174
  # Start production server
85
- echo "Starting production server..."
175
+ echo "Starting production server on port 8080..."
86
176
  if [ "$CI" = "true" ]; then
87
177
  echo "CI mode detected - skipping server start"
88
178
  else
89
- cd server && NODE_ENV=production npm start
179
+ cd server && NODE_ENV=production PORT=8080 npm start
90
180
  fi