forked from Weasyl/weasyl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wzl
executable file
·118 lines (97 loc) · 2.94 KB
/
wzl
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
#!/bin/sh
set -eu
export DOCKER_BUILDKIT=1
export WEASYL_VERSION="$(git rev-parse --short HEAD)"
# `docker-compose` is fast and easy to check for, so we fall back on `docker compose` instead of the other way around.
if command -v docker-compose > /dev/null; then
docker_compose='docker-compose'
else
docker_compose='docker compose'
fi
if test $# -eq 0; then
exec $docker_compose
fi
head="$1"
shift
check_nobuild() {
if test "$2" = --nobuild; then
return 0
fi
$docker_compose build "$1" || exit $?
return 1
}
case "$head" in
assets)
$docker_compose create "$@" build-assets
$docker_compose cp ./assets build-assets:/weasyl-build/
container_id="$($docker_compose ps -a --format=json build-assets | grep -o '"ID":"[^"]*"' | cut -d '"' -f 4)"
exec docker start -ai "$container_id"
;;
check)
if check_nobuild flake8 "${1:-}"; then shift; fi
exec $docker_compose run --rm -T flake8 "$@"
;;
configure)
c="$docker_compose run --rm -T configure"
set -x
$c "$@" alembic.ini < libweasyl/alembic/alembic.ini.example
$c "$@" site.config.txt < config/site.config.txt.example
$c "$@" weasyl-staff.py < config/weasyl-staff.example.py
$c "$@" disposable-domains.txt < config/disposable-domains.txt
;;
migrate)
if check_nobuild migrate "${1:-}"; then shift; fi
exec $docker_compose run --rm -T migrate "$@"
;;
revision)
if check_nobuild revision "${1:-}"; then shift; fi
exec $docker_compose run --rm -T revision "$@" | tar x libweasyl/alembic/versions
;;
test)
if check_nobuild test "${1:-}"; then shift; fi
exec $docker_compose run --rm test "$@"
;;
test-coverage)
if check_nobuild test "${1:-}"; then shift; fi
if test $# -eq 0; then
set -- sh -c '
coverage run -m pytest libweasyl.test libweasyl.models.test
coverage run -m pytest weasyl.test
coverage combine
coverage html -d coverage
'
fi
exec $docker_compose run --rm test "$@"
;;
poetry)
docker build --target bdist -t weasyl-poetry .
exit_code=1
if docker run --name=weasyl-poetry --init -it weasyl-poetry .poetry-venv/bin/poetry "$@"; then
docker cp weasyl-poetry:/weasyl/pyproject.toml ./
docker cp weasyl-poetry:/weasyl/poetry.lock ./
exit_code=0
fi
docker container rm weasyl-poetry
docker image rm weasyl-poetry
exit $exit_code
;;
npm)
docker build --target asset-builder -t weasyl-npm .
exit_code=1
if
docker run --name=weasyl-npm --init -it weasyl-npm npm "$@" \
&& docker cp weasyl-npm:/weasyl-build/package.json ./ \
&& docker cp weasyl-npm:/weasyl-build/package-lock.json ./
then
exit_code=0
fi
docker container rm weasyl-npm
docker image rm weasyl-npm
exit $exit_code
;;
push-templates)
docker cp weasyl/templates weasyl-web-1:/weasyl/weasyl/
;;
*)
exec $docker_compose "$head" "$@"
esac