Skip to content

Commit 4ec4401

Browse files
committed
ui: config sentry
Signed-off-by: Miguel Garcia Garcia <miguel.garcia.garcia@cern.ch>
1 parent 8136b62 commit 4ec4401

File tree

12 files changed

+178
-89
lines changed

12 files changed

+178
-89
lines changed

.github/workflows/harbour-build-ui.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
2323
id: get_branch
2424

25+
- name: Extract short commit SHA
26+
id: get_short_sha
27+
run: echo "SENTRY_RELEASE=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_OUTPUT
28+
2529
- id: build-ui
2630
name: Build and export
2731
uses: cern-sis/gh-workflows/.github/actions/docker-build@v6.1.0
@@ -35,10 +39,8 @@ jobs:
3539
username: ${{ secrets.HARBOR_USERNAME }}
3640
password: ${{ secrets.HARBOR_PASSWORD }}
3741
build-args: |
38-
BRANCH_NAME=${{ steps.get_branch.outputs.BRANCH_NAME }}
39-
PIWIK_ENV=${{ steps.get_branch.outputs.BRANCH_NAME }}
40-
CAP_PIWIK_URL=${{ secrets.CAP_PIWIK_URL }}
41-
CAP_PIWIK_SITEID_DEV=${{ secrets.CAP_PIWIK_SITEID_DEV }}
42-
CAP_PIWIK_SITEID_PROD=${{ secrets.CAP_PIWIK_SITEID_PROD }}
43-
CAP_PIWIK_SITEID_QA=${{ secrets.CAP_PIWIK_SITEID_QA }}
44-
CAP_PIWIK_SITEID_TEST=${{ secrets.CAP_PIWIK_SITEID_TEST }}
42+
SENTRY_URL=${{ secrets.CAP_SENTRY_URL }}
43+
SENTRY_ORG=${{ secrets.CAP_SENTRY_ORG }}
44+
SENTRY_PROJECT=${{ secrets.CAP_SENTRY_PROJECT }}
45+
SENTRY_AUTH_TOKEN=${{ secrets.CAP_SENTRY_AUTH_TOKEN }}
46+
SENTRY_RELEASE=${{ steps.get_short_sha.outputs.SENTRY_RELEASE }})

docker/harbour/ui/Dockerfile

+15-40
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,35 @@
1-
FROM node:18-alpine as build
1+
FROM node:18-alpine AS build
22

33
RUN apk add --no-cache git
44

55
ENV WORKING_DIR=/tmp/cap
66

77
WORKDIR $WORKING_DIR
88

9-
ARG PIWIK_ENV=dev
10-
ARG ENABLE_E2E
9+
ARG SENTRY_URL
10+
ARG SENTRY_ORG
11+
ARG SENTRY_PROJECT
12+
ARG SENTRY_AUTH_TOKEN
13+
ARG SENTRY_RELEASE
1114

12-
ARG CAP_PIWIK_URL
13-
ARG CAP_PIWIK_SITEID_DEV
14-
ARG CAP_PIWIK_SITEID_PROD
15-
ARG CAP_PIWIK_SITEID_QA
16-
ARG CAP_PIWIK_SITEID_TEST
17-
18-
ARG PIWIK_URL
19-
ARG PIWIK_SITEID_DEV
20-
ARG PIWIK_SITEID_PROD
21-
ARG PIWIK_SITEID_QA
22-
ARG PIWIK_SITEID_TEST
15+
ENV SENTRY_URL=$SENTRY_URL
16+
ENV SENTRY_ORG=$SENTRY_ORG
17+
ENV SENTRY_PROJECT=$SENTRY_PROJECT
18+
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
19+
ENV VITE_SENTRY_RELEASE=$SENTRY_RELEASE
2320

