Browse Source

build: Configure zeit for build previews (#17574)

Evan Purkhiser 5 years ago
parent
commit
21d363e3cd
6 changed files with 32 additions and 33 deletions
  1. 4 0
      .nowignore
  2. 0 28
      netlify.toml
  3. 20 0
      now.json
  4. 2 1
      package.json
  5. 5 1
      src/sentry/static/sentry/app/actionCreators/deployPreview.jsx
  6. 1 3
      webpack.config.js

+ 4 - 0
.nowignore

@@ -0,0 +1,4 @@
+/src
+/tests
+!/src/sentry/static/sentry
+!/src/sentry/locale

+ 0 - 28
netlify.toml

@@ -1,28 +0,0 @@
-# Sentry uses netlify to deploy pull-request previews of the frontend which
-# talk to the production API.
-#
-# This is an EXPERIMENTAL developer experience, there are still various pages
-# that are served through django and have no SPA equivalent views.
-
-[build]
-  publish = "src/sentry/static/sentry/dist"
-  command = "yarn webpack"
-
-[[redirects]]
-  from = "/_assets/*"
-  to = "/:splat"
-  status = 200
-
-[[redirects]]
-  from = "/api/*"
-  to = "https://sentry.io/api/:splat"
-  status = 200
-  force = true
-
-  # Pass referer as sentry.io to avoid CSRF validation errors.
-  headers = {Referer = "https://sentry.io/"}
-
-[[redirects]]
-  from = "/*"
-  to = "/index.html"
-  status = 200

+ 20 - 0
now.json

@@ -0,0 +1,20 @@
+{
+  "version": 2,
+
+  "rewrites": [
+    {"source": "/api/(.*)", "destination": "https://sentry.io/api/$1"},
+    {"source": "/_assets/(.*)", "destination": "/$1"},
+    {"source": "/(.*)", "destination": "/index.html"}
+  ],
+  "headers": [
+    {
+      "source": "/api/(.*)",
+      "headers": [{"key": "Referer", "value": "https://sentry.io/"}]
+    }
+  ],
+  "build": {
+    "env": {
+      "SENTRY_EXPERIMENTAL_SPA": "1"
+    }
+  }
+}

+ 2 - 1
package.json

@@ -196,7 +196,8 @@
     "storybook": "start-storybook -p 9001 -c .storybook",
     "storybook": "start-storybook -p 9001 -c .storybook",
     "storybook-build": "build-storybook -c .storybook -o .storybook-out && sed -i -e 's/\\/sb_dll/sb_dll/g' .storybook-out/index.html",
     "storybook-build": "build-storybook -c .storybook -o .storybook-out && sed -i -e 's/\\/sb_dll/sb_dll/g' .storybook-out/index.html",
     "snapshot": "build-storybook && PERCY_TOKEN=$STORYBOOK_PERCY_TOKEN PERCY_PROJECT=$STORYBOOK_PERCY_PROJECT percy-storybook --widths=1280",
     "snapshot": "build-storybook && PERCY_TOKEN=$STORYBOOK_PERCY_TOKEN PERCY_PROJECT=$STORYBOOK_PERCY_PROJECT percy-storybook --widths=1280",
-    "webpack-profile": "yarn -s webpack --profile --json > stats.json"
+    "webpack-profile": "yarn -s webpack --profile --json > stats.json",
+    "build": "yarn webpack --output-path=public"
   },
   },
   "volta": {
   "volta": {
     "node": "10.16.3",
     "node": "10.16.3",

+ 5 - 1
src/sentry/static/sentry/app/actionCreators/deployPreview.jsx

@@ -11,7 +11,11 @@ export function displayDeployPreviewAlert() {
   }
   }
 
 
   const {commitRef, reviewId, repoUrl} = DEPLOY_PREVIEW_CONFIG;
   const {commitRef, reviewId, repoUrl} = DEPLOY_PREVIEW_CONFIG;
-  const repoName = repoUrl.match(/\w+\/\w+\/?$/)[0];
+  const repoName = repoUrl?.match(/\w+\/\w+\/?$/)[0];
+
+  if (!repoName) {
+    return;
+  }
 
 
   const pullLink = (
   const pullLink = (
     <ExternalLink href={`${repoUrl}/pull/${reviewId}`}>
     <ExternalLink href={`${repoUrl}/pull/${reviewId}`}>

+ 1 - 3
webpack.config.js

@@ -50,10 +50,8 @@ const TS_FORK_WITH_ESLINT = !!env.TS_FORK_WITH_ESLINT; // Do not run eslint with
 const SHOULD_FORK_TS = DEV_MODE && !env.NO_TS_FORK; // Do not run fork-ts plugin (or if not dev env)
 const SHOULD_FORK_TS = DEV_MODE && !env.NO_TS_FORK; // Do not run fork-ts plugin (or if not dev env)
 const SHOULD_HOT_MODULE_RELOAD = DEV_MODE && !!env.SENTRY_UI_HOT_RELOAD;
 const SHOULD_HOT_MODULE_RELOAD = DEV_MODE && !!env.SENTRY_UI_HOT_RELOAD;
 
 
-// Deploy previews are built using netlify. We can check if we're in netlifys
+// Deploy previews are built using zeit. We can check if we're in zeit's
 // build process by checking the existence of the PULL_REQUEST env var.
 // build process by checking the existence of the PULL_REQUEST env var.
-//
-// See: https://www.netlify.com/docs/continuous-deployment/#environment-variables
 const DEPLOY_PREVIEW_CONFIG = env.PULL_REQUEST && {
 const DEPLOY_PREVIEW_CONFIG = env.PULL_REQUEST && {
   commitRef: env.COMMIT_REF,
   commitRef: env.COMMIT_REF,
   reviewId: env.REVIEW_ID,
   reviewId: env.REVIEW_ID,