-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrapper
executable file
·251 lines (223 loc) · 6.12 KB
/
wrapper
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
#!/bin/bash
# ----- Helper functions -----
print_usage() {
echo "$SCRIPT_NAME -h|--help"
echo "$SCRIPT_NAME [OPTIONS] COMMAND [ARGS...]"
echo
echo "Options:"
echo " -d Detach from container after action. Ignored except for:"
echo " bundle, exec, migrate, start"
echo
echo "Commands:"
echo " build Build diaspora:dev-latest. Rebuild if exists"
echo " bundle Install gems into the linked source folder using bundle"
echo " clean Delete all diaspora*-related containers and volumes"
echo " including database"
echo " config Creates diaspora.yml and database.yml and configures for use"
echo " with PostgreSQL"
echo " cucumber Run all cucumber tests, or only ARGS if given"
echo " exec Execute ARGS in the project folder inside the running"
echo " diaspora* container, or, if none is running, use a new one"
echo " jasmine Run all jasmine tests"
echo " migrate Execute pending migrations (incl. database setup)"
echo " restart Fast restart using bin/eye"
echo " rspec Run all rspec tests, or only ARGS if given"
echo " setup Alias for, in that order:"
echo " build, config, bundle, migrate, setup-tests"
echo " setup-tests Creates files and database structures for tests"
echo " start Start diaspora* incl. database"
echo " status Show currently running containers and related images"
echo " stop Stop all diaspora*-related containers"
}
dia_fetch_upstream() {
if ! git remote show | grep -q '^upstream$'; then
git remote add upstream https://github.com/diaspora/diaspora.git
fi
git fetch upstream develop
}
dia_is_configured() {
if [ -f "$DIASPORA_CONFIG_DB" ] \
&& [ -f "$DIASPORA_CONFIG_DIA" ]; then
return 0
else
return 1
fi
}
exit_unconfigured() {
echo "Fatal: Not properly configured. Run the 'setup' or 'config' command to configure."
exit 1
}
# ----- Command functions -----
dia_build() {
if [ -z "$UID" -o -z "$GID" ]; then
# $UID is not builtin, determine using a program
if ! type "id" 2>&1 >/dev/null; then
echo "Fatal: Cannot determine UID or GID."
exit 1
fi
EXT_UID=$(id -u)
EXT_GID=$(id -g)
else
EXT_UID=$UID
EXT_GID=$GID
fi
docker-compose build \
--build-arg EXT_UID=$EXT_UID \
--build-arg EXT_GID=$EXT_GID \
diaspora
}
dia_bundle() {
docker-compose run --rm --no-deps $option diaspora /bin/sh -c "script/configure_bundler && bin/bundle install --full-index"
}
dia_clean() {
docker-compose down
}
dia_config() {
[ ! -f "$DIASPORA_PATH"/public/source.tar.gz ] && touch "$DIASPORA_PATH"/public/source.tar.gz
[ ! -f "$DIASPORA_CONFIG_DIA" ] && cp "$DIASPORA_CONFIG_DIA".example "$DIASPORA_CONFIG_DIA"
[ ! -f "$DIASPORA_CONFIG_DB" ] && cp "$DIASPORA_CONFIG_DB".example "$DIASPORA_CONFIG_DB"
}
dia_cucumber() {
docker-compose run --rm $option diaspora bin/cucumber "$@"
}
dia_exec() {
! dia_is_configured && exit_unconfigured
if docker-compose ps --services --filter status=running | grep -q '^diaspora$'; then
docker-compose exec $option diaspora "$@"
else
echo "No running instance found, starting containers..."
docker-compose run --rm $option diaspora "$@"
fi
}
dia_jasmine() {
docker-compose run --rm $option diaspora /bin/bash -c 'RAILS_ENV=test bin/rake tests:generate_fixtures && RAILS_ENV=test bin/rake jasmine:ci'
}
dia_migrate() {
# TODO maybe if db was not running before, stop it again
! dia_is_configured && exit_unconfigured
docker-compose run --rm $option diaspora bin/rake db:create db:migrate
}
dia_pronto() {
! dia_is_configured && exit_unconfigured
cd "$DIASPORA_PATH"
if git diff-index --quiet HEAD --; then
dia_fetch_upstream
fi
cd - >/dev/null
docker-compose run --rm --no-deps diaspora bin/pronto run --unstaged -c upstream/develop
}
dia_restart() {
if docker-compose ps --services --filter status=running | grep -q '^diaspora$'; then
docker-compose exec diaspora bin/eye restart diaspora
else
dia_start
fi
}
dia_rspec() {
! dia_is_configured && exit_unconfigured
addendum=""
[ -f "$DIASPORA_PATH"/public/404.html ] && addendum="assets:generate_error_pages"
docker-compose run --rm diaspora /bin/sh -c "RAILS_ENV=test bin/rake db:create db:migrate ${addendum}"
docker-compose run --rm diaspora bin/rspec "$@"
}
dia_setup() {
dia_build
dia_config
dia_bundle
dia_migrate
dia_setup_tests
}
dia_setup_tests() {
docker-compose run --rm diaspora /bin/sh -c "RAILS_ENV=test bin/rake db:create db:migrate tests:generate_fixtures assets:generate_error_pages"
}
dia_start() {
! dia_is_configured && exit_unconfigured
docker-compose up $option diaspora
}
dia_status() {
docker-compose ps
docker-compose images
}
dia_stop() {
docker-compose stop
}
# ----- Variables -----
SCRIPT_NAME=$(basename $0)
SCRIPT_PATH="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)"
export DIASPORA_PATH="./diaspora.docker"
export DIASPORA_CONFIG_DIA="$DIASPORA_PATH/config/diaspora.yml"
export DIASPORA_CONFIG_DB="$DIASPORA_PATH/config/database.yml"
DIASPORA_DOCKER_DB=postgresql
if [ -f "$DIASPORA_CONFIG_DB" ] && grep -qE '^\s*<<:\s*\*mysql\b' "$DIASPORA_CONFIG_DB"; then
DIASPORA_DOCKER_DB=mysql
fi
export DIASPORA_DOCKER_DB
# ----- Arg parsing -----
if [ $# -lt 1 ]; then
print_usage
exit 1
fi
if [ $# -gt 0 ] && [ "$1" == "-d" ]; then
export option="-d"
shift
fi
dia_command=$1
shift
case $dia_command in
--help|-h)
print_usage
exit 0
;;
build)
dia_build
;;
bundle)
dia_bundle
;;
clean)
dia_clean
;;
config)
dia_config
;;
cucumber)
dia_cucumber "$@"
;;
exec)
dia_exec "$@"
;;
jasmine)
dia_jasmine
;;
migrate)
dia_migrate
;;
pronto)
dia_pronto
;;
restart)
dia_restart
;;
rspec)
dia_rspec "$@"
;;
setup)
dia_setup
;;
setup-tests)
dia_setup_tests
;;
start)
dia_start
;;
status)
dia_status
;;
stop)
dia_stop
;;
*)
print_usage
exit 1
;;
esac