2421
RUN mkdir -p ui/cap-react
25-
RUN echo "PIWIK_URL=$CAP_PIWIK_URL" >> ui/cap-react/.env
26-
RUN echo "ENABLE_E2E=$ENABLE_E2E" >> ui/cap-react/.env
27-
28-
RUN if [[ $PIWIK_ENV == "dev" ]]; then \
29-
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_DEV" >> ui/cap-react/.env; \
30-
fi
31-
32-
RUN if [[ $PIWIK_ENV == "prod" ]]; then \
33-
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_PROD" >> ui/cap-react/.env; \
34-
fi
35-
36-
RUN if [[ $PIWIK_ENV == "qa" ]]; then \
37-
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_QA" >> ui/cap-react/.env; \
38-
fi
39-
40-
RUN if [[ $PIWIK_ENV == "test" ]]; then \
41-
echo "PIWIK_SITEID=$CAP_PIWIK_SITEID_TEST" >> ui/cap-react/.env; \
42-
fi
43-
44-
45-
RUN echo "=========================="
46-
RUN echo $CAP_PIWIK_SITEID_TEST
47-
RUN echo $PIWIK_SITEID_TEST
48-
RUN echo "=========================="
49-
RUN cat ui/cap-react/.env
50-
RUN echo "=========================="
5122

5223
WORKDIR $WORKING_DIR/ui
5324

5425
# build CAP UI
5526
COPY ./ui ${WORKING_DIR}/ui
5627
RUN yarn install
5728
RUN yarn workspace cap-react build
29+
WORKDIR ${WORKING_DIR}/ui/cap-react
30+
RUN yarn sentry:create-release
31+
RUN yarn sentry:sourcemaps
32+
RUN yarn sentry:finalize-release
5833

5934
# build general docs
6035
COPY ./docs ${WORKING_DIR}/docs

ui/cap-react/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta charset="utf-8"/>
77
<link rel="icon" type="image/png" href="./favicon.ico">
8+
<script type="text/javascript" src="/config.js"></script>
89
<title>CERN Analysis Preservation</title>
910
</head>
1011
<body>

