Browse Source

devenv: replace volta (#75554)

joshuarli 6 months ago
parent
commit
008295ac6e
7 changed files with 41 additions and 34 deletions
  1. 5 4
      .envrc
  2. 6 7
      Makefile
  3. 12 0
      devenv/config.ini
  4. 16 10
      devenv/sync.py
  5. 1 1
      requirements-dev-frozen.txt
  6. 1 1
      requirements-dev.txt
  7. 0 11
      scripts/lib.sh

+ 5 - 4
.envrc

@@ -179,14 +179,15 @@ python3 -m tools.docker_memory_check
 debug "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"
+    die "You don't seem to have node installed. Please run devenv sync."
 fi
 
-make node-version-check
+if ! node -pe "process.exit(Number(!(process.version == 'v' + require('./.volta.json').volta.node )))"; then
+    die "Unexpected $(command -v node) version. Please run devenv sync."
+fi
 
 if [ ! -x "node_modules/.bin/webpack" ]; then
-    warn "You don't seem to have yarn packages installed."
-    commands_to_run+=("devenv sync")
+    die "You don't seem to have yarn packages installed. Please run devenv sync."
 fi
 
 PATH_add node_modules/.bin

+ 6 - 7
Makefile

@@ -20,8 +20,7 @@ run-dependent-services \
 drop-db \
 create-db \
 apply-migrations \
-reset-db \
-node-version-check :
+reset-db :
 	@./scripts/do.sh $@
 
 develop \
@@ -35,7 +34,7 @@ install-py-dev :
 devenv-sync:
 	devenv sync
 
-build-js-po: node-version-check
+build-js-po:
 	mkdir -p build
 	rm -rf node_modules/.cache/babel-loader
 	SENTRY_EXTRACT_TRANSLATIONS=1 $(WEBPACK)
@@ -107,18 +106,18 @@ test-cli: create-db
 	rm -r test_cli
 	@echo ""
 
-test-js-build: node-version-check
+test-js-build:
 	@echo "--> Running type check"
 	@yarn run tsc -p config/tsconfig.build.json
 	@echo "--> Building static assets"
 	@NODE_ENV=production yarn webpack-profile > .artifacts/webpack-stats.json
 
-test-js: node-version-check
+test-js:
 	@echo "--> Running JavaScript tests"
 	@yarn run test
 	@echo ""
 
-test-js-ci: node-version-check
+test-js-ci:
 	@echo "--> Running CI JavaScript tests"
 	@yarn run test-ci
 	@echo ""
@@ -186,7 +185,7 @@ test-symbolicator:
 	python3 -b -m pytest tests/relay_integration/lang/java/ -vv -m symbolicator
 	@echo ""
 
-test-acceptance: node-version-check
+test-acceptance:
 	@echo "--> Building static assets"
 	@$(WEBPACK)
 	make run-acceptance

+ 12 - 0
devenv/config.ini

@@ -27,6 +27,18 @@ linux_x86_64_sha256 = a73ba777b5d55ca89edef709e6b8521e3f3d4289581f174c8699adfb60
 linux_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3+20240415-aarch64-unknown-linux-gnu-install_only.tar.gz
 linux_arm64_sha256 = ec8126de97945e629cca9aedc80a29c4ae2992c9d69f2655e27ae73906ba187d
 
+[node]
+# upstream (https://nodejs.org/dist/) is not reliable enough so we've mirrored it to GCS
+darwin_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-darwin-x64.tar.xz
+darwin_x86_64_sha256 = c83bffeb4eb793da6cb61a44c422b399048a73d7a9c5eb735d9c7f5b0e8659b6
+darwin_arm64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-darwin-arm64.tar.xz
+darwin_arm64_sha256 = e8a8e78b91485bc95d20f2aa86201485593685c828ee609245ce21c5680d07ce
+linux_x86_64 = https://storage.googleapis.com/sentry-dev-infra-assets/node/node-v20.13.1-linux-x64.tar.xz
+linux_x86_64_sha256 = efc0f295dd878e510ab12ea36bbadc3db03c687ab30c07e86c7cdba7eed879a9
+# used for autoupdate
+version = v20.13.1
+yarn_version = 1.22.22
+
 [colima]
 darwin_x86_64 = https://github.com/abiosoft/colima/releases/download/v0.6.6/colima-Darwin-x86_64
 darwin_x86_64_sha256 = 84e72678945aacba5805fe363f6c7c87dc73e05cbbfdfc09f9b57cedf110865d

+ 16 - 10
devenv/sync.py

@@ -1,12 +1,11 @@
 from __future__ import annotations
 
-import configparser
 import os
 import shlex
 import subprocess
 
 from devenv import constants
-from devenv.lib import colima, config, fs, limactl, proc, venv, volta
+from devenv.lib import colima, config, fs, limactl, proc, venv
 
 
 # TODO: need to replace this with a nicer process executor in devenv.lib
@@ -30,7 +29,6 @@ def run_procs(
             **constants.user_environ,
             **proc.base_env,
             "VIRTUAL_ENV": venv_path,
-            "VOLTA_HOME": f"{reporoot}/.devenv/bin/volta-home",
             "PATH": f"{venv_path}/bin:{reporoot}/.devenv/bin:{proc.base_path}",
         }
         if extra_env:
@@ -75,6 +73,7 @@ failed command (code {p.returncode}):
 def main(context: dict[str, str]) -> int:
     repo = context["repo"]
     reporoot = context["reporoot"]
+    repo_config = config.get_config(f"{reporoot}/devenv/config.ini")
 
     # TODO: context["verbose"]
     verbose = os.environ.get("SENTRY_DEVENV_VERBOSE") is not None
@@ -88,17 +87,24 @@ def main(context: dict[str, str]) -> int:
     print(f"ensuring {repo} venv at {venv_dir}...")
     venv.ensure(venv_dir, python_version, url, sha256)
 
-    # TODO: move volta version into per-repo config
+    # repo-local devenv needs to update itself first with a successful sync
+    # so it'll take 2 syncs to get onto devenv-managed node, it is what it is
     try:
+        from devenv.lib import node
+
+        node.install(
+            repo_config["node"]["version"],
+            repo_config["node"][constants.SYSTEM_MACHINE],
+            repo_config["node"][f"{constants.SYSTEM_MACHINE}_sha256"],
+            reporoot,
+        )
+        node.install_yarn(repo_config["node"]["yarn_version"], reporoot)
+    except ImportError:
+        from devenv.lib import volta
+
         volta.install(reporoot)
-    except TypeError:
-        # this is needed for devenv <=1.4.0,>1.2.3 to finish syncing and therefore update itself
-        volta.install()
 
     if constants.DARWIN:
-        repo_config = configparser.ConfigParser()
-        repo_config.read(f"{reporoot}/devenv/config.ini")
-
         try:
             colima.install(
                 repo_config["colima"]["version"],

+ 1 - 1
requirements-dev-frozen.txt

@@ -179,7 +179,7 @@ s3transfer==0.10.0
 selenium==4.16.0
 sentry-arroyo==2.16.5
 sentry-cli==2.16.0
-sentry-devenv==1.8.0
+sentry-devenv==1.10.0
 sentry-forked-django-stubs==5.0.4.post2
 sentry-forked-djangorestframework-stubs==3.15.0.post1
 sentry-kafka-schemas==0.1.106

+ 1 - 1
requirements-dev.txt

@@ -1,6 +1,6 @@
 --index-url https://pypi.devinfra.sentry.io/simple
 
-sentry-devenv>=1.8.0
+sentry-devenv>=1.10.0
 
 covdefaults>=2.3.0
 docker>=6

+ 0 - 11
scripts/lib.sh

@@ -78,17 +78,6 @@ sudo-askpass() {
     fi
 }
 
-node-version-check() {
-    # Checks to see if node's version matches the one specified in package.json for Volta.
-    node -pe "process.exit(Number(!(process.version == 'v' + require('./.volta.json').volta.node )))" ||
-        (
-            echo 'Unexpected node version. Recommended to use https://github.com/volta-cli/volta'
-            echo 'Run `volta install node` and `volta install yarn` to update your toolchain.'
-            echo 'If you do not have volta installed run `curl https://get.volta.sh | bash` or visit https://volta.sh'
-            exit 1
-        )
-}
-
 init-config() {
     sentry init --dev --no-clobber
 }