forked from getmydia/mydia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev
More file actions
executable file
·215 lines (185 loc) · 6.48 KB
/
Copy pathdev
File metadata and controls
executable file
·215 lines (185 loc) · 6.48 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
#!/usr/bin/env bash
# Dev command wrapper for docker compose management
# Provides convenient shortcuts for common development operations
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
COMPOSE_FILE="compose.yml"
SERVICE_NAME="app"
# Check if docker is available
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: docker is not installed or not in PATH${NC}"
echo "Please install Docker: https://docs.docker.com/get-docker/"
exit 1
fi
# Check if docker compose is available
if ! docker compose version &> /dev/null; then
echo -e "${RED}Error: docker compose is not available${NC}"
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
exit 1
fi
# Check if compose file exists
if [ ! -f "$COMPOSE_FILE" ]; then
echo -e "${RED}Error: $COMPOSE_FILE not found${NC}"
echo "Please run this script from the project root directory"
exit 1
fi
# Show help if no arguments provided
if [ $# -eq 0 ]; then
cat <<EOF
${GREEN}Mydia Development Helper${NC}
Usage: ./dev <command> [arguments...]
${YELLOW}Common Commands:${NC}
up [-d] Start services (add -d for detached mode)
down Stop and remove containers
restart Restart services
logs [-f] [service] View logs (add -f to follow)
ps List running containers
stop Stop services
start Start services
${YELLOW}Container Commands:${NC}
shell Open an interactive shell in the app container
mix <args> Run mix commands inside the container
iex Start IEx inside the container
bash Open bash shell in the app container
${YELLOW}Development Commands:${NC}
test [args] Run tests (mix test)
format Format code (mix format)
deps.get Install dependencies
ecto.migrate Run database migrations
ecto.reset Reset database
phx.server Start Phoenix server
${YELLOW}Docker Compose Commands:${NC}
exec <service> <cmd> Execute command in running service
run <service> <cmd> Run one-off command in new container
build [--no-cache] Build or rebuild services
pull Pull service images
${YELLOW}Examples:${NC}
./dev up -d # Start services in background
./dev logs -f # Follow logs
./dev shell # Open interactive shell
./dev mix test # Run tests
./dev mix ecto.migrate # Run migrations
./dev exec app mix phx.routes # Show Phoenix routes
Any other command will be forwarded directly to docker compose.
EOF
exit 0
fi
# Helper function to run commands in the app container
run_in_container() {
docker compose exec "$SERVICE_NAME" "$@"
}
# Helper function to check if service is running
is_service_running() {
docker compose ps --services --filter "status=running" | grep -q "^${SERVICE_NAME}$"
}
# Parse command
COMMAND=$1
shift
case "$COMMAND" in
# Interactive shell shortcuts
shell|sh)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Opening interactive shell in $SERVICE_NAME container...${NC}"
run_in_container sh
;;
bash)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Opening bash shell in $SERVICE_NAME container...${NC}"
run_in_container bash
;;
iex)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Starting IEx in $SERVICE_NAME container...${NC}"
run_in_container iex -S mix
;;
# Mix command shortcuts
mix)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
# Set MIX_ENV=test for commands that run tests
if [[ "$1" == "precommit" ]] || [[ "$1" == "test" ]]; then
docker compose exec -e MIX_ENV=test "$SERVICE_NAME" mix "$@"
else
run_in_container mix "$@"
fi
;;
# Common development shortcuts
test)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Running tests...${NC}"
docker compose exec -e MIX_ENV=test "$SERVICE_NAME" sh -c 'mix ecto.create --quiet && mix ecto.migrate --quiet && mix test '"$*"
;;
format)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Formatting code...${NC}"
run_in_container mix format
;;
deps.get)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Installing dependencies...${NC}"
run_in_container mix deps.get
;;
ecto.migrate)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Running migrations...${NC}"
run_in_container mix ecto.migrate
;;
ecto.reset)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Resetting database...${NC}"
run_in_container mix ecto.reset
;;
phx.server)
if ! is_service_running; then
echo -e "${YELLOW}Service is not running. Starting it first...${NC}"
docker compose up -d
sleep 2
fi
echo -e "${GREEN}Starting Phoenix server...${NC}"
run_in_container mix phx.server
;;
# Forward everything else to docker compose
*)
docker compose "$COMMAND" "$@"
;;
esac