跳转到主要内容

设置Sentry开发环境的实用工具

项目描述

devenv

自'24年起管理开发环境

devenv是一个可扩展的执行框架和库,用于编写一组高级命令 - 引导、同步、诊断、销毁 - 以管理存储库的开发环境。

先决条件

您是Sentry员工吗?请确保您的GitHub账户已添加到getsentry/engineering团队。如果不是,请在继续之前打开IT票证。

否则,设置SENTRY_EXTERNAL_CONTRIBUTOR环境变量。

安装

下载此文件并运行它

bash install-devenv.sh

此"全局"devenv安装在~/.local/share/sentry-devenv/bin/devenv

要更新此安装,请运行devenv update

用户指南

devenv bootstrap

此操作适用于新机器的初始设置。

devenv fetch [repository name]

任何形式为[org]/[reponame]的github上的存储库

存储库将被克隆到全局配置中指定的"coderoot"目录。

注意:sentryops目前是特殊名称,执行更复杂的安装(例如,sentry将设置sentry和getsentry)

devenv sync

此操作将运行用户提供的[reporoot]/devenv/sync.py,该脚本应

  • 确保安装所需的任何工具
  • 使开发环境保持最新,或者如果不存在则创建它

此脚本在devenv的运行时中运行,该运行时可以访问许多有用的高级例程。目前没有api文档,但参考示例应该能让您达到90%的成效。

如果您有功能请求,请提交一个问题!

通常,我们的库旨在尽可能地在 [reporoot]/.devenv 内部隔离仓库的 dev 环境。例如,gcloud 被安装到 [reporoot]/.devenv/bin/gcloud(gcloud sdk 在 [reporoot]/.devenv/bin/google-cloud-sdk)。对此的一个例外是 python 虚拟环境,它在 [reporoot]/.devenv 的想法之前就已经实现了。

devenv doctor

当您在仓库内部时,这个工具会诊断并尝试修复常见问题。检查和修复定义在 [reporoot]/devenv/checks

devenv nuke|uninstall(wip)

当您在仓库内部时,这将完全删除 dev 环境。

技术概述

devenv 所需的一切都在 ~/.local/share/sentry-devenv

  • ~/.local/share/sentry-devenv/bin 包含 devenvdirenv
    • 我们目前依赖于一个最小的 [reporoot]/.envrc 来将 [reporoot]/.devenv/bin 添加到 PATH
    • 请参阅 示例 获取 .envrc 建议

运行时

  • devenv 仅在 ~/.local/share/sentry-devenv/venv 的虚拟环境中安装
    • 此 venv 专用于 ~/.local/share/sentry-devenv/python 的 python

配置

全局配置在 ~/.config/sentry-devenv/config.ini

仓库配置在 [reporoot]/devenv/config.ini

示例

跳转到

direnv

目前需要最小的 [reporoot]/.envrc

if [[ -f "${PWD}/.env" ]]; then
    dotenv
fi

PATH_add "${HOME}/.local/share/sentry-devenv/bin"

if ! command -v devenv >/dev/null; then
    echo "install devenv: https://github.com/getsentry/devenv#install"
    return 1
fi

PATH_add "${PWD}/.devenv/bin"

python

如果您需要多个虚拟环境,这很有用,如果您依赖一个有许多依赖项可能与其他冲突的 python 工具。

[reporoot]/.envrc

export VIRTUAL_ENV="${PWD}/.exampleproject"

PATH_add "${PWD}/.venv-exampleproject/bin"
PATH_add "${PWD}/.venv-inhouse-tool/bin"

[reporoot]/devenv/sync.py

from devenv.lib import config, venv

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]

    for name in ("exampleproject", "inhouse-tool"):
        venv_dir, python_version, requirements, editable_paths, bins = venv.get(reporoot, name)
        url, sha256 = config.get_python(reporoot, python_version)
        print(f"ensuring {name} venv at {venv_dir}...")
        venv.ensure(venv_dir, python_version, url, sha256)

        print(f"syncing {name} with {requirements}...")
        venv.sync(reporoot, venv_dir, requirements, editable_paths, bins)

    return 0

