-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·208 lines (177 loc) · 5.26 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·208 lines (177 loc) · 5.26 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
#!/bin/bash
# RVA Deployment Helper Script
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
MODE="postgres"
PORT=8060
WORKERS=4
ACTION="start"
# Display help
show_help() {
cat << EOF
RVA Deployment Helper
Usage: $0 [OPTIONS]
OPTIONS:
-m, --mode MODE Deployment mode: memory, sqlite, postgres (default: postgres)
-p, --port PORT Application port (default: 8060)
-w, --workers WORKERS Number of workers for postgres mode (default: 4)
-a, --action ACTION Action: start, stop, restart, logs, status, reset (default: start)
-h, --help Show this help message
EXAMPLES:
# Start with PostgreSQL (production)
$0 --mode postgres --workers 8
# Start with SQLite (demos)
$0 --mode sqlite
# Start with in-memory (testing)
$0 --mode memory
# Check status
$0 --action status
# View logs
$0 --action logs
# Reset database
$0 --action reset --mode postgres
EOF
}
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-m|--mode)
MODE="$2"
shift 2
;;
-p|--port)
PORT="$2"
shift 2
;;
-w|--workers)
WORKERS="$2"
shift 2
;;
-a|--action)
ACTION="$2"
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
show_help
exit 1
;;
esac
done
# Validate mode
case $MODE in
memory|sqlite|postgres)
;;
*)
echo -e "${RED}Invalid mode: $MODE${NC}"
echo "Valid modes: memory, sqlite, postgres"
exit 1
;;
esac
# Determine compose file
case $MODE in
memory)
COMPOSE_FILE="docker-compose.memory.yml"
CONTAINER_NAME="rva-memory"
;;
sqlite)
COMPOSE_FILE="docker-compose.sqlite.yml"
CONTAINER_NAME="rva-sqlite"
;;
postgres)
COMPOSE_FILE="docker-compose.rva-db.yml"
CONTAINER_NAME="rva-app"
;;
esac
# Export environment variables
export RVA_PORT=$PORT
export UVICORN_WORKERS=$WORKERS
# Execute action
case $ACTION in
start)
echo -e "${BLUE}Starting RVA in ${YELLOW}${MODE}${BLUE} mode...${NC}"
echo -e "${BLUE}Port: ${YELLOW}${PORT}${NC}"
if [ "$MODE" = "postgres" ]; then
echo -e "${BLUE}Workers: ${YELLOW}${WORKERS}${NC}"
fi
docker-compose -f "$COMPOSE_FILE" up -d
echo ""
echo -e "${GREEN}✓ RVA started successfully!${NC}"
echo -e "${BLUE}Access the application at: ${YELLOW}http://localhost:${PORT}${NC}"
echo -e "${BLUE}API docs: ${YELLOW}http://localhost:${PORT}/docs${NC}"
echo ""
echo -e "${BLUE}View logs: ${NC}docker logs -f ${CONTAINER_NAME}"
;;
stop)
echo -e "${BLUE}Stopping RVA...${NC}"
docker-compose -f "$COMPOSE_FILE" down
echo -e "${GREEN}✓ RVA stopped${NC}"
;;
restart)
echo -e "${BLUE}Restarting RVA...${NC}"
docker-compose -f "$COMPOSE_FILE" restart
echo -e "${GREEN}✓ RVA restarted${NC}"
;;
logs)
echo -e "${BLUE}Showing logs for ${CONTAINER_NAME}...${NC}"
docker logs -f "$CONTAINER_NAME"
;;
status)
echo -e "${BLUE}RVA Status:${NC}"
docker-compose -f "$COMPOSE_FILE" ps
if docker ps | grep -q "$CONTAINER_NAME"; then
echo ""
echo -e "${GREEN}✓ RVA is running${NC}"
echo -e "${BLUE}Health check:${NC}"
if curl -sf "http://localhost:${PORT}/" > /dev/null; then
echo -e "${GREEN}✓ Application is responding${NC}"
else
echo -e "${RED}✗ Application is not responding${NC}"
fi
else
echo -e "${RED}✗ RVA is not running${NC}"
fi
;;
reset)
echo -e "${YELLOW}⚠️ This will delete all data!${NC}"
read -p "Are you sure? (yes/no): " -r
echo
if [[ $REPLY =~ ^[Yy][Ee][Ss]$ ]]; then
echo -e "${BLUE}Stopping RVA...${NC}"
docker-compose -f "$COMPOSE_FILE" down
case $MODE in
sqlite)
echo -e "${BLUE}Removing SQLite volume...${NC}"
docker volume rm rva-sqlite-data || true
;;
postgres)
echo -e "${BLUE}Removing PostgreSQL volume...${NC}"
docker volume rm rva-pgdata || true
;;
memory)
echo -e "${YELLOW}Memory mode doesn't persist data${NC}"
;;
esac
echo -e "${BLUE}Restarting RVA...${NC}"
docker-compose -f "$COMPOSE_FILE" up -d
echo -e "${GREEN}✓ Database reset complete${NC}"
else
echo -e "${YELLOW}Reset cancelled${NC}"
fi
;;
*)
echo -e "${RED}Unknown action: $ACTION${NC}"
echo "Valid actions: start, stop, restart, logs, status, reset"
exit 1
;;
esac