Browse Source

Revert "dev: move core make macros into devenv sync (#68379)" (#68728)

This reverts commit d0d1d957317429018ecae94f5e0c976ce199af27.
joshuarli 11 months ago
parent
commit
d38118821c
4 changed files with 91 additions and 95 deletions
  1. 7 11
      Makefile
  2. 8 80
      devenv/sync.py
  3. 1 1
      scripts/ensure-venv.sh
  4. 75 3
      scripts/lib.sh

+ 7 - 11
Makefile

@@ -3,28 +3,24 @@ all: develop
 
 PIP := python -m pip --disable-pip-version-check
 WEBPACK := yarn build-acceptance
+POSTGRES_CONTAINER := sentry_postgres
 
 freeze-requirements:
 	@python3 -S -m tools.freeze_requirements
 
 bootstrap \
 develop \
-install-js-dev \
-install-py-dev \
-apply-migrations: devenv-sync ;
-
-# This is to ensure devenv sync's only called once if the above
-# aliases are combined e.g. `make install-js-dev install-py-dev`
-.PHONY: devenv-sync
-devenv-sync:
-	devenv sync
-
 clean \
+init-config \
+run-dependent-services \
 drop-db \
 create-db \
+apply-migrations \
 reset-db \
 setup-git \
-node-version-check :
+node-version-check \
+install-js-dev \
+install-py-dev :
 	@./scripts/do.sh $@
 
 build-platform-assets \

+ 8 - 80
devenv/sync.py

@@ -69,9 +69,6 @@ def main(context: dict[str, str]) -> int:
     repo = context["repo"]
     reporoot = context["reporoot"]
 
-    # don't want this to be accidentally run from getsentry
-    assert repo == "sentry", repo
-
     venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, repo)
     url, sha256 = config.get_python(reporoot, python_version)
     print(f"ensuring {repo} venv at {venv_dir}...")
@@ -115,39 +112,8 @@ def main(context: dict[str, str]) -> int:
         reporoot,
         venv_dir,
         (
-            (
-                "javascript dependencies",
-                (
-                    "bash",
-                    "-euo",
-                    "pipefail",
-                    "-c",
-                    """
-NODE_ENV=development ./.devenv/bin/yarn install --frozen-lockfile
-yarn check --verify-tree || yarn install --check-files
-""",
-                ),
-            ),
-            (
-                "python dependencies",
-                (
-                    "bash",
-                    "-euo",
-                    "pipefail",
-                    "-c",
-                    """
-# install pinned pip
-pip install --constraint requirements-dev-frozen.txt pip
-
-# pip doesn't do well with swapping drop-ins
-pip uninstall -qqy djangorestframework-stubs django-stubs
-
-pip install -r requirements-dev-frozen.txt
-
-python3 -m tools.fast_editable --path .
-""",
-                ),
-            ),
+            ("javascript dependencies", ("make", "install-js-dev")),
+            ("python dependencies", ("make", "install-py-dev")),
         ),
     ):
         return 1
@@ -170,12 +136,12 @@ python3 -m tools.fast_editable --path .
     if not os.path.exists(f"{constants.home}/.sentry/config.yml") or not os.path.exists(
         f"{constants.home}/.sentry/sentry.conf.py"
     ):