[reporoot]/devenv/config.ini

[venv.exampleproject]
python = 3.12.3
requirements = requirements-dev.txt
editable =
  .

[venv.inhouse-tool]
python = 3.12.3
requirements = inhouse-tool/requirements-dev.txt

[python3.12.3]
darwin_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3+20240415-x86_64-apple-darwin-install_only.tar.gz
darwin_x86_64_sha256 = c37a22fca8f57d4471e3708de6d13097668c5f160067f264bb2b18f524c890c8
darwin_arm64 = https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3+20240415-aarch64-apple-darwin-install_only.tar.gz
darwin_arm64_sha256 = ccc40e5af329ef2af81350db2a88bbd6c17b56676e82d62048c15d548401519e
linux_x86_64 = https://github.com/indygreg/python-build-standalone/releases/download/20240415/cpython-3.12.3+20240415-x86_64-unknown-linux-gnu-install_only.tar.gz
linux_x86_64_sha256 = a73ba777b5d55ca89edef709e6b8521e3f3d4289581f174c8699adfb608d09d6
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

[reporoot]/.envrc

PATH_add "${PWD}/node_modules/.bin"

[reporoot]/devenv/sync.py

from devenv import constants
from devenv.lib import config, node, proc

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]
    cfg = config.get_repo(reporoot)

    node.install(
        cfg["node"]["version"],
        cfg["node"][constants.SYSTEM_MACHINE],
        cfg["node"][f"{constants.SYSTEM_MACHINE}_sha256"],
        reporoot,
    )
    node.install_yarn(cfg["node"]["yarn_version"], reporoot)

    print("installing node dependencies...")
    proc.run(
        (
            ".devenv/bin/yarn",
            "install",
            "--frozen-lockfile",
            "--no-progress",
            "--non-interactive",
        ),
    )

    return 0

如果您需要不同的 node 版本,请先在 config.ini 中填写适当的 urls https://node.org.cn/dist/,然后联系 dev-infra,我们可以将其镜像到 GCS。

[reporoot]/devenv/config.ini

[node]
# upstream (https://node.org.cn/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

brew

[reporoot]/devenv/sync.py

from devenv import constants
from devenv.lib import brew

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]

    brew.install()

    proc.run(
        (f"{constants.homebrew_bin}/brew", "bundle"),
        cwd=reporoot,
    )

    return 0

[reporoot]/Brewfile

# whatever you want, but we generally discourage installing
# things via brew as it's very difficult to pin a particular
# version of something

colima

[reporoot]/devenv/sync.py

from devenv import constants
from devenv.lib import brew, config, colima, limactl, proc

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]
    cfg = config.get_repo(reporoot)

    brew.install()

    proc.run(
        (f"{constants.homebrew_bin}/brew", "bundle"),
        cwd=reporoot,
    )

    colima.install(
        cfg["colima"]["version"],
        cfg["colima"][constants.SYSTEM_MACHINE],
        cfg["colima"][f"{constants.SYSTEM_MACHINE}_sha256"],
        reporoot,
    )
    limactl.install(reporoot)

    # start colima if it's not already running
    colima.start(reporoot)

    return 0

[reporoot]/Brewfile

# this is docker cli (not desktop) which is needed for interacting with colima
brew 'docker'

# QEMU is needed if you are on an intel mac
# brew 'qemu'

[reporoot]/devenv/config.ini

