-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.sh
More file actions
executable file
·333 lines (292 loc) · 10.3 KB
/
scripts.sh
File metadata and controls
executable file
·333 lines (292 loc) · 10.3 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
DEV_COMPOSE_FILE="./docker-compose.development.yml"
TEST_COMPOSE_FILE="./docker-compose.test.yml"
SERVICE_NAME="skateparks-web"
TEST_SERVICE_NAME="skateparks-web-test"
check_docker() {
if ! docker info > /dev/null 2>&1; then
printf "${RED}Error: Docker is not running. Please start Docker first.${NC}\n"
exit 1
fi
}
show_docker_status() {
echo -e "${CYAN}--- Docker Status ---${NC}"
if docker ps --format "table {{.Names}}\t{{.Status}}" | grep -E "(skateparks|rails|postgres)" > /dev/null 2>&1; then
docker ps --format "table {{.Names}}\t{{.Status}}" | grep -E "(skateparks|rails|postgres)" | head -10
else
echo -e "${YELLOW}No skatepark containers currently running${NC}"
fi
echo ""
}
confirm_action() {
local message="$1"
echo -e "${YELLOW}$message${NC}"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Operation cancelled.${NC}"
exit 0
fi
}
clear
echo -e "${PURPLE}🛹 Skateparks.gr Development Toolkit 🛹${NC}"
echo ""
check_docker
show_docker_status
echo -e "${GREEN}--- Development Server ---${NC}"
echo -e " ${BLUE}(1)${NC} Start development server"
echo -e " ${BLUE}(2)${NC} Fresh build & start development server"
echo -e " ${BLUE}(3)${NC} Attach to Docker development server"
echo -e " ${BLUE}(4)${NC} Rails console (database queries)"
echo -e " ${BLUE}(5)${NC} Connect to Docker console"
echo -e " ${BLUE}(6)${NC} View development server logs"
echo -e " ${BLUE}(7)${NC} Stop development server"
echo ""
echo -e "${GREEN}--- Test Server ---${NC}"
echo -e " ${BLUE}(8)${NC} Start test server"
echo -e " ${BLUE}(9)${NC} Fresh build & start test server"
echo -e " ${BLUE}(10)${NC} Connect to test Docker console"
echo -e " ${BLUE}(11)${NC} View test server logs"
echo ""
echo -e "${GREEN}--- Tests & Linting & Formatting ---${NC}"
echo -e " ${BLUE}(12)${NC} Run tests"
echo -e " ${BLUE}(13)${NC} Run Brakeman security scan"
echo -e " ${BLUE}(14)${NC} Run bundle-audit security scan"
echo -e " ${BLUE}(15)${NC} Run yarn audit"
echo -e " ${BLUE}(16)${NC} Check Herb format"
echo -e " ${BLUE}(17)${NC} Run Herb format"
echo -e " ${BLUE}(18)${NC} Check Herb lint"
echo -e " ${BLUE}(19)${NC} Run Herb lint auto-fix"
echo -e " ${BLUE}(20)${NC} Check for RuboCop errors"
echo -e " ${BLUE}(21)${NC} Run RuboCop auto-fix"
echo -e " ${BLUE}(22)${NC} Check for Prettier errors"
echo -e " ${BLUE}(23)${NC} Run Prettier"
echo ""
echo -e "${GREEN}--- Database & Cache ---${NC}"
echo -e " ${BLUE}(24)${NC} Seed the database"
echo -e " ${BLUE}(25)${NC} Reset database & migrate"
echo -e " ${BLUE}(26)${NC} Clear all Rails cache"
echo ""
echo -e "${GREEN}--- Other ---${NC}"
echo -e " ${BLUE}(27)${NC} Stop skateparks Docker containers"
echo -e " ${BLUE}(28)${NC} Show Docker container status"
echo ""
echo -e "${YELLOW}Choose an option:${NC} "
read OPTION
case $OPTION in
# DEVELOPMENT SERVER OPTIONS
1)
echo -e "${GREEN}Starting development server...${NC}"
if docker compose -f $DEV_COMPOSE_FILE start; then
echo -e "${GREEN}✅ Development server started successfully${NC}"
else
echo -e "${RED}❌ Failed to start development server${NC}"
exit 1
fi
;;
2)
confirm_action "This will rebuild and recreate the development container."
echo -e "${GREEN}Building and starting development server with fresh build...${NC}"
if docker compose -f $DEV_COMPOSE_FILE up --remove-orphans --build --force-recreate -d; then
echo -e "${GREEN}✅ Development server built and started successfully${NC}"
else
echo -e "${RED}❌ Failed to build and start development server${NC}"
exit 1
fi
;;
3)
echo -e "${GREEN}Attaching to development server...${NC}"
docker attach $SERVICE_NAME || echo -e "${RED}❌ Failed to attach to development server${NC}"
;;
4)
echo -e "${GREEN}Opening Rails console...${NC}"
docker compose -f $DEV_COMPOSE_FILE exec $SERVICE_NAME bundle exec rails console
;;
5)
echo -e "${GREEN}Connecting to Docker console...${NC}"
docker compose -f $DEV_COMPOSE_FILE exec $SERVICE_NAME bash
;;
6)
echo -e "${GREEN}Viewing development server logs...${NC}"
docker compose -f $DEV_COMPOSE_FILE logs -f $SERVICE_NAME
;;
7)
confirm_action "This will stop the development server."
echo -e "${YELLOW}Stopping development server...${NC}"
if docker compose -f $DEV_COMPOSE_FILE stop; then
echo -e "${GREEN}✅ Development server stopped${NC}"
else
echo -e "${RED}❌ Failed to stop development server${NC}"
fi
;;
8)
echo -e "${GREEN}Starting test server...${NC}"
if docker compose -f $TEST_COMPOSE_FILE start; then
echo -e "${GREEN}✅ Test server started successfully${NC}"
else
echo -e "${RED}❌ Failed to start test server${NC}"
exit 1
fi
;;
9)
confirm_action "This will rebuild and recreate the test container."
echo -e "${GREEN}Building and starting test server with fresh build...${NC}"
if docker compose -f $TEST_COMPOSE_FILE --env-file ./.env.test up --remove-orphans --build --force-recreate -d; then
echo -e "${GREEN}✅ Test server built and started successfully${NC}"
else
echo -e "${RED}❌ Failed to build and start test server${NC}"
exit 1
fi
;;
10)
echo -e "${GREEN}Connecting to test Docker console...${NC}"
docker compose -f $TEST_COMPOSE_FILE exec $TEST_SERVICE_NAME bash
;;
11)
echo -e "${GREEN}Viewing test server logs...${NC}"
docker compose -f $TEST_COMPOSE_FILE logs -f $TEST_SERVICE_NAME
;;
12)
echo -e "${GREEN}Running tests with coverage...${NC}"
docker compose -f $TEST_COMPOSE_FILE exec $TEST_SERVICE_NAME bash -c "bin/rails test"
echo ""
echo -e "${CYAN}Coverage report: ${NC}file://$(pwd)/coverage/index.html"
;;
13)
echo -e "${GREEN}Running Brakeman security scan...${NC}"
if bundle exec brakeman -q --no-pager; then
echo -e "${GREEN}✅ No security issues found${NC}"
else
echo -e "${RED}❌ Security issues detected${NC}"
fi
;;
14)
echo -e "${GREEN}Running bundle-audit security scan...${NC}"
if bundle exec bundle-audit check --update; then
echo -e "${GREEN}✅ No vulnerable dependencies found${NC}"
else
echo -e "${RED}❌ Vulnerable dependencies detected${NC}"
fi
;;
15)
echo -e "${GREEN}Running yarn audit...${NC}"
if yarn audit --audit-level moderate; then
echo -e "${GREEN}✅ No yarn vulnerabilities found${NC}"
else
echo -e "${RED}❌ Yarn vulnerabilities detected${NC}"
fi
;;
16)
echo -e "${GREEN}Checking Herb format...${NC}"
if yarn herb:format:check; then
echo -e "${GREEN}✅ ERB files are properly formatted${NC}"
else
echo -e "${RED}❌ ERB files need formatting${NC}"
fi
;;
17)
echo -e "${GREEN}Formatting ERB files with Herb...${NC}"
if yarn herb:format; then
echo -e "${GREEN}✅ ERB files formatted successfully${NC}"
else
echo -e "${RED}❌ Failed to format ERB files${NC}"
fi
;;
18)
echo -e "${GREEN}Linting ERB files with Herb...${NC}"
if yarn herb:lint; then
echo -e "${GREEN}✅ No Herb lint errors found${NC}"
else
echo -e "${RED}❌ Herb lint errors detected${NC}"
fi
;;
19)
echo -e "${GREEN}Running Herb lint auto-fix...${NC}"
if yarn herb:lint:fix; then
echo -e "${GREEN}✅ Herb lint issues fixed${NC}"
else
echo -e "${YELLOW}⚠️ Some issues could not be auto-fixed${NC}"
fi
;;
20)
echo -e "${GREEN}Running Ruby linter (RuboCop)...${NC}"
bundle exec rubocop
;;
21)
echo -e "${GREEN}Running RuboCop auto-fix...${NC}"
if bundle exec rubocop -A; then
echo -e "${GREEN}✅ RuboCop auto-fixes applied successfully${NC}"
else
echo -e "${YELLOW}⚠️ Some issues could not be auto-fixed${NC}"
fi
;;
22)
echo -e "${GREEN}Checking Prettier errors...${NC}"
if yarn prettier:check; then
echo -e "${GREEN}✅ No Prettier errors found${NC}"
else
echo -e "${RED}❌ Prettier errors detected${NC}"
fi
;;
23)
echo -e "${GREEN}Running Prettier...${NC}"
if yarn prettier:fix; then
echo -e "${GREEN}✅ Files formatted with Prettier successfully${NC}"
else
echo -e "${RED}❌ Failed to format files with Prettier${NC}"
fi
;;
24)
echo -e "${GREEN}Seeding the database...${NC}"
if docker compose -f $DEV_COMPOSE_FILE exec $SERVICE_NAME bash -c "bundle exec rails db:seed"; then
echo -e "${GREEN}✅ Database seeded successfully${NC}"
else
echo -e "${RED}❌ Failed to seed database${NC}"
fi
;;
25)
confirm_action "This will reset and migrate the database. All data will be lost!"
echo -e "${GREEN}Resetting and migrating database...${NC}"
docker compose -f $DEV_COMPOSE_FILE exec $SERVICE_NAME bash -c "bundle exec rails db:reset db:migrate"
;;
26)
echo -e "${GREEN}Clearing Rails cache...${NC}"
if docker compose -f $DEV_COMPOSE_FILE exec $SERVICE_NAME bash -c "bundle exec rails runner 'Rails.cache.clear'"; then
echo -e "${GREEN}✅ Cache cleared successfully${NC}"
else
echo -e "${RED}❌ Failed to clear cache${NC}"
fi
;;
27)
confirm_action "This will stop all skateparks-related Docker containers."
echo -e "${YELLOW}Stopping skateparks Docker containers...${NC}"
STOPPED=false
if docker compose -f $DEV_COMPOSE_FILE stop 2>/dev/null; then
echo -e "${GREEN}✅ Development containers stopped${NC}"
STOPPED=true
fi
if docker compose -f $TEST_COMPOSE_FILE stop 2>/dev/null; then
echo -e "${GREEN}✅ Test containers stopped${NC}"
STOPPED=true
fi
if [ "$STOPPED" = false ]; then
echo -e "${YELLOW}⚠️ No skateparks containers were running${NC}"
fi
;;
28)
show_docker_status
;;
*)
echo -e "${RED}❌ Unknown option: $OPTION${NC}"
echo -e "${YELLOW}Please choose a valid option (1-28)${NC}"
exit 1
;;
esac
echo -e "${GREEN}Operation completed!${NC}"