forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devenv: add repo-local sync (getsentry#65453)
- Loading branch information
Showing
3 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from __future__ import annotations | ||
|
||
import configparser | ||
import os | ||
import subprocess | ||
|
||
from devenv import constants | ||
from devenv.lib import venv # type: ignore | ||
from devenv.lib import colima, config, limactl, proc, volta | ||
|
||
|
||
# TODO: need to replace this with a nicer process executor in devenv.lib | ||
def run_procs( | ||
repo: str, | ||
reporoot: str, | ||
venv_path: str, | ||
_procs: tuple[tuple[str, tuple[str, ...]], ...], | ||
) -> bool: | ||
procs: list[tuple[str, tuple[str, ...], subprocess.Popen[bytes]]] = [] | ||
|
||
for name, cmd in _procs: | ||
print(f"⏳ {name}") | ||
if constants.DEBUG: | ||
proc.xtrace(cmd) | ||
procs.append( | ||
( | ||
name, | ||
cmd, | ||
subprocess.Popen( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
env={ | ||
**constants.user_environ, | ||
**proc.base_env, | ||
"VIRTUAL_ENV": venv_path, | ||
"VOLTA_HOME": constants.VOLTA_HOME, | ||
"PATH": f"{venv_path}/bin:{proc.base_path}", | ||
}, | ||
cwd=reporoot, | ||
), | ||
) | ||
) | ||
|
||
all_good = True | ||
for name, final_cmd, p in procs: | ||
p.wait() | ||
if p.returncode != 0: | ||
all_good = False | ||
if p.stdout is None: | ||
out = "" | ||
else: | ||
out = p.stdout.read().decode() | ||
print( | ||
f""" | ||
❌ {name} | ||
failed command (code p.returncode): | ||
{proc.quote(final_cmd)} | ||
Output: | ||
{out} | ||
""" | ||
) | ||
else: | ||
print(f"✅ {name}") | ||
|
||
return all_good | ||
|
||
|
||
def main(context: dict[str, str]) -> int: | ||
repo = context["repo"] | ||
reporoot = context["reporoot"] | ||
|
||
venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, "sentry") | ||
url, sha256 = config.get_python(reporoot, python_version) | ||
print(f"ensuring venv at {venv_dir}...") | ||
venv.ensure(venv_dir, python_version, url, sha256) | ||
|
||
print(f"syncing {venv_dir} with {requirements}...") | ||
venv.sync(venv_dir, requirements, editable_paths, bins) | ||
|
||
if not run_procs( | ||
repo, | ||
reporoot, | ||
venv_dir, | ||
( | ||
( | ||
"git and precommit", | ||
# this can't be done in paralell with python dependencies | ||
# as multiple pips cannot act on the same venv | ||
("make", "setup-git"), | ||
), | ||
), | ||
): | ||
return 1 | ||
|
||
# This is for engineers with existing dev environments transitioning over. | ||
# Bootstrap will set devenv-managed volta up but they won't be running | ||
# devenv bootstrap, just installing devenv then running devenv sync. | ||
# make install-js-dev will fail since our run_procs expects devenv-managed | ||
# volta. | ||
volta.install() | ||
|
||
if constants.DARWIN: | ||
repo_config = configparser.ConfigParser() | ||
repo_config.read(f"{reporoot}/devenv/config.ini") | ||
|
||
# we don't officially support colima on linux yet | ||
if constants.CI: | ||
# colima 0.6.8 doesn't work with macos-13, | ||
# but integration coverage is still handy | ||
colima.install( | ||
"v0.6.2", | ||
"https://github.com/abiosoft/colima/releases/download/v0.6.2/colima-Darwin-x86_64", | ||
"43ef3fc80a8347d51b8ec1706f9caf8863bd8727a6f7532caf1ccd20497d8485", | ||
) | ||
else: | ||
colima.install( | ||
repo_config["colima"]["version"], | ||
repo_config["colima"][constants.SYSTEM_MACHINE], | ||
repo_config["colima"][f"{constants.SYSTEM_MACHINE}_sha256"], | ||
) | ||
|
||
# TODO: move limactl version into per-repo config | ||
limactl.install() | ||
|
||
if not run_procs( | ||
repo, | ||
reporoot, | ||
venv_dir, | ||
( | ||
("javascript dependencies", ("make", "install-js-dev")), | ||
("python dependencies", ("make", "install-py-dev")), | ||
), | ||
): | ||
return 1 | ||
|
||
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")) | ||
|
||
# TODO: check healthchecks for redis and postgres to short circuit this | ||
proc.run( | ||
( | ||
f"{venv_dir}/bin/sentry", | ||
"devservices", | ||
"up", | ||
"redis", | ||
"postgres", | ||
), | ||
exit=True, | ||
) | ||
|
||
if run_procs( | ||
repo, | ||
reporoot, | ||
venv_dir, | ||
( | ||
( | ||
"python migrations", | ||
(f"{venv_dir}/bin/sentry", "upgrade", "--noinput"), | ||
), | ||
), | ||
): | ||
return 0 | ||
|
||
return 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters