.envrc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. fi
  100. ### System ###
  101. for pkg in \
  102. make \
  103. docker \
  104. chromedriver \
  105. openssl; do
  106. if ! require "$pkg"; then
  107. die "You seem to be missing the system dependency: ${pkg}
  108. Please install homebrew, and run brew bundle."
  109. fi
  110. done
  111. ### Git ###
  112. debug "Configuring git..."
  113. make setup-git-config
  114. ### Python ###
  115. if [ -f .venv/bin/devenv ]; then
  116. DEVENV=.venv/bin/devenv
  117. else
  118. DEVENV=devenv
  119. fi
  120. export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-$XDG_DATA_HOME/sentry-devenv}"
  121. PATH_add "${SENTRY_DEVENV_HOME}/bin"
  122. if ! command -v "$DEVENV" >/dev/null; then
  123. die '
  124. Please install the devenv tool:
  125. https://github.com/getsentry/devenv#install
  126. '
  127. fi
  128. PATH_add .venv/bin
  129. export VIRTUAL_ENV="$PWD/.venv"
  130. if ! require sentry; then
  131. warn "Your virtualenv is activated, but sentry doesn't seem to be installed."
  132. commands_to_run+=("devenv sync")
  133. fi
  134. # this is the standard repo-local bin root
  135. PATH_add "${PWD}/.devenv/bin"
  136. ### pre-commit ###
  137. debug "Checking pre-commit..."
  138. if ! require pre-commit; then
  139. warn "Looks like you don't have pre-commit installed."
  140. commands_to_run+=("make setup-git")
  141. fi
  142. python3 -m tools.docker_memory_check
  143. ### Node ###
  144. debug "Checking node..."
  145. if ! require node; then
  146. die "You don't seem to have node installed. Install volta (a node version manager): https://develop.sentry.dev/environment/#javascript"
  147. fi
  148. make node-version-check
  149. if [ ! -x "node_modules/.bin/webpack" ]; then
  150. warn "You don't seem to have yarn packages installed."
  151. commands_to_run+=("make install-js-dev")
  152. fi
  153. PATH_add node_modules/.bin
  154. # These are commands that can take a significant amount of time
  155. if [ ${#commands_to_run[@]} -ne 0 ]; then
  156. show_commands_info
  157. fi
  158. if [ "${complete_success}" != "yup" ]; then
  159. help_message
  160. warn "\nPartial success. The virtualenv is active, however, you're not fully up-to-date (see messages above)."
  161. else
  162. echo "${green}${bold}SUCCESS!${reset}"
  163. fi
  164. # Since we can't use an EXIT routine we need to guarantee we delete the file here
  165. [ -z "$_SENTRY_LOG_FILE" ] || rm -f "$_SENTRY_LOG_FILE"