Skip to content

Commit ee461ce

Browse files
ref: rework build to be reusable outside of setup.py (#71098)
need to get off setuptools so we can get to python 3.12 -- and so we can conditionally do the js build only for self-hosted (since we do it twice for getsentry for no reason!) <!-- Describe your PR here. -->
1 parent 3ecef85 commit ee461ce

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

src/sentry/build/_static_assets.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
import os
5+
import subprocess
6+
7+
8+
def _build_static_assets() -> None:
9+
node_options = os.environ.get("NODE_OPTIONS", "")
10+
env = {
11+
**os.environ,
12+
# By setting NODE_ENV=production, a few things happen
13+
# * React optimizes out certain code paths
14+
# * Webpack will add version strings to built/referenced assets
15+
"NODE_ENV": "production",
16+
# TODO: Our JS builds should not require 4GB heap space
17+
"NODE_OPTIONS": f"{node_options} --max-old-space-size=4096".lstrip(),
18+
}
19+
20+
def _cmd(*cmd: str) -> None:
21+
ret = subprocess.call(cmd, env=env)
22+
if ret:
23+
raise SystemExit(ret)
24+
25+
_cmd("yarn", "install", "--production", "--frozen-lockfile", "--quiet")
26+
_cmd("yarn", "tsc", "-p", "config/tsconfig.build.json")
27+
_cmd("yarn", "build-production", "--bail")
28+
_cmd("yarn", "build-chartcuterie-config", "--bail")
29+
30+
31+
def main() -> int:
32+
parser = argparse.ArgumentParser()
33+
parser.parse_args()
34+
35+
_build_static_assets()
36+
return 0
37+
38+
39+
if __name__ == "__main__":
40+
raise SystemExit(main())

src/sentry/build/main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import argparse
2+
3+
from sentry.build import _integration_docs, _js_sdk_registry, _static_assets
4+
5+
6+
def main() -> int:
7+
parser = argparse.ArgumentParser()
8+
parser.parse_args()
9+
10+
print("=> integration docs")
11+
_integration_docs._sync_docs(_integration_docs._TARGET)
12+
print("=> js sdk registry")
13+
_js_sdk_registry._download(_js_sdk_registry._TARGET)
14+
print("=> static assets")
15+
_static_assets._build_static_assets()
16+
17+
return 0
18+
19+
20+
if __name__ == "__main__":
21+
raise SystemExit(main())

src/sentry/utils/distutils/commands/build_assets.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import os.path
77

8+
from sentry.build._static_assets import _build_static_assets
9+
810
from .base import BaseBuildCommand
911

1012
log = logging.getLogger(__name__)
@@ -17,17 +19,7 @@ def get_dist_paths(self):
1719
return ["src/sentry/static/sentry/dist"]
1820

1921
def _build(self):
20-
# By setting NODE_ENV=production, a few things happen
21-
# * React optimizes out certain code paths
22-
# * Webpack will add version strings to built/referenced assets
23-
env = dict(os.environ)
24-
env["SENTRY_STATIC_DIST_PATH"] = self.sentry_static_dist_path
25-
env["NODE_ENV"] = "production"
26-
# TODO: Our JS builds should not require 4GB heap space
27-
env["NODE_OPTIONS"] = (env.get("NODE_OPTIONS", "") + " --max-old-space-size=4096").lstrip()
28-
self._run_command(["yarn", "tsc", "-p", "config/tsconfig.build.json"], env=env)
29-
self._run_command(["yarn", "build-production", "--bail"], env=env)
30-
self._run_command(["yarn", "build-chartcuterie-config", "--bail"], env=env)
22+
_build_static_assets()
3123

3224
@property
3325
def sentry_static_dist_path(self):

webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const ENABLE_CODECOV_BA = env.CODECOV_ENABLE_BA === 'true' ?? false;
113113
// this is the path to the django "sentry" app, we output the webpack build here to `dist`
114114
// so that `django collectstatic` and so that we can serve the post-webpack bundles
115115
const sentryDjangoAppPath = path.join(__dirname, 'src/sentry/static/sentry');
116-
const distPath = env.SENTRY_STATIC_DIST_PATH || path.join(sentryDjangoAppPath, 'dist');
116+
const distPath = path.join(sentryDjangoAppPath, 'dist');
117117
const staticPrefix = path.join(__dirname, 'static');
118118

119119
// Locale file extraction build step

0 commit comments

Comments
 (0)