forked from jbakerr/lanelookout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd
executable file
·117 lines (109 loc) · 3.68 KB
/
d
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
#!/bin/bash
cd "$(dirname $0)"
task=$1 # More descriptive name
arg=$2
args=${*:2}
case $task in
build)
# Build docker containers. Pass --no-cache to force re-downloading of images.
# See ./d build --help for additional info
if [ ! -f .env ]; then
cp .env.example .env
fi
docker-compose build $args
;;
start)
# Start docker containers.
# See ./d up --help for additional info
docker-compose up $args
;;
stop)
# Stop docker containers.
docker-compose stop
;;
clean)
# Remove docker containers (if they exist)
if docker inspect oak-bike-db > /dev/null 2> /dev/null; then
docker rm -f oak-bike-db
fi
if docker inspect oak-bike-db-test > /dev/null 2> /dev/null; then
docker rm -f oak-bike-db-test
fi
if docker inspect oak-bike > /dev/null 2> /dev/null; then
docker rm -f oak-bike
fi
if docker image inspect oak-bike-db > /dev/null 2> /dev/null; then
docker rmi oak-bike-db
fi
if docker image inspect oak-bike > /dev/null 2> /dev/null; then
docker rmi oak-bike
fi
;;
bash)
# SSH (bash) into server container.
# Useful for running Django shell commands.
docker exec -it oak-bike bash
;;
bashdb)
# SSH (bash) into database container.
# Useful for running commands directly against database.
docker exec -it oak-bike-db bash
;;
shell)
# SSH (bash) into server container.
# Useful for running Django shell commands.
docker exec -it oak-bike python manage.py shell
;;
lint)
# Lint server code automatically with autopep8.
# WARNING: This updates files in-place.
docker exec -it oak-bike autopep8 . --in-place --recursive --global-config setup.cfg
;;
dbshell)
# SSH (bash) into database container.
# Useful for running postgres commands.
docker exec -it oak-bike-db psql -U postgres
;;
cleandb)
# Drop the local database.
docker exec -it db psql -U postgres uplift -c
docker exec -it db psql -h db -U postgres -c "DROP DATABASE IF EXISTS uplift"
;;
migrate)
# Run database migrations.
docker exec -it oak-bike python manage.py migrate $args
;;
test)
# Run the tests against a test database, from a test container.
# Useful for running Django shell commands.
if ! docker inspect oak-bike-db-test > /dev/null 2> /dev/null; then
docker run \
--detach \
--name oak-bike-db-test \
--env-file=.env \
postgres
fi
docker start oak-bike-db-test > /dev/null
# in a while loop wait for the db test container to really start
until docker exec -it oak-bike-db-test psql -U postgres -c '\q' > /dev/null 2> /dev/null; do
sleep 0.5
done
docker exec -it oak-bike-db-test psql -U postgres -c "DROP DATABASE IF EXISTS uplift"
docker exec -it oak-bike-db-test psql -U postgres -c "CREATE DATABASE uplift"
docker run \
-it --rm \
--name oak-bike-test \
--link oak-bike-db-test:db \
-v $(pwd):/code:rw \
--env-file=.env \
-e IS_TESTING=true \
oak-bike \
test $args
;;
'')
echo 'Usage: ./d action [params]. For a list of actions, run ./d help'
;;
*)
echo 'Unknown action '$task'. For a list of the available actions, run ./d help'
;;
esac