Skip to content

Open-source status page, incident response and uptime monitoring

fix: make GCP actually optional and fix other env validation issues (#2537)

Max5bc95dfeed21
diff --git a/.env.docker.example b/.env.docker.example
index c43abaafc..e248359b6 100644
--- a/.env.docker.example
+++ b/.env.docker.example
@@ -83,10 +83,10 @@ AUTH_OIDC_NAME=
# GOOGLE CLOUD
# ============================================================================
# Google Cloud Platform (optional - for scheduled tasks)
-GCP_PROJECT_ID=your-value
-GCP_LOCATION=your-value
-GCP_CLIENT_EMAIL=your-value
-GCP_PRIVATE_KEY=your-value
+GCP_PROJECT_ID=
+GCP_LOCATION=
+GCP_CLIENT_EMAIL=
+GCP_PRIVATE_KEY=
# Cron secret for scheduled jobs.
# Also used by the private-location app to authenticate status forwards to the workflows
diff --git a/apps/workflows/src/cron/checker.ts b/apps/workflows/src/cron/checker.ts
index 39c76877a..73d0dbb11 100644
--- a/apps/workflows/src/cron/checker.ts
+++ b/apps/workflows/src/cron/checker.ts
@@ -50,18 +50,54 @@ export const isAuthorizedDomain = (url: string) => {
const logger = getLogger("workflow");
-const client = new CloudTasksClient({
- // fallback: true,
- projectId: env().GCP_PROJECT_ID,
- credentials: {
- client_email: env().GCP_CLIENT_EMAIL,
- private_key: env().GCP_PRIVATE_KEY.replaceAll("\\n", "\n"),
- },
-});
+/**
+ * Check if GCP Cloud Tasks is properly configured.
+ * Returns false if credentials are missing or set to placeholder values.
+ */
+function isGcpConfigured(): boolean {
+ const projectId = env().GCP_PROJECT_ID;
+ const location = env().GCP_LOCATION;
+ const clientEmail = env().GCP_CLIENT_EMAIL;
+ const privateKey = env().GCP_PRIVATE_KEY;
+
+ return (
+ projectId !== "" &&
+ projectId !== "your-value" &&
+ location !== "" &&
+ location !== "your-value" &&
+ clientEmail !== "" &&
+ clientEmail !== "your-value" &&
+ privateKey !== "" &&
+ privateKey !== "your-value"
+ );
+}
+
+// Only initialize CloudTasksClient if GCP credentials are properly configured
+// This allows self-hosted deployments to run without GCP Cloud Tasks
+let client: CloudTasksClient | null = null;
+
+if (isGcpConfigured()) {
+ client = new CloudTasksClient({
+ // fallback: true,
+ projectId: env().GCP_PROJECT_ID,
+ credentials: {
+ client_email: env().GCP_CLIENT_EMAIL,
+ private_key: env().GCP_PRIVATE_KEY.replaceAll("\\n", "\n"),
+ },
+ });
+}
export async function sendCheckerTasks(
periodicity: z.infer<typeof monitorPeriodicitySchema>,
): Promise<{ success: number; failed: number }> {
+ // If GCP Cloud Tasks is not configured, skip task creation
+ if (!client) {
+ logger.warn("GCP Cloud Tasks not configured - skipping checker tasks", {
+ periodicity,
+ });
+ return { success: 0, failed: 0 };
+ }
+
const parent = client.queuePath(
env().GCP_PROJECT_ID,
env().GCP_LOCATION,
@@ -240,6 +276,11 @@ const createCronTask = async (
{ row, timestamp, status, region }: TaskInput,
parent: string,
) => {
+ // This should never happen due to the guard in sendCheckerTasks, but TypeScript needs this
+ if (!client) {
+ throw new Error("GCP Cloud Tasks client is not initialized");
+ }
+
let payload:
| z.infer<typeof httpPayloadSchema>
| z.infer<typeof tpcPayloadSchema>
diff --git a/apps/workflows/src/cron/monitor.ts b/apps/workflows/src/cron/monitor.ts
index 371f9b4e4..0e3b1e399 100644
--- a/apps/workflows/src/cron/monitor.ts
+++ b/apps/workflows/src/cron/monitor.ts
@@ -29,20 +29,49 @@ import { env } from "../env";
const redis = Redis.fromEnv();
-const client = new CloudTasksClient({
- projectId: env().GCP_PROJECT_ID,
- fallback: "rest",
- credentials: {
- client_email: env().GCP_CLIENT_EMAIL,
- private_key: env().GCP_PRIVATE_KEY.replaceAll("\\n", "\n"),
- },
-});
-
-const parent = client.queuePath(
- env().GCP_PROJECT_ID,
- env().GCP_LOCATION,
- "workflow",
-);
+// Check if GCP is properly configured (not empty and not placeholder values)
+const isGcpConfigured = () => {
+ const gcpProjectId = env().GCP_PROJECT_ID;
+ const gcpLocation = env().GCP_LOCATION;
+ const gcpClientEmail = env().GCP_CLIENT_EMAIL;
+ const gcpPrivateKey = env().GCP_PRIVATE_KEY;
+
+ return (
+ gcpProjectId &&
+ gcpLocation &&
+ gcpClientEmail &&
+ gcpPrivateKey &&
+ gcpProjectId !== "" &&
+ gcpLocation !== "" &&
+ gcpClientEmail !== "" &&
+ gcpPrivateKey !== "" &&
+ gcpProjectId !== "your-value" &&
+ gcpLocation !== "your-value" &&
+ gcpClientEmail !== "your-value" &&
+ gcpPrivateKey !== "your-value"
+ );
+};
+
+// Only initialize Cloud Tasks client if GCP is properly configured
+let client: CloudTasksClient | null = null;
+let parent: string | null = null;
+
+if (isGcpConfigured()) {
+ client = new CloudTasksClient({
+ projectId: env().GCP_PROJECT_ID,
+ fallback: "rest",
+ credentials: {
+ client_email: env().GCP_CLIENT_EMAIL,
+ private_key: env().GCP_PRIVATE_KEY.replaceAll("\\n", "\n"),
+ },
+ });
+
+ parent = client.queuePath(
+ env().GCP_PROJECT_ID,
+ env().GCP_LOCATION,
+ "workflow",
+ );
+}
const limiter = new RateLimiter({ tokensPerInterval: 15, interval: "second" });
@@ -184,6 +213,15 @@ async function workflowInit({
return;
}
const initialRun = new Date().getTime();
+
+ // Only create GCP Cloud Tasks if GCP is configured
+ if (!client || !parent) {
+ console.log(
+ `Skipping workflow for user ${user.userId} - GCP not configured`,
+ );
+ return;
+ }
+
await CreateTask({
parent,
client: client,
@@ -191,6 +229,7 @@ async function workflowInit({
userId: user.userId,
initialRun,
});
+
await redis.set(`workflow:user:${user.userId}`, initialRun, {
ex: 30 * 86400,
});
@@ -229,13 +268,20 @@ export async function Step14Days(userId: number, workFlowRunTimestamp: number) {
});
}
- await CreateTask({
- parent,
- client: client,
- step: "3days",
- userId: user.id,
- initialRun: workFlowRunTimestamp,
- });
+ // Only create GCP Cloud Tasks if GCP is configured
+ if (client && parent) {
+ await CreateTask({
+ parent,
+ client: client,
+ step: "3days",
+ userId: user.id,
+ initialRun: workFlowRunTimestamp,
+ });
+ } else {
+ console.log(
+ `Skipping Cloud Tasks creation for user ${user.id} - GCP not configured`,
+ );
+ }
}
export async function Step3Days(userId: number, workFlowRunTimestamp: number) {
@@ -270,13 +316,20 @@ export async function Step3Days(userId: number, workFlowRunTimestamp: number) {
});
}
- await CreateTask({
- client,
- parent,
- step: "paused",
- userId,
- initialRun: workFlowRunTimestamp,
- });
+ // Only create GCP Cloud Tasks if GCP is configured
+ if (client && parent) {
+ await CreateTask({
+ client,
+ parent,
+ step: "paused",
+ userId,
+ initialRun: workFlowRunTimestamp,
+ });
+ } else {
+ console.log(
+ `Skipping Cloud Tasks creation for user ${userId} - GCP not configured`,
+ );
+ }
}
export async function StepPaused(userId: number, workFlowRunTimestamp: number) {
diff --git a/packages/api/src/env.ts b/packages/api/src/env.ts
index 66d923c58..8cc9b9687 100644
--- a/packages/api/src/env.ts
+++ b/packages/api/src/env.ts
@@ -1,19 +1,22 @@
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
+// Parse SELF_HOST using z.stringbool() to ensure consistency with the schema
+const isSelfHost = z.stringbool().catch(false).parse(process.env.SELF_HOST);
+
export const env = createEnv({
server: {
- STRIPE_SECRET_KEY: z.string(),
- PROJECT_ID_VERCEL: z.string(),
- TEAM_ID_VERCEL: z.string(),
- VERCEL_AUTH_BEARER_TOKEN: z.string(),
- TINY_BIRD_API_KEY: z.string(),
+ STRIPE_SECRET_KEY: isSelfHost ? z.string().optional() : z.string(),
+ PROJECT_ID_VERCEL: isSelfHost ? z.string().optional() : z.string(),
+ TEAM_ID_VERCEL: isSelfHost ? z.string().optional() : z.string(),
+ VERCEL_AUTH_BEARER_TOKEN: isSelfHost ? z.string().optional() : z.string(),
+ TINY_BIRD_API_KEY: isSelfHost ? z.string().optional() : z.string(),
TINYBIRD_URL: z.string().default("https://api.tinybird.co"),
TINYBIRD_NOOP: z.stringbool().catch(false),
RESEND_API_KEY: z.string(),
CRON_SECRET: z.string(),
- UNKEY_TOKEN: z.string(),
- UNKEY_API_ID: z.string(),
+ UNKEY_TOKEN: isSelfHost ? z.string().optional() : z.string(),
+ UNKEY_API_ID: isSelfHost ? z.string().optional() : z.string(),
SLACK_FEEDBACK_WEBHOOK_URL: z.string().optional(),
EXTERNAL_REPORT_SALT: z.string().optional(),
SELF_HOST: z.stringbool().prefault("false"),
diff --git a/packages/api/src/tb.ts b/packages/api/src/tb.ts
index 1d638191d..fdbb6e80c 100644
--- a/packages/api/src/tb.ts
+++ b/packages/api/src/tb.ts
@@ -3,7 +3,7 @@ import { OSTinybird } from "@openstatus/tinybird";
import { env } from "./env";
export const tb = new OSTinybird({
- token: env.TINY_BIRD_API_KEY,
+ token: env.TINY_BIRD_API_KEY ?? "",
baseUrl: env.TINYBIRD_URL,
noop: env.TINYBIRD_NOOP,
});