-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathlib.sh
executable file
·110 lines (95 loc) · 3.59 KB
/
lib.sh
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
#!/bin/bash
# NOTE: This file is sourced in CI across different repos (e.g. snuba),
# thus, renaming this file or any functions can break CI!
#
# Module containing code shared across various shell scripts
# Execute functions from this module via the script do.sh
# shellcheck disable=SC2034 # Unused variables
# shellcheck disable=SC2001 # https://github.com/koalaman/shellcheck/wiki/SC2001
POSTGRES_CONTAINER="sentry-postgres-1"
USE_OLD_DEVSERVICES=${USE_OLD_DEVSERVICES:-"0"}
if [ "$USE_OLD_DEVSERVICES" == "1" ]; then
POSTGRES_CONTAINER="sentry_postgres"
fi
venv_name=".venv"
# XDG paths' standardized defaults:
# (see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables )
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/var/run}"
# Check if a command is available
require() {
command -v "$1" >/dev/null 2>&1
}
sudo-askpass() {
if [ -z "${sudo-askpass-x}" ]; then
sudo --askpass "$@"
else
sudo "$@"
fi
}
init-config() {
sentry init --dev --no-clobber
}
run-dependent-services() {
sentry devservices up
}
create-db() {
container_name=${POSTGRES_CONTAINER}
echo "--> Creating 'sentry' database"
docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 sentry || true
echo "--> Creating 'control', 'region' and 'secondary' database"
docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 control || true
docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 region || true
docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 secondary || true
}
apply-migrations() {
create-db
echo "--> Applying migrations"
sentry upgrade --noinput
}
create-superuser() {
echo "--> Creating a superuser account"
if [[ -n "${GITHUB_ACTIONS+x}" ]]; then
sentry createuser --superuser --email [email protected] --no-password --no-input
else
sentry createuser --superuser --email [email protected] --password admin --no-input
echo "Password is admin."
fi
}
build-platform-assets() {
echo "--> Building platform assets"
python3 -m sentry.build._integration_docs
# make sure this didn't silently do nothing
test -f src/sentry/integration-docs/android.json
}
clean() {
echo "--> Cleaning static cache"
rm -rf dist/* src/sentry/static/sentry/dist/*
echo "--> Cleaning integration docs cache"
rm -rf src/sentry/integration-docs
echo "--> Cleaning pyc files"
find . -name "*.pyc" -delete
echo "--> Cleaning python build artifacts"
rm -rf build/ dist/ src/sentry/assets.json
echo ""
}
drop-db() {
container_name=${POSTGRES_CONTAINER}
echo "--> Dropping existing 'sentry' database"
docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres sentry
echo "--> Dropping 'control' and 'region' database"
docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres control
docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres region
docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres secondary
}
reset-db() {
drop-db
apply-migrations
create-superuser
echo 'Finished resetting database. To load mock data, run `./bin/load-mocks`'
}