lib.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # NOTE: This file is sourced in CI across different repos (e.g. snuba),
  3. # thus, renaming this file or any functions can break CI!
  4. #
  5. # Module containing code shared across various shell scripts
  6. # Execute functions from this module via the script do.sh
  7. # shellcheck disable=SC2034 # Unused variables
  8. # shellcheck disable=SC2001 # https://github.com/koalaman/shellcheck/wiki/SC2001
  9. POSTGRES_CONTAINER="sentry-postgres-1"
  10. USE_OLD_DEVSERVICES=${USE_OLD_DEVSERVICES:-"0"}
  11. if [ "$USE_OLD_DEVSERVICES" == "1" ]; then
  12. POSTGRES_CONTAINER="sentry_postgres"
  13. fi
  14. venv_name=".venv"
  15. # XDG paths' standardized defaults:
  16. # (see https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables )
  17. export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
  18. export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
  19. export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
  20. export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
  21. export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
  22. export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
  23. export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/var/run}"
  24. # Check if a command is available
  25. require() {
  26. command -v "$1" >/dev/null 2>&1
  27. }
  28. sudo-askpass() {
  29. if [ -z "${sudo-askpass-x}" ]; then
  30. sudo --askpass "$@"
  31. else
  32. sudo "$@"
  33. fi
  34. }
  35. init-config() {
  36. sentry init --dev --no-clobber
  37. }
  38. run-dependent-services() {
  39. sentry devservices up
  40. }
  41. create-db() {
  42. container_name=${POSTGRES_CONTAINER}
  43. echo "--> Creating 'sentry' database"
  44. docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 sentry || true
  45. echo "--> Creating 'control', 'region' and 'secondary' database"
  46. docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 control || true
  47. docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 region || true
  48. docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 secondary || true
  49. }
  50. apply-migrations() {
  51. create-db
  52. echo "--> Applying migrations"
  53. sentry upgrade --noinput
  54. }
  55. create-superuser() {
  56. echo "--> Creating a superuser account"
  57. if [[ -n "${GITHUB_ACTIONS+x}" ]]; then
  58. sentry createuser --superuser --email foo@tbd.com --no-password --no-input
  59. else
  60. sentry createuser --superuser --email admin@sentry.io --password admin --no-input
  61. echo "Password is admin."
  62. fi
  63. }
  64. build-platform-assets() {
  65. echo "--> Building platform assets"
  66. python3 -m sentry.build._integration_docs
  67. # make sure this didn't silently do nothing
  68. test -f src/sentry/integration-docs/android.json
  69. }
  70. clean() {
  71. echo "--> Cleaning static cache"
  72. rm -rf dist/* src/sentry/static/sentry/dist/*
  73. echo "--> Cleaning integration docs cache"
  74. rm -rf src/sentry/integration-docs
  75. echo "--> Cleaning pyc files"
  76. find . -name "*.pyc" -delete
  77. echo "--> Cleaning python build artifacts"
  78. rm -rf build/ dist/ src/sentry/assets.json
  79. echo ""
  80. }
  81. drop-db() {
  82. container_name=${POSTGRES_CONTAINER}
  83. echo "--> Dropping existing 'sentry' database"
  84. docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres sentry
  85. echo "--> Dropping 'control' and 'region' database"
  86. docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres control
  87. docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres region
  88. docker exec "${container_name}" dropdb --if-exists -h 127.0.0.1 -U postgres secondary
  89. }
  90. reset-db() {
  91. drop-db
  92. apply-migrations
  93. create-superuser
  94. echo 'Finished resetting database. To load mock data, run `./bin/load-mocks`'
  95. }