Unify and prune environment variables (#1613)
This commit is contained in:
commit
6797dde517
22 changed files with 218 additions and 304 deletions
9
Development.md
Normal file
9
Development.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
## Notes for Developers
|
||||
|
||||
### Local production builds
|
||||
|
||||
```sh
|
||||
yarn export:photos
|
||||
cd apps/
|
||||
python3 -m http.server
|
||||
```
|
|
@ -1,3 +1,3 @@
|
|||
import { setupSentry } from '@ente/shared/sentry/config/sentry.config.base';
|
||||
import { initSentry } from '@ente/shared/sentry/config/sentry.config.base';
|
||||
|
||||
setupSentry('https://ad075e4713480307bb8bc0811547c65e@sentry.ente.io/8');
|
||||
initSentry('https://ad075e4713480307bb8bc0811547c65e@sentry.ente.io/8');
|
||||
|
|
|
@ -5,7 +5,7 @@ import { t } from 'i18next';
|
|||
import { useRouter } from 'next/router';
|
||||
import { Overlay } from '@ente/shared/components/Container';
|
||||
import EnteSpinner from '@ente/shared/components/EnteSpinner';
|
||||
import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
|
||||
import { LS_KEYS } from '@ente/shared/storage/localStorage';
|
||||
import HTTPService from '@ente/shared/network/HTTPService';
|
||||
import Head from 'next/head';
|
||||
import LoadingBar from 'react-top-loading-bar';
|
||||
|
@ -17,8 +17,10 @@ import {
|
|||
DialogBoxAttributesV2,
|
||||
SetDialogBoxAttributesV2,
|
||||
} from '@ente/shared/components/DialogBoxV2/types';
|
||||
import { addLogLine } from '@ente/shared/logging';
|
||||
import { clearLogsIfLocalStorageLimitExceeded } from '@ente/shared/logging/web';
|
||||
import {
|
||||
clearLogsIfLocalStorageLimitExceeded,
|
||||
logStartupMessage,
|
||||
} from '@ente/shared/logging/web';
|
||||
|
||||
import { CacheProvider } from '@emotion/react';
|
||||
import {
|
||||
|
@ -31,8 +33,6 @@ import createEmotionCache from '@ente/shared/themes/createEmotionCache';
|
|||
import { THEME_COLOR } from '@ente/shared/themes/constants';
|
||||
import { SetTheme } from '@ente/shared/themes/types';
|
||||
import { setupI18n } from '@ente/shared/i18n';
|
||||
import { getSentryUserID } from '@ente/shared/sentry/utils';
|
||||
import { User } from '@ente/shared/user/types';
|
||||
import { useLocalState } from '@ente/shared/hooks/useLocalState';
|
||||
import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
|
||||
import { getTheme } from '@ente/shared/themes';
|
||||
|
@ -87,12 +87,7 @@ export default function App(props: EnteAppProps) {
|
|||
});
|
||||
// setup logging
|
||||
clearLogsIfLocalStorageLimitExceeded();
|
||||
const main = async () => {
|
||||
addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
|
||||
addLogLine(`sentryID: ${await getSentryUserID()}`);
|
||||
addLogLine(`sentry release ID: ${process.env.SENTRY_RELEASE}`);
|
||||
};
|
||||
main();
|
||||
logStartupMessage();
|
||||
}, []);
|
||||
|
||||
const setUserOnline = () => setOffline(false);
|
||||
|
|
|
@ -1,46 +1,41 @@
|
|||
# Sample configuration file
|
||||
#
|
||||
# All variables are commented out by default. Copy paste this into a new file
|
||||
# called `.env.local`, or create a new file with that name and add the
|
||||
# environment variables you need into it. That `.env.local` file will be
|
||||
# .gitignored, so you can freely customize how the app runs in your local setup.
|
||||
# called `.env.local` (or create a new file with that name) and add the
|
||||
# environment variables you want to apply during development. `.env.local` is
|
||||
# gitignored, so you can freely customize it for your local setup.
|
||||
#
|
||||
# - `.env.local` is picked up by next when NODE_ENV is development
|
||||
# `.env.local` is picked up by Next.js when NODE_ENV is 'development' (it is
|
||||
# 'production' by default, but gets set to 'development' when we run `next dev`)
|
||||
#
|
||||
# - `.env` is picked up always
|
||||
#
|
||||
# You don't necessarily need to use these files, these variables can be provided
|
||||
# as environment variables when running yarn dev too. e.g.
|
||||
# Alternatively, these variables can be provided as environment variables, say:
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:3000 yarn dev:photos
|
||||
#
|
||||
# Variables prefixed with NEXT_PUBLIC_ (in our case, all of them) are made
|
||||
# available when next runs our code in the browser. For more details, see
|
||||
# Variables prefixed with NEXT_PUBLIC_ are made available when Next.js runs our
|
||||
# code in the browser (Behind the scenes, Next.js just hardcodes occurrences of
|
||||
# `process.env.NEXT_PUBLIC_FOO` with the value of the `NEXT_PUBLIC_FOO` env var
|
||||
# when the bundle is built). See
|
||||
# https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
|
||||
#
|
||||
# By default, the app is configured to connect to the production instance etc.
|
||||
# This is usually a good default, for example someone might want to run the
|
||||
# client locally but still use their actual ente account.
|
||||
# A development build behaves differently in some aspects:
|
||||
#
|
||||
# Even though it connects to the production instances, when invoked with `yarn
|
||||
# dev:*`, next will behave as if NODE_ENV was set to 'development' (otherwise
|
||||
# this is assumed to be 'production'). There are some other cases too when we
|
||||
# assume we're in a dev environment (e.g. the NEXT_PUBLIC_APP_ENV env var below.
|
||||
# For the full list of rules that decide what counts as a dev build, see the
|
||||
# `isDevDeployment` function).
|
||||
# - Logs go to the browser console (in addition to the log file)
|
||||
# - There is some additional logging
|
||||
# - Sentry is not initialized
|
||||
# - ... (search for isDevBuild to see all impacts)
|
||||
#
|
||||
# We have some development related conveniences tied to the dev build:
|
||||
# 1. Logs go to the browser console instead of the log file
|
||||
# 2. Sentry crash reporting etc is disabled
|
||||
#
|
||||
# The variables below thus serve as ways to customize which API instance we
|
||||
# connect to for various purposes. These variables are only honoured when we're
|
||||
# in a development environment.
|
||||
# Note that even in development build, the app still connects to the production
|
||||
# APIs by default (can be customized using the env vars below). This is usually
|
||||
# a good default, for example a customer cloning this repository want to build
|
||||
# and run the client from source but still use their actual Ente account.
|
||||
|
||||
# The ente API endpoint
|
||||
# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:3000
|
||||
# The Ente API endpoint
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_ENDPOINT = http://localhost:3000
|
||||
|
||||
# The ente API endpoint for payments related functionality
|
||||
# The Ente API endpoint for payments related functionality
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_PAYMENT_ENDPOINT = http://localhost:3001
|
||||
|
||||
# The URL for the shared albums deployment
|
||||
|
@ -49,6 +44,7 @@
|
|||
# deploying, we add an a CNAME alias from "albums.ente.io" -> "/shared-album".
|
||||
#
|
||||
# Enhancement: Consider splitting this into a separate app/ in this repository.
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT = http://localhost:3002
|
||||
|
||||
# The URL of the family plans web app deployment
|
||||
|
@ -58,41 +54,21 @@
|
|||
# these pages.
|
||||
#
|
||||
# Enhancement: Consider moving that into the app/ folder in this repository.
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT = http://localhost:3003
|
||||
|
||||
# This in not useful when running locally. It is used to provide us a way to
|
||||
# mark certain deployments as "staging" by setting environment variables in the
|
||||
# CI job that deploys them on a remote server. See the `isDevDeployment`
|
||||
# function.
|
||||
# Set this to "true" to disable the upload of files via Cloudflare Workers.
|
||||
#
|
||||
# By default, the photos web app gets deployed to "web.ente.io".
|
||||
# NEXT_PUBLIC_ENTE_WEB_ENDPOINT = http://localhost:3000
|
||||
|
||||
# Set this to true to disable reporting of crashes to Sentry.
|
||||
# These workers were introduced as a way of make file uploads faster:
|
||||
# https://ente.io/blog/tech/making-uploads-faster/
|
||||
#
|
||||
# Crash reporting is disabled if the user has opted out. This provides another
|
||||
# way to disable crash reporting, say for local test branches.
|
||||
# NEXT_PUBLIC_DISABLE_SENTRY=true
|
||||
|
||||
# Set this to disable the upload of files via CF Workers
|
||||
# By default, that's the route we take. However, during development it can be
|
||||
# convenient to turn this flag on to directly upload to the S3-compatible URLs
|
||||
# returned by the ente API.
|
||||
#
|
||||
# CF workers provide us with a way of make the file uploads faster. The why and
|
||||
# how is explained here: https://ente.io/blog/tech/making-uploads-faster/
|
||||
#
|
||||
# By default, that's the route we take. This flag can be set to true to disable
|
||||
# that route, and instead directly upload to the S3-compatible URLs provided by
|
||||
# our API server.
|
||||
#
|
||||
# Note the double negative.
|
||||
# NEXT_PUBLIC_DISABLE_CF_UPLOAD_PROXY = true
|
||||
|
||||
# This is an alternative to run as a development build.
|
||||
#
|
||||
# You likely don't need this if you're running on your machine, because when
|
||||
# invoked with `next dev` (as is the case for `yarn dev:photos` etc), next will
|
||||
# behave as if NODE_ENV was set to 'development'.
|
||||
# NEXT_PUBLIC_APP_ENV = development
|
||||
# NEXT_PUBLIC_ENTE_DIRECT_UPLOAD = true
|
||||
|
||||
# The path of the JSON file which contains the expected results of our
|
||||
# integration tests. See `upload.test.ts` for more details.
|
||||
# NEXT_PUBLIC_EXPECTED_JSON_PATH = /path/to/dataset/expected.json
|
||||
#
|
||||
# NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH = /path/to/dataset/expected.json
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import { setupSentry } from '@ente/shared/sentry/config/sentry.config.base';
|
||||
import { initSentry } from '@ente/shared/sentry/config/sentry.config.base';
|
||||
|
||||
setupSentry('https://cbed7333f2810fbbdb692dcd76d8ca1a@sentry.ente.io/2');
|
||||
initSentry('https://cbed7333f2810fbbdb692dcd76d8ca1a@sentry.ente.io/2');
|
||||
|
|
0
apps/photos/sentry.edge.config.ts
Normal file
0
apps/photos/sentry.edge.config.ts
Normal file
|
@ -1,3 +1,6 @@
|
|||
defaults.url=https://sentry.ente.io/
|
||||
defaults.org=ente
|
||||
defaults.project=photos-web
|
||||
# This file is used by the SentryWebpackPlugin to upload sourcemaps (if the
|
||||
# SENTRY_AUTH_TOKEN environment variable is defined).
|
||||
|
||||
defaults.url = https://sentry.ente.io/
|
||||
defaults.org = ente
|
||||
defaults.project = photos-web
|
||||
|
|
|
@ -39,7 +39,10 @@ import {
|
|||
} from 'services/userService';
|
||||
import { CustomError } from '@ente/shared/error';
|
||||
import { addLogLine } from '@ente/shared/logging';
|
||||
import { clearLogsIfLocalStorageLimitExceeded } from '@ente/shared/logging/web';
|
||||
import {
|
||||
clearLogsIfLocalStorageLimitExceeded,
|
||||
logStartupMessage,
|
||||
} from '@ente/shared/logging/web';
|
||||
import isElectron from 'is-electron';
|
||||
import ElectronAPIs from '@ente/shared/electron';
|
||||
import {
|
||||
|
@ -71,8 +74,6 @@ import createEmotionCache from '@ente/shared/themes/createEmotionCache';
|
|||
import { THEME_COLOR } from '@ente/shared/themes/constants';
|
||||
import { SetTheme } from '@ente/shared/themes/types';
|
||||
import { setupI18n } from '@ente/shared/i18n';
|
||||
import { getSentryUserID } from '@ente/shared/sentry/utils';
|
||||
import { User } from '@ente/shared/user/types';
|
||||
import { useLocalState } from '@ente/shared/hooks/useLocalState';
|
||||
import { PHOTOS_PAGES as PAGES } from '@ente/shared/constants/pages';
|
||||
import { getTheme } from '@ente/shared/themes';
|
||||
|
@ -168,12 +169,7 @@ export default function App(props: EnteAppProps) {
|
|||
});
|
||||
// setup logging
|
||||
clearLogsIfLocalStorageLimitExceeded();
|
||||
const main = async () => {
|
||||
addLogLine(`userID: ${(getData(LS_KEYS.USER) as User)?.id}`);
|
||||
addLogLine(`sentryID: ${await getSentryUserID()}`);
|
||||
addLogLine(`sentry release ID: ${process.env.SENTRY_RELEASE}`);
|
||||
};
|
||||
main();
|
||||
logStartupMessage();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
import {
|
||||
getEndpoint,
|
||||
getFamilyPortalURL,
|
||||
isDevDeployment,
|
||||
} from '@ente/shared/network/api';
|
||||
import { getEndpoint, getFamilyPortalURL } from '@ente/shared/network/api';
|
||||
import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
|
||||
import localForage from '@ente/shared/storage/localForage';
|
||||
import { getToken } from '@ente/shared/storage/localStorage/helpers';
|
||||
|
@ -323,12 +319,9 @@ export const updateMapEnabledStatus = async (newStatus: boolean) => {
|
|||
};
|
||||
|
||||
export async function getDisableCFUploadProxyFlag(): Promise<boolean> {
|
||||
if (process.env.NEXT_PUBLIC_ENTE_DIRECT_UPLOAD === 'true') return true;
|
||||
|
||||
try {
|
||||
const disableCFUploadProxy =
|
||||
process.env.NEXT_PUBLIC_DISABLE_CF_UPLOAD_PROXY;
|
||||
if (isDevDeployment() && typeof disableCFUploadProxy !== 'undefined') {
|
||||
return disableCFUploadProxy === 'true';
|
||||
}
|
||||
const featureFlags = (
|
||||
await fetch('https://static.ente.io/feature_flags.json')
|
||||
).json() as GetFeatureFlagResponse;
|
||||
|
|
|
@ -100,14 +100,13 @@ const FILE_NAME_TO_JSON_NAME = [
|
|||
];
|
||||
|
||||
export async function testUpload() {
|
||||
if (!process.env.NEXT_PUBLIC_EXPECTED_JSON_PATH) {
|
||||
const jsonPath = process.env.NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH;
|
||||
if (!jsonPath) {
|
||||
throw Error(
|
||||
'upload test failed NEXT_PUBLIC_EXPECTED_JSON_PATH missing'
|
||||
'Please specify the NEXT_PUBLIC_ENTE_TEST_EXPECTED_JSON_PATH to run the upload tests'
|
||||
);
|
||||
}
|
||||
const expectedState = await import(
|
||||
process.env.NEXT_PUBLIC_EXPECTED_JSON_PATH
|
||||
);
|
||||
const expectedState = await import(jsonPath);
|
||||
if (!expectedState) {
|
||||
throw Error('upload test failed expectedState missing');
|
||||
}
|
||||
|
|
|
@ -6,12 +6,6 @@ export enum APPS {
|
|||
ALBUMS = 'ALBUMS',
|
||||
}
|
||||
|
||||
export enum APP_ENV {
|
||||
DEVELOPMENT = 'development',
|
||||
PRODUCTION = 'production',
|
||||
TEST = 'test',
|
||||
}
|
||||
|
||||
export const CLIENT_PACKAGE_NAMES = new Map([
|
||||
[APPS.ALBUMS, 'io.ente.albums.web'],
|
||||
[APPS.PHOTOS, 'io.ente.photos.web'],
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import { APP_ENV } from './constants';
|
||||
|
||||
export const getAppEnv = () =>
|
||||
process.env.NEXT_PUBLIC_APP_ENV ?? APP_ENV.PRODUCTION;
|
||||
|
||||
export const isDisableSentryFlagSet = () => {
|
||||
return process.env.NEXT_PUBLIC_DISABLE_SENTRY === 'true';
|
||||
};
|
||||
|
||||
export const getSentryRelease = () => process.env.SENTRY_RELEASE;
|
|
@ -1,9 +1,8 @@
|
|||
import isElectron from 'is-electron';
|
||||
import { logError } from '@ente/shared/sentry';
|
||||
import { getAppEnv } from '../apps/env';
|
||||
import { APP_ENV } from '../apps/constants';
|
||||
import { formatLog, logWeb } from './web';
|
||||
import { WorkerSafeElectronService } from '../electron/service';
|
||||
import { isDevBuild } from '../network/api';
|
||||
|
||||
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
export const MAX_LOG_LINES = 1000;
|
||||
|
@ -14,7 +13,7 @@ export function addLogLine(
|
|||
) {
|
||||
try {
|
||||
const completeLog = [log, ...optionalParams].join(' ');
|
||||
if (getAppEnv() === APP_ENV.DEVELOPMENT) {
|
||||
if (isDevBuild) {
|
||||
console.log(completeLog);
|
||||
}
|
||||
if (isElectron()) {
|
||||
|
@ -29,7 +28,7 @@ export function addLogLine(
|
|||
}
|
||||
|
||||
export const addLocalLog = (getLog: () => string) => {
|
||||
if (getAppEnv() === APP_ENV.DEVELOPMENT) {
|
||||
if (isDevBuild) {
|
||||
console.log(
|
||||
formatLog({
|
||||
logLine: getLog(),
|
||||
|
|
|
@ -8,6 +8,9 @@ import {
|
|||
setData,
|
||||
} from '@ente/shared/storage/localStorage';
|
||||
import { ElectronFile } from '../upload/types';
|
||||
import { addLogLine } from '.';
|
||||
import { getSentryUserID } from '../sentry/utils';
|
||||
import type { User } from '../user/types';
|
||||
|
||||
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
|
||||
export const MAX_LOG_LINES = 1000;
|
||||
|
@ -67,6 +70,12 @@ export const clearLogsIfLocalStorageLimitExceeded = () => {
|
|||
}
|
||||
};
|
||||
|
||||
export const logStartupMessage = async () => {
|
||||
addLogLine(`User ID: ${(getData(LS_KEYS.USER) as User)?.id}`);
|
||||
addLogLine(`Sentry ID: ${await getSentryUserID()}`);
|
||||
addLogLine(`Git commit: ${process.env.GIT_SHA}`);
|
||||
};
|
||||
|
||||
function getLogs(): Log[] {
|
||||
return getData(LS_KEYS.LOGS)?.logs ?? [];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export const getEndpoint = () => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
if (endpoint) {
|
||||
return endpoint;
|
||||
}
|
||||
return 'https://api.ente.io';
|
||||
|
@ -8,7 +8,7 @@ export const getEndpoint = () => {
|
|||
|
||||
export const getFileURL = (id: number) => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
if (endpoint) {
|
||||
return `${endpoint}/files/download/${id}`;
|
||||
}
|
||||
return `https://files.ente.io/?fileID=${id}`;
|
||||
|
@ -16,7 +16,7 @@ export const getFileURL = (id: number) => {
|
|||
|
||||
export const getPublicCollectionFileURL = (id: number) => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
if (endpoint) {
|
||||
return `${endpoint}/public-collection/files/download/${id}`;
|
||||
}
|
||||
return `https://public-albums.ente.io/download/?fileID=${id}`;
|
||||
|
@ -40,7 +40,7 @@ export const getCastThumbnailURL = (id: number) => {
|
|||
|
||||
export const getThumbnailURL = (id: number) => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
if (endpoint) {
|
||||
return `${endpoint}/files/preview/${id}`;
|
||||
}
|
||||
return `https://thumbnails.ente.io/?fileID=${id}`;
|
||||
|
@ -48,15 +48,15 @@ export const getThumbnailURL = (id: number) => {
|
|||
|
||||
export const getPublicCollectionThumbnailURL = (id: number) => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
if (endpoint) {
|
||||
return `${endpoint}/public-collection/files/preview/${id}`;
|
||||
}
|
||||
return `https://public-albums.ente.io/preview/?fileID=${id}`;
|
||||
};
|
||||
|
||||
export const getUploadEndpoint = () => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_UPLOAD_ENDPOINT;
|
||||
if (isDevDeployment() && endpoint) {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (endpoint) {
|
||||
return endpoint;
|
||||
}
|
||||
return `https://uploader.ente.io`;
|
||||
|
@ -64,7 +64,7 @@ export const getUploadEndpoint = () => {
|
|||
|
||||
export const getPaymentsURL = () => {
|
||||
const paymentsURL = process.env.NEXT_PUBLIC_ENTE_PAYMENT_ENDPOINT;
|
||||
if (isDevDeployment() && paymentsURL) {
|
||||
if (paymentsURL) {
|
||||
return paymentsURL;
|
||||
}
|
||||
return `https://payments.ente.io`;
|
||||
|
@ -72,38 +72,33 @@ export const getPaymentsURL = () => {
|
|||
|
||||
export const getAlbumsURL = () => {
|
||||
const albumsURL = process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT;
|
||||
if (isDevDeployment() && albumsURL) {
|
||||
if (albumsURL) {
|
||||
return albumsURL;
|
||||
}
|
||||
return `https://albums.ente.io`;
|
||||
};
|
||||
|
||||
// getFamilyPortalURL returns the endpoint for the family dashboard which can be used to
|
||||
// create or manage family.
|
||||
/**
|
||||
* Return the URL for the family dashboard which can be used to create or manage
|
||||
* family plans.
|
||||
*/
|
||||
export const getFamilyPortalURL = () => {
|
||||
const familyURL = process.env.NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT;
|
||||
if (isDevDeployment() && familyURL) {
|
||||
if (familyURL) {
|
||||
return familyURL;
|
||||
}
|
||||
return `https://family.ente.io`;
|
||||
};
|
||||
|
||||
/*
|
||||
It's a dev deployment (and should use the environment override for endpoints ) in three cases:
|
||||
1. when the URL opened is that of the staging web app, or
|
||||
2. when the URL opened is that of the staging album app, or
|
||||
3. if the app is running locally (hence node_env is development)
|
||||
4. if the app is running in test mode
|
||||
*/
|
||||
export const isDevDeployment = () => {
|
||||
if (globalThis?.location) {
|
||||
return (
|
||||
process.env.NEXT_PUBLIC_ENTE_WEB_ENDPOINT ===
|
||||
globalThis.location.origin ||
|
||||
process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT ===
|
||||
globalThis.location.origin ||
|
||||
process.env.NEXT_PUBLIC_IS_TEST_APP === 'true' ||
|
||||
process.env.NODE_ENV === 'development'
|
||||
);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* A build is considered as a development build if either the NODE_ENV is
|
||||
* environment variable is set to 'development'.
|
||||
*
|
||||
* NODE_ENV is automatically set to 'development' when we run `yarn dev`. From
|
||||
* Next.js docs:
|
||||
*
|
||||
* > If the environment variable NODE_ENV is unassigned, Next.js automatically
|
||||
* assigns development when running the `next dev` command, or production for
|
||||
* all other commands.
|
||||
*/
|
||||
export const isDevBuild = process.env.NODE_ENV === 'development';
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const ENV_DEVELOPMENT = 'development';
|
||||
const ENV_PRODUCTION = 'production';
|
||||
const ENV_TEST = 'test';
|
||||
|
||||
module.exports = {
|
||||
ENV_DEVELOPMENT,
|
||||
ENV_PRODUCTION,
|
||||
ENV_TEST,
|
||||
};
|
||||
|
||||
module.exports.getAppEnv = () => {
|
||||
return process.env.NEXT_PUBLIC_APP_ENV ?? ENV_PRODUCTION;
|
||||
};
|
||||
|
||||
module.exports.isDisableSentryFlagSet = () => {
|
||||
return process.env.NEXT_PUBLIC_DISABLE_SENTRY === 'true';
|
||||
};
|
|
@ -1,61 +1,73 @@
|
|||
/**
|
||||
* @file Configure the Next.js build
|
||||
*
|
||||
* This file gets used by the Next.js build phase, and is not included in the
|
||||
* browser build. It will not be parsed by Webpack, Babel or TypeScript, so
|
||||
* don't use features that will not be available in our target node version.
|
||||
*
|
||||
* https://nextjs.org/docs/pages/api-reference/next-config-js
|
||||
*/
|
||||
|
||||
const { withSentryConfig } = require('@sentry/nextjs');
|
||||
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
|
||||
const cp = require('child_process');
|
||||
|
||||
const { getGitSha, getIsSentryEnabled } = require('./utils/sentry');
|
||||
const gitSHA = cp.execSync('git rev-parse --short HEAD', {
|
||||
cwd: __dirname,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
|
||||
const GIT_SHA = getGitSha();
|
||||
|
||||
const IS_SENTRY_ENABLED = getIsSentryEnabled();
|
||||
|
||||
module.exports = (phase) =>
|
||||
withSentryConfig(
|
||||
{
|
||||
sentry: {
|
||||
widenClientFileUpload: true,
|
||||
disableServerWebpackPlugin: true,
|
||||
autoInstrumentServerFunctions: false,
|
||||
},
|
||||
compiler: {
|
||||
emotion: {
|
||||
importMap: {
|
||||
'@mui/material': {
|
||||
styled: {
|
||||
canonicalImport: ['@emotion/styled', 'default'],
|
||||
styledBaseImport: ['@mui/material', 'styled'],
|
||||
},
|
||||
},
|
||||
'@mui/material/styles': {
|
||||
styled: {
|
||||
canonicalImport: ['@emotion/styled', 'default'],
|
||||
styledBaseImport: [
|
||||
'@mui/material/styles',
|
||||
'styled',
|
||||
],
|
||||
},
|
||||
},
|
||||
const nextConfig = {
|
||||
compiler: {
|
||||
emotion: {
|
||||
importMap: {
|
||||
'@mui/material': {
|
||||
styled: {
|
||||
canonicalImport: ['@emotion/styled', 'default'],
|
||||
styledBaseImport: ['@mui/material', 'styled'],
|
||||
},
|
||||
},
|
||||
'@mui/material/styles': {
|
||||
styled: {
|
||||
canonicalImport: ['@emotion/styled', 'default'],
|
||||
styledBaseImport: ['@mui/material/styles', 'styled'],
|
||||
},
|
||||
},
|
||||
},
|
||||
transpilePackages: [
|
||||
'@mui/material',
|
||||
'@mui/system',
|
||||
'@mui/icons-material',
|
||||
],
|
||||
env: {
|
||||
SENTRY_RELEASE: GIT_SHA,
|
||||
NEXT_PUBLIC_IS_TEST_APP: process.env.IS_TEST_RELEASE || 'false',
|
||||
},
|
||||
|
||||
// https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
|
||||
webpack: (config, { isServer }) => {
|
||||
if (!isServer) {
|
||||
config.resolve.fallback.fs = false;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
},
|
||||
{
|
||||
dryRun: phase === PHASE_DEVELOPMENT_SERVER || !IS_SENTRY_ENABLED,
|
||||
release: GIT_SHA,
|
||||
},
|
||||
transpilePackages: ['@mui/material', '@mui/system', '@mui/icons-material'],
|
||||
|
||||
// Add environment variables to the JavaScript bundle. They will be
|
||||
// available as `process.env.VAR_NAME` to our code.
|
||||
env: {
|
||||
GIT_SHA: gitSHA,
|
||||
},
|
||||
|
||||
// https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
|
||||
webpack: (config, { isServer }) => {
|
||||
if (!isServer) {
|
||||
config.resolve.fallback.fs = false;
|
||||
}
|
||||
);
|
||||
return config;
|
||||
},
|
||||
|
||||
// Build time Sentry configuration
|
||||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
|
||||
sentry: {
|
||||
widenClientFileUpload: true,
|
||||
disableServerWebpackPlugin: true,
|
||||
},
|
||||
};
|
||||
|
||||
const sentryWebpackPluginOptions = {};
|
||||
|
||||
// withSentryConfig extends the default Next.js usage of webpack to:
|
||||
//
|
||||
// 1. Initialize the SDK on client page load (See `sentry.client.config.ts`)
|
||||
//
|
||||
// 2. Upload sourcemaps, using the settings defined in `sentry.properties`.
|
||||
// Sourcemaps are only uploaded if SENTRY_AUTH_TOKEN is defined.
|
||||
//
|
||||
// Irritatingly, Sentry insists that we create empty sentry.server.config.ts and
|
||||
// sentry.edge.config.ts files, even though we are not using those parts.
|
||||
module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
const {
|
||||
getAppEnv,
|
||||
ENV_DEVELOPMENT,
|
||||
isDisableSentryFlagSet,
|
||||
} = require('../env.js');
|
||||
const cp = require('child_process');
|
||||
|
||||
module.exports.getIsSentryEnabled = () => {
|
||||
const isAppENVDevelopment = getAppEnv() === ENV_DEVELOPMENT;
|
||||
const isSentryDisabled = isDisableSentryFlagSet();
|
||||
return !isAppENVDevelopment && !isSentryDisabled;
|
||||
};
|
||||
|
||||
module.exports.getGitSha = () =>
|
||||
cp.execSync('git rev-parse --short HEAD', {
|
||||
cwd: __dirname,
|
||||
encoding: 'utf8',
|
||||
});
|
|
@ -2,44 +2,37 @@ import * as Sentry from '@sentry/nextjs';
|
|||
import { getSentryUserID } from '@ente/shared/sentry/utils';
|
||||
import { runningInBrowser } from '@ente/shared/platform';
|
||||
import { getHasOptedOutOfCrashReports } from '@ente/shared/storage/localStorage/helpers';
|
||||
import { getIsSentryEnabled } from '@ente/shared/sentry/utils';
|
||||
import { getAppEnv, getSentryRelease } from '@ente/shared/apps/env';
|
||||
import { isDevBuild } from '@ente/shared/network/api';
|
||||
|
||||
export const setupSentry = async (dsn: string) => {
|
||||
const HAS_OPTED_OUT_OF_CRASH_REPORTING =
|
||||
runningInBrowser() && getHasOptedOutOfCrashReports();
|
||||
export const initSentry = async (dsn: string) => {
|
||||
// Don't initialize Sentry for dev builds
|
||||
if (isDevBuild) return;
|
||||
|
||||
if (!HAS_OPTED_OUT_OF_CRASH_REPORTING) {
|
||||
const APP_ENV = getAppEnv();
|
||||
const IS_ENABLED = getIsSentryEnabled();
|
||||
const SENTRY_RELEASE = getSentryRelease();
|
||||
// Don't initialize Sentry if the user has opted out of crash reporting
|
||||
if (optedOut()) return;
|
||||
|
||||
Sentry.init({
|
||||
dsn,
|
||||
enabled: IS_ENABLED,
|
||||
environment: APP_ENV,
|
||||
release: SENTRY_RELEASE,
|
||||
attachStacktrace: true,
|
||||
autoSessionTracking: false,
|
||||
tunnel: 'https://sentry-reporter.ente.io',
|
||||
beforeSend(event) {
|
||||
event.request = event.request || {};
|
||||
const currentURL = new URL(document.location.href);
|
||||
currentURL.hash = '';
|
||||
event.request.url = currentURL.href;
|
||||
return event;
|
||||
},
|
||||
integrations: function (i) {
|
||||
return i.filter(function (i) {
|
||||
return i.name !== 'Breadcrumbs';
|
||||
});
|
||||
},
|
||||
// ...
|
||||
// Note: if you want to override the automatic release value, do not set a
|
||||
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
|
||||
// that it will also get attached to your source maps
|
||||
});
|
||||
Sentry.init({
|
||||
dsn,
|
||||
release: process.env.GIT_SHA,
|
||||
attachStacktrace: true,
|
||||
autoSessionTracking: false,
|
||||
tunnel: 'https://sentry-reporter.ente.io',
|
||||
beforeSend(event) {
|
||||
event.request = event.request || {};
|
||||
const currentURL = new URL(document.location.href);
|
||||
currentURL.hash = '';
|
||||
event.request.url = currentURL.href;
|
||||
return event;
|
||||
},
|
||||
integrations: function (i) {
|
||||
return i.filter(function (i) {
|
||||
return i.name !== 'Breadcrumbs';
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Sentry.setUser({ id: await getSentryUserID() });
|
||||
}
|
||||
Sentry.setUser({ id: await getSentryUserID() });
|
||||
};
|
||||
|
||||
/** Return true if the user has opted out of crash reporting */
|
||||
const optedOut = () => runningInBrowser() && getHasOptedOutOfCrashReports();
|
||||
|
|
|
@ -4,9 +4,6 @@ import {
|
|||
setLocalSentryUserID,
|
||||
} from '@ente/shared/storage/localStorage/helpers';
|
||||
import isElectron from 'is-electron';
|
||||
import { getAppEnv } from '@ente/shared/apps/env';
|
||||
import { APP_ENV } from '@ente/shared/apps/constants';
|
||||
import { isDisableSentryFlagSet } from '@ente/shared/apps/env';
|
||||
import { ApiError } from '../error';
|
||||
import { HttpStatusCode } from 'axios';
|
||||
|
||||
|
@ -47,9 +44,3 @@ export function isErrorUnnecessaryForSentry(error: any) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export const getIsSentryEnabled = () => {
|
||||
const isAppENVDevelopment = getAppEnv() === APP_ENV.DEVELOPMENT;
|
||||
const isSentryDisabled = isDisableSentryFlagSet();
|
||||
return !isAppENVDevelopment && !isSentryDisabled;
|
||||
};
|
||||
|
|
|
@ -1,33 +1,31 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is run by the Cloudflare Pages integration when deploying the apps
|
||||
# in this repository. The app to build is decided based on the the value of the
|
||||
# CF_PAGES_BRANCH environment variable.
|
||||
# in this repository. The app to build and the environment variables to use is
|
||||
# decided based on the the value of the CF_PAGES_BRANCH environment variable.
|
||||
#
|
||||
# Ref: https://developers.cloudflare.com/pages/how-to/build-commands-branches/
|
||||
#
|
||||
# The CF Pages configuration is set to use `out/` as the build output directory,
|
||||
# so once we're done building we copy the app specific output to `out/`.
|
||||
|
||||
set -o errexit
|
||||
set -o xtrace
|
||||
|
||||
# The Cloudflare Pages build configuration is set to use `out/` as the build
|
||||
# output directory, so once we're done building we copy the app specific output
|
||||
# to `out/` (symlinking didn't work).
|
||||
|
||||
rm -rf out
|
||||
|
||||
if test "$CF_PAGES_BRANCH" = "auth-release"
|
||||
then
|
||||
# By default, for preview deployments the NEXT_PUBLIC_APP_ENV is set to
|
||||
# "test" in the CF environment variables. For production deployments of the
|
||||
# auth app, reset this to "production".
|
||||
#
|
||||
# This is not needed for the default `yarn export:photos` case, because
|
||||
# there the actual production deployment runs without NEXT_PUBLIC_APP_ENV
|
||||
# being set to anything (and the other preview deployments have
|
||||
# NEXT_PUBLIC_APP_ENV set to "test", as is correct).
|
||||
export NEXT_PUBLIC_APP_ENV=production
|
||||
if test "$CF_PAGES_BRANCH" = "photos-release"; then
|
||||
yarn export:photos
|
||||
cp -R apps/photos/out .
|
||||
elif test "$CF_PAGES_BRANCH" = "auth-release"; then
|
||||
yarn export:auth
|
||||
cp -R apps/auth/out .
|
||||
else
|
||||
# Apart from the named branches, everything else connects to the dev APIs.
|
||||
export NEXT_PUBLIC_ENTE_ENDPOINT=https://dev-api.ente.io
|
||||
export NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT=https://dev-albums.ente.io
|
||||
|
||||
yarn export:photos
|
||||
cp -R apps/photos/out .
|
||||
fi
|
||||
|
|
|
@ -24,10 +24,7 @@
|
|||
"NEXT_PUBLIC_ENTE_PAYMENT_ENDPOINT",
|
||||
"NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT",
|
||||
"NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT",
|
||||
"NEXT_PUBLIC_ENTE_WEB_ENDPOINT",
|
||||
"NEXT_PUBLIC_IS_TEST_APP",
|
||||
"NODE_ENV",
|
||||
"SENTRY_RELEASE",
|
||||
"SENTRY_AUTH_TOKEN"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue