generated from GDGVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhex.sh
executable file
·121 lines (108 loc) · 3.2 KB
/
hex.sh
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
#!/bin/sh
# Hexathon
# Handy set of commands to run to get a new server up and running
if [ "$1" = "local" ]; then
shift # Discard the first argument
environment="local"
file="docker-compose-local.yaml"
else
environment="production"
file="docker-compose-prod.yaml"
fi
command=$1
if [ -z "$command" ]; then
echo
echo " ██╗ ██╗███████╗██╗ ██╗"
echo " ██║ ██║██╔════╝╚██╗██╔╝"
echo " ███████║█████╗ ╚███╔╝ "
echo " ██╔══██║██╔══╝ ██╔██╗ "
echo " ██║ ██║███████╗██╔╝ ██╗"
echo " ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝"
echo
echo "Environment: $environment"
echo
echo "Author: Dhruv Shah"
echo
echo "Usage: hex [env] [command]"
echo
echo "Available environments:"
echo " local: Local development environment"
echo " prod: Production environment (default)"
echo
echo "Available commands:"
echo " up: Start the server"
echo " down: Stop the server"
echo " restart: Restart the server"
echo " recreatedb: Recreate all the tables in database"
echo " copy: Copy a file to the hexathon api container"
echo " cli: Run a command inside the container"
exit 1
fi
# Start server command
if [ "$command" = "up" ]; then
echo "Starting server"
docker compose -f "$file" up -d --build
exit 1
fi
# Stop server command
if [ "$command" = "down" ]; then
echo "Stopping server"
docker compose -f "$file" down
exit 1
fi
# Restart server command
if [ "$command" = "restart" ]; then
echo "Restarting server"
docker compose -f "$file" down
docker compose -f "$file" up -d --build
exit 1
fi
# Drop all DB tables
if [ "$command" = "recreatedb" ]; then
echo "Dropping all tables"
docker exec -it hexathon-postgres psql -U postgres -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
echo "Restarting server"
docker compose -f "$file" up -d --build
exit 1
fi
# Copy file to hexathon api container
if [ "$command" = "copy" ]; then
shift # Discard the first argument
docker cp "$1" hexathon-api:/"$1"
exit 1
fi
# Backup database
if [ "$command" = "backup" ]; then
echo "Backing up database"
shift # Discard the first argument
# Make sure argument is provided
if [ -z "$1" ]; then
echo "Usage: hex backup <backup_name>"
exit 1
fi
./backup.sh "$1"
exit 1
fi
# Restore database
if [ "$command" = "restore" ]; then
echo "Restoring database"
shift # Discard the first argument
# Make sure argument is provided
if [ -z "$1" ]; then
echo "Usage: hex restore <backup_file>"
exit 1
fi
./restore.sh "$1"
exit 1
fi
# Management commands
if [ "$command" = "cli" ]; then
shift # Discard the first argument
docker compose -f "$file" run --rm hexathon-api ./bin/hex-api "$@"
exit 1
fi
if [ "$command" = "psql" ]; then
docker compose -f "$file" exec -it postgres psql -U postgres postgres
exit 1
fi
docker compose -f "$file" "$@"