-        proc.run((f"{venv_dir}/bin/sentry", "init", "--dev", "--no-clobber"))
+        proc.run((f"{venv_dir}/bin/sentry", "init", "--dev"))
 
     # TODO: check healthchecks for redis and postgres to short circuit this
     proc.run(
         (
-            f"{venv_dir}/bin/sentry",
+            f"{venv_dir}/bin/{repo}",
             "devservices",
             "up",
             "redis",
@@ -185,55 +151,17 @@ python3 -m tools.fast_editable --path .
         exit=True,
     )
 
-    if not run_procs(
+    if run_procs(
         repo,
         reporoot,
         venv_dir,
         (
             (
                 "python migrations",
-                (
-                    "bash",
-                    "-euo",
-                    "pipefail",
-                    "-c",
-                    """
-make create-db
-sentry upgrade --noinput
-""",
-                ),
+                ("make", "apply-migrations"),
             ),
         ),
     ):
-        return 1
-
-    # Starting sentry is slow.
-    stdout = proc.run(
-        (
-            "docker",
-            "exec",
-            "sentry_postgres",
-            "psql",
-            "sentry",
-            "postgres",
-            "-t",
-            "-c",
-            "select exists (select from auth_user where email = 'admin@sentry.io')",
-        ),
-        stdout=True,
-    )
-    if stdout != "t":
-        proc.run(
-            (
-                f"{venv_dir}/bin/sentry",
-                "createuser",
-                "--superuser",
-                "--email",
-                "admin@sentry.io",
-                "--password",
-                "admin",
-                "--no-input",
-            )
-        )
+        return 0
 
-    return 0
+    return 1

+ 1 - 1
scripts/ensure-venv.sh

@@ -24,7 +24,7 @@ if [[ -n "$VIRTUAL_ENV" ]]; then
     query-valid-python-version || exit 1
 else
     if [[ ! -f "${venv_name}/bin/activate" ]]; then
-        die "You don't seem to have a virtualenv. Please create one by running: devenv sync"
+        die "You don't seem to have a virtualenv. Please create one by running: source ./scripts/bootstrap-py3-venv"
     fi
     die "You have a virtualenv, but it doesn't seem to be activated. Please run: source ${venv_name}/bin/activate"
 fi

+ 75 - 3
scripts/lib.sh

@@ -78,16 +78,33 @@ sudo-askpass() {
     fi
 }
 
-# needed by getsentry make
 pip-install() {
     pip install --constraint "${HERE}/../requirements-dev-frozen.txt" "$@"
 }
 
-# needed by getsentry make
 upgrade-pip() {
     pip-install pip
 }
 
+install-py-dev() {
+    upgrade-pip
+    # It places us within top src dir to be at the same path as setup.py
+    # This helps when getsentry calls into this script
+    cd "${HERE}/.." || exit
+
+    echo "--> Installing Sentry (for development)"
+
+    # pip doesn't do well with swapping drop-ins
+    pip uninstall -qqy djangorestframework-stubs django-stubs
+
+    pip-install -r requirements-dev-frozen.txt
+
+    # SENTRY_LIGHT_BUILD=1 disables webpacking during setup.py.
+    # Webpacked assets are only necessary for devserver (which does it lazily anyways)
+    # and acceptance tests, which webpack automatically if run.
+    python3 -m tools.fast_editable --path .
+}
+
 setup-git-config() {
     git config --local branch.autosetuprebase always
     git config --local core.ignorecase false
@@ -121,6 +138,32 @@ node-version-check() {
         )
 }
 
+install-js-dev() {
+    node-version-check
+    echo "--> Installing Yarn packages (for development)"
+    # Use NODE_ENV=development so that yarn installs both dependencies + devDependencies
+    NODE_ENV=development yarn install --frozen-lockfile
+    # A common problem is with node packages not existing in `node_modules` even though `yarn install`
+    # says everything is up to date. Even though `yarn install` is run already, it doesn't take into
+    # account the state of the current filesystem (it only checks .yarn-integrity).
+    # Add an additional check against `node_modules`
+    yarn check --verify-tree || yarn install --check-files
+}
+
+develop() {
+    install-js-dev
+    install-py-dev
+    setup-git
+}
+
+init-config() {
+    sentry init --dev --no-clobber
+}
+
+run-dependent-services() {
+    sentry devservices up
+}
+
 create-db() {
     container_name=${POSTGRES_CONTAINER:-sentry_postgres}
     echo "--> Creating 'sentry' database"
@@ -130,6 +173,22 @@ create-db() {
     docker exec "${container_name}" createdb -h 127.0.0.1 -U postgres -E utf-8 region || true
 }
 
+apply-migrations() {
+    create-db
+    echo "--> Applying migrations"
+    sentry upgrade --noinput
+}
+
+create-superuser() {
+    echo "--> Creating a superuser account"
+    if [[ -n "${GITHUB_ACTIONS+x}" ]]; then
+        sentry createuser --superuser --email foo@tbd.com --no-password --no-input
+    else
+        sentry createuser --superuser --email admin@sentry.io --password admin --no-input
+        echo "Password is admin."
+    fi
+}
+
 build-platform-assets() {
     echo "--> Building platform assets"
     echo "from sentry.utils.integrationdocs import sync_docs; sync_docs(quiet=True)" | sentry exec
@@ -137,6 +196,18 @@ build-platform-assets() {
     test -f src/sentry/integration-docs/android.json
 }
 
+bootstrap() {
+    develop
+    init-config
+    run-dependent-services
+    apply-migrations
+    create-superuser
+    # Load mocks requires a superuser
+    bin/load-mocks
+    build-platform-assets
+    echo "--> Finished bootstrapping. Have a nice day."
+}
+
 clean() {
     echo "--> Cleaning static cache"
     rm -rf dist/* src/sentry/static/sentry/dist/*
@@ -160,7 +231,8 @@ drop-db() {
 
 reset-db() {
     drop-db
-    devenv sync
+    apply-migrations
+    create-superuser
     echo 'Finished resetting database. To load mock data, run `./bin/load-mocks`'
 }