-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev
executable file
·161 lines (133 loc) · 2.93 KB
/
dev
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
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true
built_image_name="external-domain-broker-migrator-dev"
main() {
[[ $# -eq 0 ]] && usage "Expected command."
if [[ "${DEBUG+x}" ]] ; then
set -x
fi
cd "$(git rev-parse --show-toplevel)"
command="$1"
shift
case $command in
-h)
usage
;;
serve)
build_image
serve "$@"
;;
tests)
build_image
tests "$@"
;;
watch-tests)
build_image
watch-tests "$@"
;;
run)
build_image
run "$@"
;;
upgrade-requirements)
build_image
upgrade-requirements "$@"
;;
update-requirements)
build_image
update-requirements "$@"
;;
shell)
build_image
shell
;;
*)
usage "Unknown command: $command"
;;
esac
}
build_image() {
# The build-args are used to create a user with the same UID/GID as
# yourself. That way, any files written to the $PWD mount will be owned by
# you. This user is embedded in the docker image, so the resulting image
# should only be used locally. These arguments are not used in our
# concourse pipeline.
echo "Building image..."
docker build \
--quiet \
--file=docker/Dockerfile.dev \
--tag=${built_image_name} \
--build-arg UID="$(id -u)" \
--build-arg GID="$(id -g)" \
--build-arg USER="$USER" \
--build-arg base_image="ubuntu:22.04" \
.
}
run_docker() {
docker run \
--rm \
-it \
-v "$PWD:/app" \
"${built_image_name}" \
"$*"
}
run_docker_read_only() {
docker \
run \
--rm \
-it \
-v "$PWD:/app:ro" \
-v "$PWD/tmp:/app/tmp:rw" \
-v "$PWD/logs:/app/logs:rw" \
-v "$PWD/.pytest_cache:/app/.pytest_cache:rw" \
"${built_image_name}" \
"$*"
}
tests() {
run_docker_read_only docker/tests "$@"
}
watch-tests() {
run_docker_read_only docker/tests watch "$@"
}
run() {
run_docker "$@"
}
shell() {
run "./docker/start-servers.sh && bash"
}
update-requirements() {
run "docker/update-requirements-txt"
}
upgrade-requirements() {
run "docker/upgrade-requirements-txt"
}
usage() {
[[ $# -gt 0 ]] && echo "ERROR: $*"
local me=$(basename "$0")
cat <<-EOF
USAGE: $me COMMAND
Run workflows via the development docker image.
This provides a consistent developer experience, and avoids the "works on my
laptop" issue.
Examples:
# Run the tests once
$me
# Same as above
$me tests
# Continually watch for file changes and runs tests
$me watch-tests
# Start an interactive bash shell in the tests container
$me shell
# Generate the pip-tools/*requirements.txt files from
# pip-tools/*requirements.in
$me update-requirements
# upgrade versions in the *requirements.txt files from
# pip-tools/*requirements.in
$me upgrade-requirements
# Run command 'foo' in the container
$me run foo
EOF
exit 1
}
main "$@"