-
Notifications
You must be signed in to change notification settings - Fork 208
/
ov
executable file
·148 lines (114 loc) · 4.04 KB
/
ov
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
#! /usr/bin/env bash
set -e
# https://stackoverflow.com/a/1482133
OPENVERSE_PROJECT="$(dirname "$(readlink -f -- "$0")")"
export OPENVERSE_PROJECT
_self="$OPENVERSE_PROJECT/ov"
_cmd="$1"
dev_env="$OPENVERSE_PROJECT"/docker/dev_env
export DEV_ENV="$dev_env"
if [[ $_cmd == "help" || $_cmd == "-h" || $_cmd == "--help" || -z $_cmd ]]; then
cat <<-'EOF'
Openverse development toolkit
USAGE
ov <subcommand> [...ARGS]
COMMANDS
ov init
Initialise the Openverse development toolkit for the first time
Alias for:
ov build && ov setup-env && ov just install-hooks init-ov-profile install
ov build [...ARGS]
Build the Openverse development toolkit Docker image.
ARGS are passed to `docker build`. See `docker build --help` for options.
ov setup-env
Setup the environment inside the container. `ov init` automatically runs this,
and in most cases you should not need to run this manually. However, you may
occasionally need to run it manually if tool requirements inside the container
change. This can also be a helpful debugging step if tools in the container are
not working as expected.
ov stop
Stop the persistent `ov` Docker container.
ov doctor
Try some basic automated troubleshooting steps for common issues.
ov clean
Remove the Openverse development toolkit Docker container, image and volume.
Use in conjunction with `ov init` to recreate the environment from
scratch:
ov clean && ov init
Warning: running `ov clean` will result in needing to fully rebuild the environment
including downloading tools handled by `ov setup-env` and pre-commit environments.
ov hook HOOK
Run Git hooks through pre-commit inside the development toolkit container.
ov aliases [--help|-h]
Display information about ov aliases. By default, lists all available aliases.
Passing --help will print documentation about how to use and configure aliases.
ov COMMAND [...ARGS]
Run COMMAND inside the development toolkit container. COMMAND will be processed
through ov aliases (see `ov aliases --help` for details). ov is aware of your
current working directory and will execute the command relative to your current directory
inside the repository.
Tip: The toolkit comes loaded with many tools for working with Openverse! Try
some of the following:
- ov just
- ov pdm
- ov pnpm
- ov python
- ov bash
- ov jq
- ov http
EOF
exit 0
fi
case "$_cmd" in
init)
"$_self" build
"$_self" setup-env
"$_self" just install-hooks
"$_self" just init-ov-profile
"$_self" just install
;;
build)
# k6 does not install on aarch64, so we must specify the platform on macOS.
docker build "${@:2}" --tag openverse-dev_env:latest "$dev_env"
;;
setup-env)
"$_self" sudo bash "$dev_env"/setup_env.sh
;;
stop)
docker stop openverse-dev_env
;;
doctor)
# Expand these checks/fixes as needed
# Log a message for each fix so it's clear what is happening
printf "🩺 The Openverse Doctor is here to help... I will try to apply some basic fixes that might help.\n"
case "$OSTYPE" in
linux*)
# For some reason permissions can get mixed up in `/opt` and PDM will fail to create venvs
# This is only relevant to Linux hosts because macOS hosts run the container as root regardless
printf " - Fixing file permissions in container's /opt\n"
"$_self" sudo chmod -R 0777 /opt
;;
esac
;;
clean)
# Using `|| true` allows these commands to be skipped if the
# container, image or volume does not exist.
docker container stop openverse-dev_env || true
docker container rm openverse-dev_env || true
docker image rm openverse-dev_env || true
docker volume rm openverse_dev-env || true
rm -rf "$dev_env"/.cache
;;
hook)
# Arguments match the implementation of hooks installed by pre-commit
"$_self" pre-commit hook-impl \
--config=.pre-commit-config.yaml \
--hook-type="$2" \
--hook-dir "$OPENVERSE_PROJECT"/.git/hooks \
--color=always \
-- "${@:3}"
;;
*)
"$dev_env"/run.sh "$@"
;;
esac