ui/cap-react/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"test:e2e:run": "cypress run --headless --browser chrome",
2323
"tests": "start-server-and-test start http://localhost:3000 test:e2e:run",
2424
"open:cover": "npm run test:cover && opn ./coverage/lcov-report/index.html",
25+
"sentry:create-release": "sentry-cli releases new $VITE_SENTRY_RELEASE",
26+
"sentry:sourcemaps": "sentry-cli releases files $VITE_SENTRY_RELEASE upload-sourcemaps dist",
27+
"sentry:finalize-release": "sentry-cli releases finalize $VITE_SENTRY_RELEASE",
2528
"dev": "vite",
2629
"dev:docker": "DOCKER=true vite",
2730
"preview": "vite preview"
@@ -73,6 +76,7 @@
7376
"vite": "^5.0.2"
7477
},
7578
"devDependencies": {
79+
"@sentry/cli": "2.38.2",
7680
"autoprefixer": "7.1.4",
7781
"chalk": "2.0.1",
7882
"concurrently": "3.5.0",

ui/cap-react/public/config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(() => {
2+
const CONFIG = {
3+
ENV: null,
4+
PIWIK_URL: null,
5+
PIWIK_SITE_ID: null,
6+
SENTRY_UI_DSN: null,
7+
ENABLE_E2E: false,
8+
};
9+
10+
Object.defineProperty(window, "CONFIG", { value: Object.freeze(CONFIG) });
11+
})();

ui/cap-react/src/antd/Root.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import App from "../antd/App";
55
import { ConfigProvider } from "antd";
66
import { MatomoProvider, createInstance } from "@datapunt/matomo-tracker-react";
77
import { theme } from "./utils/theme";
8+
import { getConfigFor } from "../config";
9+
10+
const PIWIK_URL = getConfigFor("PIWIK_URL");
11+
const PIWIK_SITE_ID = getConfigFor("PIWIK_SITE_ID");
812

913
export const matomoInstance =
10-
process.env.PIWIK_URL && process.env.PIWIK_SITEID
14+
PIWIK_URL && PIWIK_SITE_ID
1115
? createInstance({
12-
urlBase: process.env.PIWIK_URL,
13-
siteId: process.env.PIWIK_SITEID,
16+
urlBase: PIWIK_URL,
17+
siteId: PIWIK_SITE_ID,
1418
})
1519
: null;
1620

ui/cap-react/src/antd/drafts/CreateForm/CreateForm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect } from "react";
22
import PropTypes from "prop-types";
33
import { Space, Form, Input, Radio } from "antd";
4+
import { getConfigFor } from "../../../config";
45
const BLOCK_DEPOSIT_GROUPS = ["cms-analysis"];
56
const CreateForm = ({
67
contentTypes,
@@ -17,7 +18,7 @@ const CreateForm = ({
1718
}, []);
1819

1920
let contentType = contentTypes;
20-
if (!(process.env.NODE_ENV === "development" || process.env.ENABLE_E2E)) {
21+
if (!(process.env.NODE_ENV === "development" || getConfigFor("ENABLE_E2E"))) {
2122
contentType =
2223
contentTypes &&
2324
contentTypes.filter(

ui/cap-react/src/antd/partials/Header/Menu/Menu.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { WELCOME } from "../../../routes";
44
import { LoginOutlined } from "@ant-design/icons";
55
import LoginForm from "../LoginForm";
66
import { useState } from "react";
7+
import { getConfigFor } from "../../../../config";
78

89
const SimpleMenu = ({
910
loginLocalUser,
@@ -30,7 +31,7 @@ const SimpleMenu = ({
3031
},
3132
];
3233

33-
(process.env.NODE_ENV == "development" || process.env.ENABLE_E2E) &&
34+
(process.env.NODE_ENV == "development" || getConfigFor("ENABLE_E2E")) &&
3435
menuItems.unshift({
3536
key: "localLogin",
3637
label: (

ui/cap-react/src/config.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
const config = {
2-
project: {
3-
name: "CERN Analysis Preservation",
4-
api: "https://pammbp.cern.ch:5000"
5-
}
6-
};
1+
import * as Sentry from "@sentry/react";
72

8-
export default config;
3+
export function getConfigFor(configKey, notSetValue = null) {
4+
try {
5+
return window.CONFIG[configKey] != null
6+
? window.CONFIG[configKey]
7+
: notSetValue;
8+
} catch (error) {
9+
Sentry.captureException(error);
10+
console.error(error); // eslint-disable-line no-console
11+
return notSetValue;
12+
}
13+
}

ui/cap-react/src/index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import { createRoot } from "react-dom/client";
22
import store, { history } from "./store/configureStore";
33
import Root from "./antd/Root";
44
import * as Sentry from "@sentry/react";
5+
import { getConfigFor } from "./config";
56

67
// import "antd/dist/reset.css";
78
import "./style.less";
89

9-
if (process.env.SENTRY_UI_DSN) {
10-
Sentry.init({ dsn: process.env.SENTRY_UI_DSN });
10+
const SENTRY_UI_DSN = getConfigFor("SENTRY_UI_DSN");
11+
const ENV = getConfigFor("ENV");
12+
13+
if (SENTRY_UI_DSN && ENV) {
14+
Sentry.init({
15+
dsn: SENTRY_UI_DSN,
16+
environment: ENV,
17+
release: import.meta.env.VITE_SENTRY_RELEASE,
18+
});
1119
}
1220

1321
const container = document.getElementById("app");

ui/cap-react/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default defineConfig(({ mode }) => {
4343
commonjsOptions: {
4444
transformMixedEsModules: true,
4545
},
46+
sourcemap: true, // For Sentry
4647
},
4748
// Allows writing JSX in .js files
4849
esbuild: {

0 commit comments

Comments
 (0)