.envrc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/not/executable/bash
  2. # This is the .envrc for sentry, for use with direnv.
  3. # It's responsible for enforcing a standard dev environment by checking as much state as possible, and either performing
  4. # initialization (e.g. activating the venv) or giving recommendations on how to reach the desired state.
  5. # It also sets useful environment variables.
  6. # If you'd like to override or set any custom environment variables, this .envrc will read a .env file at the end.
  7. set -e
  8. # Upgrading Mac can uninstall the Command Line Tools, thus, removing our access to git
  9. # The message talks about xcrun, however, we can use the lack of git as a way to know that we need this
  10. # xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
  11. # missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  12. if [ "$(uname -s)" == "Darwin" ] && [ ! -f "/Library/Developer/CommandLineTools/usr/bin/git" ]; then
  13. echo -e "$(tput setaf 1)\nERROR: Complete the interactive installation (10+ mins) of the Command Line Tools.$(tput sgr0)"
  14. xcode-select --install
  15. return 1
  16. fi
  17. SENTRY_ROOT="$(
  18. cd "$(dirname "${BASH_SOURCE[0]}")"
  19. pwd -P
  20. )"
  21. source "${SENTRY_ROOT}/scripts/lib.sh"
  22. # XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
  23. # consequently, using "exit" anywhere will skip this notice from showing.
  24. # so need to use set -e, and return 1.
  25. trap notice ERR
  26. complete_success="yup"
  27. help_message() {
  28. cat <<EOF
  29. For more help run: make direnv-help
  30. EOF
  31. }
  32. failure_message() {
  33. cat <<EOF
  34. ${red}${bold}direnv wasn't able to complete execution.
  35. You may have been given some recommendations in the error message.
  36. Follow them, and then you'll need to re-run direnv by running "direnv allow".${reset}
  37. EOF
  38. help_message
  39. }
  40. notice() {
  41. [ $? -eq 0 ] && return
  42. failure_message
  43. }
  44. debug() {
  45. if [ "${SENTRY_DIRENV_DEBUG-}" ]; then
  46. echo -e "${@}"
  47. fi
  48. }
  49. info() {
  50. echo -e "${bold}${*}${reset}"
  51. }
  52. warn() {
  53. echo -e "${yellow}${*}${reset}" >&2
  54. complete_success="nope"
  55. }
  56. die() {
  57. echo -e "${red}${bold}FATAL: ${*}${reset}" >&2
  58. return 1
  59. }
  60. show_commands_info() {
  61. echo -e "\n${red}Run the following commands to bring your environment up-to-date:"
  62. for cmd in "${commands_to_run[@]}"; do
  63. warn " ${red}$cmd"
  64. done
  65. echo ""
  66. }
  67. ### Environment ###
  68. commands_to_run=()
  69. # Always write stdout immediately. Very helpful for debugging
  70. export PYTHONUNBUFFERED=1
  71. # make sure we don't have any conflicting PYTHONPATH
  72. unset PYTHONPATH
  73. # don't check pypi for a potential new pip version; low-hanging fruit to save a bit of time
  74. export PIP_DISABLE_PIP_VERSION_CHECK=on
  75. # increase node's memory limit, required for our webpacking
  76. export NODE_OPTIONS=--max-old-space-size=4096
  77. # Frontend hot module reloader using `react-refresh`
  78. # Enable this by default for development envs (CI/deploys do not use envrc)
  79. export SENTRY_UI_HOT_RELOAD=1
  80. ### You can override the exported variables with a .env file
  81. # All exports should happen before here unless they're safeguarded (see devenv error reporting below)
  82. if [ -f "${SENTRY_ROOT}/.env" ]; then
  83. info "Loading variables from ${SENTRY_ROOT}/.env"
  84. dotenv "${SENTRY_ROOT}/.env"
  85. fi
  86. ## Notify of reporting to Sentry
  87. if [ -n "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
  88. debug "No development environment errors will be reported (since you've defined SENTRY_DEVENV_NO_REPORT)."
  89. _SENTRY_LOG_FILE=''
  90. else
  91. # Since direnv traps the EXIT signal we place the temp file under /tmp for the odd time
  92. # the script will use the EXIT path
  93. _SENTRY_LOG_FILE=$(mktemp /tmp/sentry.envrc.$$.out || mktemp /tmp/sentry.envrc.XXXXXXXX.out)
  94. exec > >(tee "$_SENTRY_LOG_FILE")
  95. exec 2>&1
  96. debug "Development errors will be reported to Sentry.io. If you wish to opt-out, set SENTRY_DEVENV_NO_REPORT as an env variable."
  97. # This will allow `sentry devservices` errors to be reported
  98. export SENTRY_DEVSERVICES_DSN=https://23670f54c6254bfd9b7de106637808e9@o1.ingest.sentry.io/1492057
  99. # This will allow metrics to be sent to the `sentry-devservices` project (in the Sentry SDKs org).
  100. export SENTRY_DSN=https://8ae521d2441786bb405b3b3705bb9dc1@o447951.ingest.us.sentry.io/4507346183716864
  101. fi
  102. ### System ###
  103. for pkg in \
  104. make \
  105. docker \
  106. chromedriver \
  107. openssl; do
  108. if ! require "$pkg"; then
  109. die "You seem to be missing the system dependency: ${pkg}
  110. Please install homebrew, and run brew bundle."
  111. fi
  112. done
  113. ### Git ###
  114. debug "Configuring git..."
  115. make setup-git-config
  116. ### Python ###
  117. if [ -f .venv/bin/devenv ]; then
  118. DEVENV=.venv/bin/devenv
  119. else
  120. DEVENV=devenv
  121. fi
  122. export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-$XDG_DATA_HOME/sentry-devenv}"
  123. PATH_add "${SENTRY_DEVENV_HOME}/bin"
  124. if ! command -v "$DEVENV" >/dev/null; then
  125. die '
  126. Please install the devenv tool:
  127. https://github.com/getsentry/devenv#install
  128. '
  129. fi
  130. PATH_add .venv/bin
  131. export VIRTUAL_ENV="$PWD/.venv"
  132. if ! require sentry; then
  133. warn "Your virtualenv is activated, but sentry doesn't seem to be installed."
  134. commands_to_run+=("devenv sync")
  135. fi
  136. # this is the standard repo-local bin root
  137. PATH_add "${PWD}/.devenv/bin"
  138. ### pre-commit ###
  139. debug "Checking pre-commit..."
  140. if ! require pre-commit; then
  141. warn "Looks like you don't have pre-commit installed."
  142. commands_to_run+=("make setup-git")
  143. fi
  144. python3 -m tools.docker_memory_check
  145. ### Node ###
  146. debug "Checking node..."
  147. if ! require node; then
  148. die "You don't seem to have node installed. Install volta (a node version manager): https://develop.sentry.dev/environment/#javascript"
  149. fi
  150. make node-version-check
  151. if [ ! -x "node_modules/.bin/webpack" ]; then
  152. warn "You don't seem to have yarn packages installed."
  153. commands_to_run+=("make install-js-dev")
  154. fi
  155. PATH_add node_modules/.bin
  156. # These are commands that can take a significant amount of time
  157. if [ ${#commands_to_run[@]} -ne 0 ]; then
  158. show_commands_info
  159. fi
  160. if [ "${complete_success}" != "yup" ]; then
  161. help_message
  162. warn "\nPartial success. The virtualenv is active, however, you're not fully up-to-date (see messages above)."
  163. else
  164. echo "${green}${bold}SUCCESS!${reset}"
  165. fi
  166. # Since we can't use an EXIT routine we need to guarantee we delete the file here
  167. [ -z "$_SENTRY_LOG_FILE" ] || rm -f "$_SENTRY_LOG_FILE"