Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): Fix environment variable handling in Docker builds for dev/prod deployments (#10859)

Nicholas Tindle0325ec0a2ca6
diff --git a/autogpt_platform/frontend/.prettierignore b/autogpt_platform/frontend/.prettierignore
index 9951e9905d..e4a8a24cc5 100644
--- a/autogpt_platform/frontend/.prettierignore
+++ b/autogpt_platform/frontend/.prettierignore
@@ -4,3 +4,5 @@ pnpm-lock.yaml
.auth
build
public
+Dockerfile
+.prettierignore
diff --git a/autogpt_platform/frontend/Dockerfile b/autogpt_platform/frontend/Dockerfile
index 311b4e4a26..57f91e62aa 100644
--- a/autogpt_platform/frontend/Dockerfile
+++ b/autogpt_platform/frontend/Dockerfile
@@ -12,9 +12,16 @@ COPY autogpt_platform/frontend/ .
# Allow CI to opt-in to Playwright test build-time flags
ARG NEXT_PUBLIC_PW_TEST="false"
ENV NEXT_PUBLIC_PW_TEST=$NEXT_PUBLIC_PW_TEST
-RUN if [ -f .env ]; then \
+ENV NODE_ENV="production"
+# Merge env files appropriately based on environment
+RUN if [ -f .env.production ]; then \
+ # In CI/CD: merge defaults with production (production takes precedence)
+ cat .env.default .env.production > .env.merged && mv .env.merged .env.production; \
+ elif [ -f .env ]; then \
+ # Local with custom .env: merge defaults with .env
cat .env.default .env > .env.merged && mv .env.merged .env; \
else \
+ # Local without custom .env: use defaults
cp .env.default .env; \
fi
RUN pnpm run generate:api
diff --git a/autogpt_platform/frontend/instrumentation-client.ts b/autogpt_platform/frontend/instrumentation-client.ts
index d491553ae7..656a39a42e 100644
--- a/autogpt_platform/frontend/instrumentation-client.ts
+++ b/autogpt_platform/frontend/instrumentation-client.ts
@@ -2,12 +2,16 @@
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import { BehaveAs, getBehaveAs, getEnvironmentStr } from "@/lib/utils";
+import {
+ AppEnv,
+ BehaveAs,
+ getAppEnv,
+ getBehaveAs,
+ getEnvironmentStr,
+} from "@/lib/utils";
import * as Sentry from "@sentry/nextjs";
-const isProdOrDev =
- process.env.NODE_ENV === "production" ||
- process.env.NODE_ENV === "development";
+const isProdOrDev = [AppEnv.PROD, AppEnv.DEV].includes(getAppEnv());
const isCloud = getBehaveAs() === BehaveAs.CLOUD;
const isDisabled = process.env.DISABLE_SENTRY === "true";
diff --git a/autogpt_platform/frontend/sentry.edge.config.ts b/autogpt_platform/frontend/sentry.edge.config.ts
index e0d3d5c5ce..c6d75bfd45 100644
--- a/autogpt_platform/frontend/sentry.edge.config.ts
+++ b/autogpt_platform/frontend/sentry.edge.config.ts
@@ -4,11 +4,15 @@
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
-import { BehaveAs, getBehaveAs, getEnvironmentStr } from "./src/lib/utils";
-
-const isProdOrDev =
- process.env.NODE_ENV === "production" ||
- process.env.NODE_ENV === "development";
+import {
+ AppEnv,
+ BehaveAs,
+ getAppEnv,
+ getBehaveAs,
+ getEnvironmentStr,
+} from "./src/lib/utils";
+
+const isProdOrDev = [AppEnv.PROD, AppEnv.DEV].includes(getAppEnv());
const isCloud = getBehaveAs() === BehaveAs.CLOUD;
const isDisabled = process.env.DISABLE_SENTRY === "true";
diff --git a/autogpt_platform/frontend/sentry.server.config.ts b/autogpt_platform/frontend/sentry.server.config.ts
index 20a9b718b4..75d371e62f 100644
--- a/autogpt_platform/frontend/sentry.server.config.ts
+++ b/autogpt_platform/frontend/sentry.server.config.ts
@@ -2,13 +2,17 @@
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import { BehaveAs, getBehaveAs, getEnvironmentStr } from "@/lib/utils";
+import {
+ AppEnv,
+ BehaveAs,
+ getAppEnv,
+ getBehaveAs,
+ getEnvironmentStr,
+} from "@/lib/utils";
import * as Sentry from "@sentry/nextjs";
// import { NodeProfilingIntegration } from "@sentry/profiling-node";
-const isProdOrDev =
- process.env.NODE_ENV === "production" ||
- process.env.NODE_ENV === "development";
+const isProdOrDev = [AppEnv.PROD, AppEnv.DEV].includes(getAppEnv());
const isCloud = getBehaveAs() === BehaveAs.CLOUD;
const isDisabled = process.env.DISABLE_SENTRY === "true";