set telemetry post frontend build in standalone docker img

This commit is contained in:
Maidul Islam
2023-10-17 12:22:08 +01:00
parent 136308f299
commit fb7c7045e9
10 changed files with 53 additions and 7 deletions

View File

@@ -74,6 +74,7 @@ COPY backend/package*.json ./
RUN npm ci --only-production RUN npm ci --only-production
COPY /backend . COPY /backend .
COPY standalone-entrypoint.sh standalone-entrypoint.sh
RUN npm run build RUN npm run build
# Production stage # Production stage
@@ -105,6 +106,9 @@ ENV NODE_ENV production
WORKDIR /backend WORKDIR /backend
CMD ["node", "build/index.js"] ENV TELEMETRY_ENABLED true
CMD ["./standalone-entrypoint.sh"]

View File

@@ -55,9 +55,6 @@ export const setup = async () => {
// initializing global feature set // initializing global feature set
await EELicenseService.initGlobalFeatureSet(); await EELicenseService.initGlobalFeatureSet();
// initializing the database connection
await DatabaseService.initDatabase(await getMongoURL());
await initializePassport(); await initializePassport();
// re-encrypt any data previously encrypted under server hex 128-bit ENCRYPTION_KEY // re-encrypt any data previously encrypted under server hex 128-bit ENCRYPTION_KEY

View File

@@ -0,0 +1,13 @@
#!/bin/sh
scripts/replace-standalone-build-variable.sh "$BAKED_NEXT_PUBLIC_POSTHOG_API_KEY" "$NEXT_PUBLIC_POSTHOG_API_KEY"
scripts/replace-standalone-build-variable.sh "$BAKED_NEXT_PUBLIC_INTERCOM_ID" "$NEXT_PUBLIC_INTERCOM_ID"
if [ "$TELEMETRY_ENABLED" != "false" ]; then
echo "Telemetry is enabled"
scripts/set-standalone-build-telemetry.sh true
else
echo "Client opted out of telemetry"
scripts/set-standalone-build-telemetry.sh false
fi

View File

@@ -0,0 +1,16 @@
#!/bin/sh
ORIGINAL=$1
REPLACEMENT=$2
if [ "${ORIGINAL}" = "${REPLACEMENT}" ]; then
echo "Environment variable replacement is the same, skipping.."
exit 0
fi
echo "Replacing pre-baked value.."
find public .next -type f -name "*.js" |
while read file; do
sed -i "s|$ORIGINAL|$REPLACEMENT|g" "$file"
done

0
frontend/scripts/replace-variable.sh Normal file → Executable file
View File

View File

@@ -0,0 +1,8 @@
#!/bin/sh
VALUE=$1
find public .next -type f -name "*.js" |
while read file; do
sed -i "s|TELEMETRY_CAPTURING_ENABLED|$VALUE|g" "$file"
done

0
frontend/scripts/set-telemetry.sh Normal file → Executable file
View File

View File

@@ -10,7 +10,7 @@ export const initPostHog = () => {
try { try {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
// @ts-ignore // @ts-ignore
if (ENV === "production" && TELEMETRY_CAPTURING_ENABLED) { if (ENV === "production" && TELEMETRY_CAPTURING_ENABLED === "true") {
posthog.init(POSTHOG_API_KEY, { posthog.init(POSTHOG_API_KEY, {
api_host: POSTHOG_HOST api_host: POSTHOG_HOST
}); });

View File

@@ -13,7 +13,7 @@ class Capturer {
} }
capture(item: string) { capture(item: string) {
if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED) { if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED === "true") {
try { try {
this.api.capture(item); this.api.capture(item);
} catch (error) { } catch (error) {
@@ -23,7 +23,7 @@ class Capturer {
} }
identify(id: string, email?: string) { identify(id: string, email?: string) {
if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED) { if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED === "true") {
try { try {
this.api.identify(id, { this.api.identify(id, {
email: email email: email

8
standalone-entrypoint.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
cd frontend-build
scripts/initialize-standalone-build.sh
cd ../
exec node build/index.js