|
@@ -0,0 +1,208 @@
|
|
|
+# This is the .envrc for sentry, for use with direnv.
|
|
|
+# It's responsible for enforcing a standard dev environment by checking as much state as possible, and either performing
|
|
|
+# initialization (e.g. activating the venv) or giving recommendations on how to reach the desired state.
|
|
|
+# It also sets useful environment variables.
|
|
|
+# If you'd like to override or set any custom environment variables, this .envrc will read a .env file at the end.
|
|
|
+
|
|
|
+set -e
|
|
|
+
|
|
|
+bold="$(tput bold)"
|
|
|
+red="$(tput setaf 1)"
|
|
|
+green="$(tput setaf 2)"
|
|
|
+reset="$(tput sgr0)"
|
|
|
+
|
|
|
+# XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
|
|
|
+# consequently, using "exit" anywhere will skip this notice from showing.
|
|
|
+# so need to use set -e, and return 1.
|
|
|
+trap notice ERR
|
|
|
+
|
|
|
+notice () {
|
|
|
+ [ $? -eq 0 ] && return
|
|
|
+ cat <<EOF
|
|
|
+${red}${bold}direnv wasn't able to complete execution.
|
|
|
+You may have been given some recommendations in the error message.
|
|
|
+Follow them, and then you'll need to redo direnv by running "direnv allow".${reset}
|
|
|
+
|
|
|
+direnv tooling is in an ALPHA state!
|
|
|
+If you're having trouble, or have questions, please ask in #discuss-dev-tooling
|
|
|
+and/or reach out to @josh.
|
|
|
+EOF
|
|
|
+}
|
|
|
+
|
|
|
+require () {
|
|
|
+ command -v "$1" 2>&1 > /dev/null
|
|
|
+}
|
|
|
+
|
|
|
+info () {
|
|
|
+ cat <<EOF
|
|
|
+${bold}direnv: ${1}${reset}
|
|
|
+EOF
|
|
|
+}
|
|
|
+
|
|
|
+die () {
|
|
|
+ >&2 cat <<EOF
|
|
|
+${red}${bold}direnv FATAL: ${1}
|
|
|
+${reset}
|
|
|
+EOF
|
|
|
+ return 1
|
|
|
+}
|
|
|
+
|
|
|
+init_venv () {
|
|
|
+ deactivate 2>/dev/null || true
|
|
|
+ info "Creating a virtualenv for you."
|
|
|
+ require python2.7 || \
|
|
|
+ die "You'll need to install python2.7, or make it available on your PATH.
|
|
|
+It's recommended to use pyenv - please refer to https://docs.sentry.io/development/contribute/environment"
|
|
|
+ python2.7 -m virtualenv .venv
|
|
|
+}
|
|
|
+
|
|
|
+### Environment ###
|
|
|
+
|
|
|
+# don't write *.pyc files; using stale python code occasionally causes subtle problems
|
|
|
+export PYTHONDONTWRITEBYTECODE=1
|
|
|
+
|
|
|
+# don't check pypi for a potential new pip version; low-hanging fruit to save a bit of time
|
|
|
+export PIP_DISABLE_PIP_VERSION_CHECK=on
|
|
|
+
|
|
|
+# increase node's memory limit, required for our webpacking
|
|
|
+export NODE_OPTIONS=--max-old-space-size=4096
|
|
|
+
|
|
|
+
|
|
|
+### System ###
|
|
|
+
|
|
|
+for pkg in \
|
|
|
+ make \
|
|
|
+ docker \
|
|
|
+ chromedriver \
|
|
|
+ pkg-config \
|
|
|
+ openssl ;
|
|
|
+ do
|
|
|
+ if ! require "$pkg"; then
|
|
|
+ die "You seem to be missing the system dependency: ${pkg}
|
|
|
+Please install homebrew, and run brew bundle."
|
|
|
+ fi
|
|
|
+done
|
|
|
+
|
|
|
+
|
|
|
+### Python ###
|
|
|
+
|
|
|
+info "Checking virtualenv..."
|
|
|
+
|
|
|
+# direnv set -u's, so we need to do this.
|
|
|
+VIRTUAL_ENV="${VIRTUAL_ENV:-}"
|
|
|
+
|
|
|
+if [ -n "$VIRTUAL_ENV" ]; then
|
|
|
+ # we're enforcing that virtualenv be in .venv, since future tooling e.g. venv-update will rely on this.
|
|
|
+ if [ "$VIRTUAL_ENV" != "${PWD}/.venv" ]; then
|
|
|
+ info "You're in a virtualenv, but it's not in the expected location (${PWD}/.venv)"
|
|
|
+ init_venv
|
|
|
+ fi
|
|
|
+else
|
|
|
+ if [ ! -f ".venv/bin/activate" ]; then
|
|
|
+ info "You don't seem to have a virtualenv."
|
|
|
+ init_venv
|
|
|
+ fi
|
|
|
+fi
|
|
|
+
|
|
|
+info "Activating virtualenv."
|
|
|
+source .venv/bin/activate
|
|
|
+[ "$(command -v python)" != "${PWD}/.venv/bin/python" ] && die "Failed to activate virtualenv."
|
|
|
+
|
|
|
+python -c "import sys; sys.exit(sys.version_info[:2] != (2, 7))" || \
|
|
|
+ die "For some reason, the virtualenv isn't Python 2.7."
|
|
|
+
|
|
|
+if [ "$(command -v sentry)" != "${PWD}/.venv/bin/sentry" ]; then
|
|
|
+ info "Your .venv is activated, but sentry doesn't seem to be installed. Let's install it."
|
|
|
+ make ensure-pinned-pip
|
|
|
+ SENTRY_LIGHT_BUILD=1 make install-sentry-dev
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+### pre-commit ###
|
|
|
+
|
|
|
+info "Checking pre-commit..."
|
|
|
+
|
|
|
+# this is cheap, so we'll just do it every time
|
|
|
+ln -sf config/hooks/* .git/hooks
|
|
|
+
|
|
|
+if ! require pre-commit; then
|
|
|
+ info "Looks like you don't have pre-commit installed. Let's install it."
|
|
|
+ make setup-git
|
|
|
+fi
|
|
|
+
|
|
|
+# this hotfix is cheap too, so just run it every time
|
|
|
+rm -f .git/hooks/pre-commit.legacy
|
|
|
+
|
|
|
+
|
|
|
+### devservices ###
|
|
|
+
|
|
|
+info "Checking devservices..."
|
|
|
+
|
|
|
+# XXX: these container names are hardcoded for now
|
|
|
+# NOTE: sentry_symbolicator isn't started up by devservices, and is behind a config flag, so we're not checking for it
|
|
|
+for container in \
|
|
|
+ sentry_postgres \
|
|
|
+ sentry_clickhouse \
|
|
|
+ sentry_snuba \
|
|
|
+ sentry_redis ;
|
|
|
+ do
|
|
|
+ docker exec "$container" true || die "The docker container ${container} doesn't seem to be running.
|
|
|
+Please run sentry devservices up."
|
|
|
+done
|
|
|
+
|
|
|
+
|
|
|
+### database ###
|
|
|
+
|
|
|
+info "Checking database..."
|
|
|
+
|
|
|
+if ! docker exec sentry_postgres sh \
|
|
|
+ -c "psql -U postgres -h 127.0.0.1 sentry --command 'select 1 from sentry_useremail'" >/dev/null;
|
|
|
+ then
|
|
|
+ die "It doesn't look like you have a database for sentry yet - you'll need to run 'make reset-db'."
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+### Node ###
|
|
|
+
|
|
|
+info "Checking node..."
|
|
|
+
|
|
|
+node_version="10.16.3"
|
|
|
+
|
|
|
+# It would be nice to enforce that node is installed via volta (and is therefore a shim that will check against
|
|
|
+# the node pin in package.json), but for now, let's just explicitly check the node version.
|
|
|
+
|
|
|
+if ! require node; then
|
|
|
+ die "You don't seem to have node installed. We want version ${node_version}.
|
|
|
+It's recommended to use volta - please refer to https://docs.sentry.io/development/contribute/environment"
|
|
|
+fi
|
|
|
+
|
|
|
+if [ "$(node -v)" != "v${node_version}" ]; then
|
|
|
+ die "Your node version doesn't match ${node_version}.
|
|
|
+It's recommended to use volta - please refer to https://docs.sentry.io/development/contribute/environment"
|
|
|
+fi
|
|
|
+
|
|
|
+if [ ! -x "node_modules/.bin/webpack" ]; then
|
|
|
+ info "You don't seem to have yarn packages installed. Let's install them."
|
|
|
+ make install-yarn-pkgs
|
|
|
+fi
|
|
|
+
|
|
|
+PATH_add node_modules/.bin
|
|
|
+
|
|
|
+
|
|
|
+### Overrides ###
|
|
|
+
|
|
|
+if [ -f '.env' ]; then
|
|
|
+ info ".env found. Reading it..."
|
|
|
+ dotenv .env
|
|
|
+fi
|
|
|
+
|
|
|
+cat <<EOF
|
|
|
+${green}${bold}direnv: SUCCESS!
|
|
|
+${reset}
|
|
|
+direnv tooling is in an ALPHA state!
|
|
|
+If you're having trouble, or have questions, please ask in #discuss-dev-tooling
|
|
|
+and/or reach out to @josh.
|
|
|
+
|
|
|
+You can safely ignore the followiing "PS1 cannot be exported" message.
|
|
|
+
|
|
|
+EOF
|