-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpapersorter-cli
More file actions
executable file
·86 lines (78 loc) · 2.41 KB
/
papersorter-cli
File metadata and controls
executable file
·86 lines (78 loc) · 2.41 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
#!/bin/bash
# PaperSorter CLI wrapper for Docker
# This script allows running PaperSorter commands from the host system
# against the dockerized instance
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if docker-compose is available
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed or not in PATH${NC}"
exit 1
fi
# Check if we're in the right directory (where docker-compose.yml exists)
if [ ! -f "docker-compose.yml" ]; then
echo -e "${RED}Error: docker-compose.yml not found in current directory${NC}"
echo "Please run this script from the PaperSorter root directory"
exit 1
fi
# Check if the web container is running
if ! docker-compose ps --services --filter "status=running" | grep -q "^web$"; then
echo -e "${YELLOW}Warning: PaperSorter web container is not running${NC}"
echo "Starting services..."
docker-compose up -d
# Wait for services to be ready
echo "Waiting for services to be ready..."
sleep 5
# Wait for database to be ready
for i in {1..30}; do
if docker-compose exec -T web pg_isready -h postgres -U papersorter &> /dev/null; then
echo -e "${GREEN}Services are ready!${NC}"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED}Error: Services failed to start${NC}"
exit 1
fi
echo -n "."
sleep 2
done
echo
fi
# Special handling for certain commands
case "$1" in
"logs")
# Show logs from web container
docker-compose logs -f web
;;
"shell")
# Open interactive shell in web container
docker-compose exec web bash
;;
"db-shell")
# Open PostgreSQL shell
docker-compose exec postgres psql -U papersorter papersorter
;;
"status")
# Show status of all services
docker-compose ps
;;
"restart")
# Restart all services
docker-compose restart
;;
"update-image")
# Rebuild and update Docker images
echo "Rebuilding PaperSorter images..."
docker-compose build --no-cache
docker-compose up -d
;;
*)
# Pass through to papersorter command in container
# Use -T flag to disable TTY allocation for non-interactive commands
docker-compose exec -T web papersorter "$@"
;;
esac