[colima]
darwin_x86_64 = https://github.com/abiosoft/colima/releases/download/v0.6.6/colima-Darwin-x86_64
darwin_x86_64_sha256 = 84e72678945aacba5805fe363f6c7c87dc73e05cbbfdfc09f9b57cedf110865d
darwin_arm64 = https://github.com/abiosoft/colima/releases/download/v0.6.6/colima-Darwin-arm64
darwin_arm64_sha256 = b2729edcf99470071240ab6986349346211e25944a5dc317bba8fa27ed0f25e5
linux_x86_64 = https://github.com/abiosoft/colima/releases/download/v0.6.6/colima-Linux-x86_64
linux_x86_64_sha256 = bf9e370c4bacbbebdfaa46de04d0e01fe2649a8e366f282cf35ae7dd84559a25
linux_arm64 = https://github.com/abiosoft/colima/releases/download/v0.6.6/colima-Linux-aarch64
linux_arm64_sha256 = 6ecba675e90d154f22e20200fa5684f20ad1495b73c0462f1bd7da4e9d0beaf8
# used for autoupdate
version = v0.6.6

gcloud

[reporoot]/devenv/sync.py

from devenv import constants
from devenv.lib import config, gcloud

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]
    cfg = config.get_repo(reporoot)

    gcloud.install(
        cfg["gcloud"]["version"],
        cfg["gcloud"][SYSTEM_MACHINE],
        cfg["gcloud"][f"{SYSTEM_MACHINE}_sha256"],
        reporoot,
    )

    return 0

[reporoot]/devenv/config.ini

[gcloud]
# custom python version not supported yet, it just uses
# devenv's internal python 3.11
darwin_x86_64 = https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-490.0.0-darwin-x86_64.tar.gz
darwin_x86_64_sha256 = fa396909acc763cf831dd5d89e778999debf37ceadccb3c1bdec606e59ba2694
darwin_arm64 = https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-490.0.0-darwin-arm.tar.gz
darwin_arm64_sha256 = a3a098a5f067b561e003c37284a9b164f28f37fd0d6371bb55e326679f48641c
linux_x86_64 = https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-490.0.0-linux-x86_64.tar.gz
linux_x86_64_sha256 = 40ce41958236f76d9cb08f377ccb9fd6502d2df4da14b36d9214bcb620e2b020
# used for autoupdate
version = 490.0.0

terraform

我们的责任仅限于安装 tenv 并在 [reporoot]/.devenv/bin/tenv-root 中包含 TENV_ROOT。我们安装 terraformterragrunt shims,它们使用该 TENV_ROOT

定义 [reporoot]/.terraform-version[reporoot]/.terragrunt-version(如果需要的话)并在运行同步后,只需输入 terraform,tenv 就会处理其余部分。

[reporoot]/devenv/sync.py

from devenv import constants
from devenv.lib import config, tenv

def main(context: dict[str, str]) -> int:
    reporoot = context["reporoot"]
    cfg = config.get_repo(reporoot)

    tenv.install(
        cfg["tenv"]["version"],
        cfg["tenv"][SYSTEM_MACHINE],
        cfg["tenv"][f"{SYSTEM_MACHINE}_sha256"],
        reporoot,
    )

    return 0

[reporoot]/devenv/config.ini

[tenv]
darwin_x86_64 = https://github.com/tofuutils/tenv/releases/download/v1.3.0/tenv_v1.3.0_Darwin_x86_64.tar.gz
darwin_x86_64_sha256 = 994100d26f4de6de4eebc7691ca4ea7b424e2fd73e6d5d77c5bf6dfd4af94752
darwin_arm64 =  https://github.com/tofuutils/tenv/releases/download/v1.3.0/tenv_v1.3.0_Darwin_arm64.tar.gz
darwin_arm64_sha256 = c31d2b8412147316a0cadb684408bc123e567852d7948091be7e4303fc19397a
# used for autoupdate
version = v1.3.0

开发

我们使用 tox。在本地运行 devenv 的最简单方法是使用 tox venv 的可执行文件

~/code/sentry $  ~/code/devenv/.tox/py311/bin/devenv sync

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解有关 安装软件包 的更多信息。

源分布

sentry_devenv-1.10.3.tar.gz (43.5 kB 查看哈希

上传时间

构建分布

sentry_devenv-1.10.3-py3-none-any.whl (59.5 kB 查看哈希值)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面