Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

set telemetry post frontend build in standalone docker img

Maidul Islamfb7c7045e995
diff --git a/Dockerfile.standalone-infisical b/Dockerfile.standalone-infisical
index 1ce05ccc17..34b7607b74 100644
--- a/Dockerfile.standalone-infisical
+++ b/Dockerfile.standalone-infisical
@@ -74,6 +74,7 @@ COPY backend/package*.json ./
RUN npm ci --only-production
COPY /backend .
+COPY standalone-entrypoint.sh standalone-entrypoint.sh
RUN npm run build
# Production stage
@@ -105,6 +106,9 @@ ENV NODE_ENV production
WORKDIR /backend
-CMD ["node", "build/index.js"]
+ENV TELEMETRY_ENABLED true
+
+CMD ["./standalone-entrypoint.sh"]
+
diff --git a/backend/src/utils/setup/index.ts b/backend/src/utils/setup/index.ts
index d85d63aca0..6625bff7b4 100644
--- a/backend/src/utils/setup/index.ts
+++ b/backend/src/utils/setup/index.ts
@@ -55,9 +55,6 @@ export const setup = async () => {
// initializing global feature set
await EELicenseService.initGlobalFeatureSet();
- // initializing the database connection
- await DatabaseService.initDatabase(await getMongoURL());
-
await initializePassport();
// re-encrypt any data previously encrypted under server hex 128-bit ENCRYPTION_KEY
diff --git a/frontend/scripts/initialize-standalone-build.sh b/frontend/scripts/initialize-standalone-build.sh
new file mode 100755
index 0000000000..d9138bb77e
--- /dev/null
+++ b/frontend/scripts/initialize-standalone-build.sh
@@ -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
diff --git a/frontend/scripts/replace-standalone-build-variable.sh b/frontend/scripts/replace-standalone-build-variable.sh
new file mode 100755
index 0000000000..fde4ca282f
--- /dev/null
+++ b/frontend/scripts/replace-standalone-build-variable.sh
@@ -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
diff --git a/frontend/scripts/replace-variable.sh b/frontend/scripts/replace-variable.sh
old mode 100644
new mode 100755
diff --git a/frontend/scripts/set-standalone-build-telemetry.sh b/frontend/scripts/set-standalone-build-telemetry.sh
new file mode 100644
index 0000000000..5e788b6b91
--- /dev/null
+++ b/frontend/scripts/set-standalone-build-telemetry.sh
@@ -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
diff --git a/frontend/scripts/set-telemetry.sh b/frontend/scripts/set-telemetry.sh
old mode 100644
new mode 100755
diff --git a/frontend/src/components/analytics/posthog.ts b/frontend/src/components/analytics/posthog.ts
index 706f795151..246d5c9cc4 100644
--- a/frontend/src/components/analytics/posthog.ts
+++ b/frontend/src/components/analytics/posthog.ts
@@ -10,7 +10,7 @@ export const initPostHog = () => {
try {
if (typeof window !== "undefined") {
// @ts-ignore
- if (ENV === "production" && TELEMETRY_CAPTURING_ENABLED) {
+ if (ENV === "production" && TELEMETRY_CAPTURING_ENABLED === "true") {
posthog.init(POSTHOG_API_KEY, {
api_host: POSTHOG_HOST
});
diff --git a/frontend/src/components/utilities/telemetry/Telemetry.ts b/frontend/src/components/utilities/telemetry/Telemetry.ts
index 2676bed852..76e86fa379 100644
--- a/frontend/src/components/utilities/telemetry/Telemetry.ts
+++ b/frontend/src/components/utilities/telemetry/Telemetry.ts
@@ -13,7 +13,7 @@ class Capturer {
}
capture(item: string) {
- if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED) {
+ if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED === "true") {
try {
this.api.capture(item);
} catch (error) {
@@ -23,7 +23,7 @@ class Capturer {
}
identify(id: string, email?: string) {
- if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED) {
+ if (ENV === 'production' && TELEMETRY_CAPTURING_ENABLED === "true") {
try {
this.api.identify(id, {
email: email
diff --git a/standalone-entrypoint.sh b/standalone-entrypoint.sh
new file mode 100755
index 0000000000..e15931dc41
--- /dev/null
+++ b/standalone-entrypoint.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+cd frontend-build
+scripts/initialize-standalone-build.sh
+
+cd ../
+
+exec node build/index.js