-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·125 lines (101 loc) · 3.52 KB
/
deploy.sh
File metadata and controls
executable file
·125 lines (101 loc) · 3.52 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
#!/bin/bash
# ============================================
# BudStack Deployment Script
# ============================================
set -e # Exit on error
echo "=========================================="
echo "BudStack Platform Deployment"
echo "=========================================="
echo ""
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check if .env.production exists
if [ ! -f .env.production ]; then
echo -e "${RED}❌ Error: .env.production file not found!${NC}"
echo "Please create .env.production from .env.production.example"
echo "cp .env.production.example .env.production"
echo "Then edit .env.production with your actual credentials"
exit 1
fi
echo -e "${GREEN}✓${NC} Found .env.production"
echo ""
# Check Docker installation
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker is not installed${NC}"
echo "Please install Docker: https://docs.docker.com/get-docker/"
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}❌ Docker Compose is not installed${NC}"
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
exit 1
fi
echo -e "${GREEN}✓${NC} Docker and Docker Compose are installed"
echo ""
# Ask for deployment type
echo "Select deployment type:"
echo "1) Development (with hot reload)"
echo "2) Production (optimized build)"
read -p "Enter choice [1-2]: " DEPLOY_TYPE
if [ "$DEPLOY_TYPE" == "1" ]; then
ENV_FILE=".env"
echo -e "${YELLOW}➤${NC} Starting in DEVELOPMENT mode..."
# Install dependencies
echo ""
echo -e "${YELLOW}➤${NC} Installing dependencies..."
cd nextjs_space
yarn install
cd ..
# Start dev server
cd nextjs_space
yarn dev &
cd ..
echo -e "${GREEN}✓${NC} Development server starting on http://localhost:3000"
elif [ "$DEPLOY_TYPE" == "2" ]; then
ENV_FILE=".env.production"
echo -e "${YELLOW}➤${NC} Starting in PRODUCTION mode..."
# Stop existing containers
echo ""
echo -e "${YELLOW}➤${NC} Stopping existing containers..."
docker-compose --env-file $ENV_FILE down
# Build and start containers
echo ""
echo -e "${YELLOW}➤${NC} Building Docker images..."
docker-compose --env-file $ENV_FILE build --no-cache
echo ""
echo -e "${YELLOW}➤${NC} Starting containers..."
docker-compose --env-file $ENV_FILE up -d
# Wait for database to be ready
echo ""
echo -e "${YELLOW}➤${NC} Waiting for database to be ready..."
sleep 10
# Run migrations
echo ""
echo -e "${YELLOW}➤${NC} Running database migrations..."
docker-compose --env-file $ENV_FILE exec -T app npx prisma migrate deploy
# Check container status
echo ""
echo -e "${YELLOW}➤${NC} Checking container status..."
docker-compose --env-file $ENV_FILE ps
# Show logs
echo ""
echo -e "${GREEN}✓${NC} Deployment complete!"
echo ""
echo "=========================================="
echo "Useful commands:"
echo "=========================================="
echo "View logs: docker-compose logs -f app"
echo "Stop services: docker-compose down"
echo "Restart: docker-compose restart"
echo "Database backup: docker-compose exec postgres pg_dump -U budstack budstack_db > backup.sql"
echo ""
echo "Application URL: http://localhost:3000"
else
echo -e "${RED}❌ Invalid choice${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}✓${NC} Done!"