Browse Source

feat(devenv): start colima more robustly (#74975)

joshuarli 7 months ago
parent
commit
6acce9c20d

+ 1 - 1
requirements-dev-frozen.txt

@@ -181,7 +181,7 @@ s3transfer==0.10.0
 selenium==4.16.0
 sentry-arroyo==2.16.5
 sentry-cli==2.16.0
-sentry-devenv==1.7.0
+sentry-devenv==1.8.0
 sentry-forked-django-stubs==5.0.4.post1
 sentry-forked-djangorestframework-stubs==3.15.0.post1
 sentry-kafka-schemas==0.1.102

+ 1 - 1
requirements-dev.txt

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

+ 0 - 51
scripts/start-colima.py

@@ -1,51 +0,0 @@
-from __future__ import annotations
-
-import os
-import platform
-import subprocess
-from collections.abc import Sequence
-
-
-def main(argv: Sequence[str] | None = None) -> int:
-    if not os.getenv("CI"):
-        macos_version = platform.mac_ver()[0]
-        macos_major_version = int(macos_version.split(".")[0])
-        if macos_major_version < 14:
-            raise SystemExit(f"macos >= 14 is required to use colima, found {macos_version}")
-
-    cpus = os.cpu_count()
-    if cpus is None:
-        raise SystemExit("failed to determine cpu count")
-
-    # SC_PAGE_SIZE is POSIX 2008
-    # SC_PHYS_PAGES is a linux addition but also supported by more recent MacOS versions
-    SC_PAGE_SIZE = os.sysconf("SC_PAGE_SIZE")
-    SC_PHYS_PAGES = os.sysconf("SC_PHYS_PAGES")
-    if SC_PAGE_SIZE == -1 or SC_PHYS_PAGES == -1:
-        raise SystemExit("failed to determine memsize_bytes")
-    memsize_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")
-
-    args = [
-        "--cpu",
-        f"{cpus//2}",
-        "--memory",
-        f"{memsize_bytes//(2*1024**3)}",
-    ]
-    if platform.machine() == "arm64":
-        args = [*args, "--vm-type=vz", "--vz-rosetta", "--mount-type=virtiofs"]
-    HOME = os.path.expanduser("~")
-    rc = subprocess.call(
-        (
-            "colima",
-            "start",
-            f"--mount=/var/folders:w,/private/tmp/colima:w,{HOME}:r",
-            *args,
-        )
-    )
-    if rc != 0:
-        return rc
-    return subprocess.call(("docker", "context", "use", "colima"))
-
-
-if __name__ == "__main__":
-    raise SystemExit(main())

+ 1 - 1
scripts/use-colima.sh

@@ -55,7 +55,7 @@ with open(os.path.expanduser("~/.docker/config.json"), "w") as f:
 EOF
 
 echo "Starting colima."
-python3 -uS scripts/start-colima.py
+devenv colima start
 
 echo "Recreating your postgres volume for use with colima. May take a few minutes."
 docker volume create --name sentry_postgres

+ 3 - 3
src/sentry/runner/commands/devservices.py

@@ -67,9 +67,9 @@ def get_docker_client() -> Generator[docker.DockerClient]:
                     click.echo("Attempting to start colima...")
                     subprocess.check_call(
                         (
-                            "python3",
-                            "-uS",
-                            f"{os.path.dirname(__file__)}/../../../../scripts/start-colima.py",
+                            "devenv",
+                            "colima",
+                            "start",
                         )
                     )
                 elif USE_DOCKER_DESKTOP: