123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- # 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)"
- yellow="$(tput setaf 3)"
- 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
- # This is used to group issues on Sentry.io.
- # If an issue does not call info() or die() it will be grouped under this
- error_message="Unknown issue"
- log_level="info"
- 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}
- If you're stuck or have questions, ask in #discuss-dev-tooling.
- EOF
- [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ] && report_to_sentry
- }
- report_to_sentry() {
- if ! require sentry-cli; then
- curl -sL https://sentry.io/get-cli/ | bash
- fi
- SENTRY_DSN=${SENTRY_DEVENV_DSN} \
- sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level
- rm "$_SENTRY_LOG_FILE"
- }
- require() {
- command -v "$1" >/dev/null 2>&1
- }
- warn() {
- cat <<EOF
- ${yellow}${bold}direnv: ${@}${reset}
- EOF
- }
- info() {
- cat <<EOF
- ${bold}direnv: ${@}${reset}
- EOF
- # info() calls happen multiple times in this script. The last info statement
- # is the one that will be used to group Sentry issues
- error_message=( "${@}" )
- }
- die() {
- cat >&2 <<EOF
- ${red}${bold}direnv FATAL: ${@}
- ${reset}
- EOF
- # When reporting to Sentry, this will allow grouping the errors differently
- # NOTE: The first line of the output is used to group issues
- error_message=( "${@}" )
- log_level="error"
- return 1
- }
- advice_init_venv() {
- venv_name="$1"
- deactivate 2>/dev/null || true
- info "To create a virtualenv, please type: python3.6 -m venv ${venv_name}"
- require "python3.6" ||
- die "You'll need to install python3, or make it available on your PATH.
- It's recommended to use pyenv - please refer to https://docs.sentry.io/development/contribute/environment"
- return 1
- }
- advice_install_sentry() {
- info "To install sentry, please type: make install-py-dev"
- return 1
- }
- advice_install_pre_commit() {
- info "To install pre-commit, please type: make setup-git"
- return 1
- }
- advice_install_yarn_pkgs() {
- info "To install yarn packages, please type: make install-js-dev"
- return 1
- }
- ### Environment ###
- # don't write *.pyc files; using stale python code occasionally causes subtle problems
- export PYTHONDONTWRITEBYTECODE=1
- # Always write stdout immediately. Very helpful for debugging
- export PYTHONUNBUFFERED=1
- # make sure we don't have any conflicting PYTHONPATH
- unset PYTHONPATH
- # 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
- # Frontend hot module reloader using `react-refresh`
- # Enable this by default for development envs (CI/deploys do not use envrc)
- export SENTRY_UI_HOT_RELOAD=1
- ### You can override the exported variables with a .env file
- # All exports should happen before here unless they're safeguarded (see devenv error reporting below)
- if [ -f '.env' ]; then
- info ".env found. Reading it..."
- dotenv .env
- fi
- ## Notify of reporting to Sentry
- if [ -n "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
- info "No development environment errors will be reported (since you've defined SENTRY_DEVENV_NO_REPORT)."
- else
- # Since direnv traps the EXIT signal we place the temp file under /tmp for the odd time
- # the script will use the EXIT path
- _SENTRY_LOG_FILE=$(mktemp /tmp/sentry.envrc.$$.out || mktemp /tmp/sentry.envrc.XXXXXXXX.out)
- exec > >(tee "$_SENTRY_LOG_FILE")
- exec 2>&1
- info "Development errors will be reported to Sentry.io."$'\n'" If you wish to opt-out, set SENTRY_DEVENV_NO_REPORT as an env variable."
- export SENTRY_DEVENV_DSN=https://23670f54c6254bfd9b7de106637808e9@o1.ingest.sentry.io/1492057
- fi
- ### System ###
- for pkg in \
- make \
- docker \
- chromedriver \
- pkg-config \
- pyenv \
- 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
- ### Git ###
- info "Configuring git..."
- make setup-git-config
- ### Python ###
- venv_name=".venv"
- info "Activating virtualenv..."
- if [ ! -f "${venv_name}/bin/activate" ]; then
- info "You don't seem to have a virtualenv."
- # If the version doesn't match the contents of .python-version it will fail
- [[ $(pyenv version) ]] || \
- die "pyenv does not have the right Python version installed. Please run:
- make setup-pyenv && python3.6 -m venv ${venv_name}"
- advice_init_venv "$venv_name"
- fi
- # The user might be cd'ing into sentry with another non-direnv managed
- # (in that it would be automatically deactivated) virtualenv active.
- deactivate 2>/dev/null || true
- source "${venv_name}/bin/activate"
- # XXX: ideally, direnv is able to export PS1 as modified by sourcing venvs
- # but we'd have to patch direnv, and ".venv" isn't descriptive anyways
- unset PS1
- info "Ensuring proper virtualenv..."
- ${PWD}/scripts/ensure-venv.sh
- if ! require sentry; then
- info "Your virtualenv is activated, but sentry doesn't seem to be installed."
- # XXX: if direnv fails, the venv won't be activated outside of direnv execution...
- # So, it is critical that make install-py-dev is guarded by scripts/ensure-venv.
- advice_install_sentry
- fi
- ### pre-commit ###
- info "Checking pre-commit..."
- if ! require pre-commit; then
- info "Looks like you don't have pre-commit installed."
- advice_install_pre_commit
- fi
- ### Node ###
- info "Checking node..."
- if ! require node; then
- die "You don't seem to have node installed. Install volta (a node version manager): https://develop.sentry.dev/environment/#javascript"
- fi
- make node-version-check
- if [ ! -x "node_modules/.bin/webpack" ]; then
- info "You don't seem to have yarn packages installed."
- advice_install_yarn_pkgs
- fi
- PATH_add node_modules/.bin
- ### Overrides ###
- cat <<EOF
- ${green}${bold}direnv: SUCCESS!
- ${reset}
- EOF
- if [ -z "${SENTRY_SILENCE_DIRENV_NOTICE:-}" ]; then
- cat <<EOF
- If you're stuck or have questions, ask in #discuss-dev-tooling.
- EOF
- fi
- # Since we can't use an EXIT routine we need to guarantee we delete the file here
- rm -f "$_SENTRY_LOG_FILE"
|