-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
235 lines (194 loc) · 5.71 KB
/
deploy.sh
File metadata and controls
235 lines (194 loc) · 5.71 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/bash
# Code Fix Deployment Script
# This script handles deployment to various platforms
set -e
echo "🚀 Code Fix Deployment Script"
echo "=============================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if Node.js is installed
check_node() {
if ! command -v node &> /dev/null; then
print_error "Node.js is not installed. Please install Node.js 16+ first."
exit 1
fi
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 16 ]; then
print_error "Node.js version 16+ is required. Current version: $(node --version)"
exit 1
fi
print_success "Node.js $(node --version) detected"
}
# Check if Docker is installed
check_docker() {
if ! command -v docker &> /dev/null; then
print_warning "Docker is not installed. Docker deployment will not be available."
return 1
fi
print_success "Docker $(docker --version | cut -d' ' -f3 | cut -d',' -f1) detected"
return 0
}
# Install dependencies
install_deps() {
print_status "Installing dependencies..."
npm ci --only=production
print_success "Dependencies installed successfully"
}
# Run tests (if available)
run_tests() {
if [ -f "package.json" ] && grep -q '"test"' package.json; then
print_status "Running tests..."
npm test
print_success "All tests passed"
else
print_warning "No tests found, skipping test phase"
fi
}
# Build for production
build_production() {
print_status "Preparing production build..."
# Create production environment file if it doesn't exist
if [ ! -f ".env" ]; then
cp .env.example .env
print_warning "Created .env file from .env.example. Please review and update as needed."
fi
# Set production environment
sed -i 's/NODE_ENV=development/NODE_ENV=production/' .env
print_success "Production build prepared"
}
# Local deployment
deploy_local() {
print_status "Starting local deployment..."
check_node
install_deps
build_production
print_success "Local deployment ready!"
print_status "Run 'npm start' to start the server"
print_status "Application will be available at: http://localhost:3002"
}
# Docker deployment
deploy_docker() {
print_status "Starting Docker deployment..."
if ! check_docker; then
print_error "Docker is required for Docker deployment"
exit 1
fi
print_status "Building Docker image..."
docker build -t code-fix:latest .
print_status "Starting Docker container..."
docker-compose up -d
print_success "Docker deployment completed!"
print_status "Application is running at: http://localhost:3002"
print_status "Use 'docker-compose logs -f' to view logs"
print_status "Use 'docker-compose down' to stop the application"
}
# Vercel deployment
deploy_vercel() {
print_status "Preparing Vercel deployment..."
if ! command -v vercel &> /dev/null; then
print_error "Vercel CLI is not installed. Install with: npm i -g vercel"
exit 1
fi
# Create vercel.json if it doesn't exist
if [ ! -f "vercel.json" ]; then
cat > vercel.json << EOF
{
"version": 2,
"builds": [
{
"src": "server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/server.js"
}
]
}
EOF
print_status "Created vercel.json configuration"
fi
print_status "Deploying to Vercel..."
vercel --prod
print_success "Vercel deployment completed!"
}
# Netlify deployment
deploy_netlify() {
print_status "Preparing Netlify deployment..."
if ! command -v netlify &> /dev/null; then
print_error "Netlify CLI is not installed. Install with: npm i -g netlify-cli"
exit 1
fi
# Create _redirects file for SPA routing
echo "/* /index.html 200" > _redirects
print_status "Deploying to Netlify..."
netlify deploy --prod --dir=.
print_success "Netlify deployment completed!"
}
# Health check
health_check() {
print_status "Running health check..."
if [ -f "healthcheck.js" ]; then
node healthcheck.js
print_success "Health check passed"
else
print_warning "Health check script not found"
fi
}
# Main deployment function
main() {
case "${1:-local}" in
"local")
deploy_local
;;
"docker")
deploy_docker
;;
"vercel")
deploy_vercel
;;
"netlify")
deploy_netlify
;;
"health")
health_check
;;
*)
echo "Usage: $0 {local|docker|vercel|netlify|health}"
echo ""
echo "Deployment options:"
echo " local - Deploy locally with Node.js"
echo " docker - Deploy using Docker containers"
echo " vercel - Deploy to Vercel platform"
echo " netlify - Deploy to Netlify platform"
echo " health - Run health check"
echo ""
echo "Examples:"
echo " $0 local # Local development deployment"
echo " $0 docker # Production Docker deployment"
echo " $0 vercel # Deploy to Vercel"
exit 1
;;
esac
}
# Run main function with all arguments
main "$@"