Skip to content

Commit c272b5b

Browse files
committed
Make S2 env vars optional
1 parent f54ec87 commit c272b5b

File tree

3 files changed

+61
-32
lines changed

3 files changed

+61
-32
lines changed

apps/webapp/app/env.server.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ const GithubAppEnvSchema = z.preprocess(
2525
])
2626
);
2727

28+
// eventually we can make all S2 env vars required once the S2 OSS version is out
29+
const S2EnvSchema = z.preprocess(
30+
(val) => {
31+
const obj = val as any;
32+
if (!obj || !obj.S2_ENABLED) {
33+
return { ...obj, S2_ENABLED: "0" };
34+
}
35+
return obj;
36+
},
37+
z.discriminatedUnion("S2_ENABLED", [
38+
z.object({
39+
S2_ENABLED: z.literal("1"),
40+
S2_ACCESS_TOKEN: z.string(),
41+
S2_DEPLOYMENT_LOGS_BASIN_NAME: z.string(),
42+
}),
43+
z.object({
44+
S2_ENABLED: z.literal("0"),
45+
}),
46+
])
47+
);
48+
2849
const EnvironmentSchema = z
2950
.object({
3051
NODE_ENV: z.union([z.literal("development"), z.literal("production"), z.literal("test")]),
@@ -1201,11 +1222,9 @@ const EnvironmentSchema = z
12011222
EVENT_LOOP_MONITOR_UTILIZATION_SAMPLE_RATE: z.coerce.number().default(0.05),
12021223

12031224
VERY_SLOW_QUERY_THRESHOLD_MS: z.coerce.number().int().optional(),
1204-
1205-
S2_ACCESS_TOKEN: z.string(),
1206-
S2_DEPLOYMENT_LOGS_BASIN_NAME: z.string(),
12071225
})
1208-
.and(GithubAppEnvSchema);
1226+
.and(GithubAppEnvSchema)
1227+
.and(S2EnvSchema);
12091228

12101229
export type Environment = z.infer<typeof EnvironmentSchema>;
12111230
export const env = EnvironmentSchema.parse(process.env);

apps/webapp/app/presenters/v3/DeploymentPresenter.server.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,32 @@ export class DeploymentPresenter {
145145
? ExternalBuildData.safeParse(deployment.externalBuildData)
146146
: undefined;
147147

148-
const s2 = new S2({ accessToken: env.S2_ACCESS_TOKEN });
149-
const projectS2AccessToken = await s2.accessTokens.issue({
150-
id: `${project.externalRef}-${new Date().getTime()}`,
151-
expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(), // 1 hour
152-
scope: {
153-
ops: ["read"],
154-
basins: {
155-
exact: env.S2_DEPLOYMENT_LOGS_BASIN_NAME,
156-
},
157-
streams: {
158-
prefix: `projects/${project.externalRef}/deployments/`,
148+
let s2Logs = undefined;
149+
if (env.S2_ENABLED === "1") {
150+
const s2 = new S2({ accessToken: env.S2_ACCESS_TOKEN });
151+
const projectS2AccessToken = await s2.accessTokens.issue({
152+
id: `${project.externalRef}-${new Date().getTime()}`,
153+
expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(), // 1 hour
154+
scope: {
155+
ops: ["read"],
156+
basins: {
157+
exact: env.S2_DEPLOYMENT_LOGS_BASIN_NAME,
158+
},
159+
streams: {
160+
prefix: `projects/${project.externalRef}/deployments/`,
161+
},
159162
},
160-
},
161-
});
163+
});
162164

163-
return {
164-
s2Logs: {
165+
s2Logs = {
165166
basin: env.S2_DEPLOYMENT_LOGS_BASIN_NAME,
166167
stream: `projects/${project.externalRef}/deployments/${deployment.shortCode}`,
167168
accessToken: projectS2AccessToken.access_token,
168-
},
169+
};
170+
}
171+
172+
return {
173+
s2Logs,
169174
deployment: {
170175
id: deployment.id,
171176
shortCode: deployment.shortCode,

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.deployments.$deploymentParam/route.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ export default function Page() {
8080
const location = useLocation();
8181
const page = new URLSearchParams(location.search).get("page");
8282

83+
const logsDisabled = s2Logs === undefined;
8384
const [logs, setLogs] = useState<LogEntry[]>([]);
8485
const [isStreaming, setIsStreaming] = useState(true);
8586
const [streamError, setStreamError] = useState<string | null>(null);
8687

8788
useEffect(() => {
89+
if (logsDisabled) return;
90+
8891
const abortController = new AbortController();
8992

9093
setLogs([]);
@@ -150,7 +153,7 @@ export default function Page() {
150153
return () => {
151154
abortController.abort();
152155
};
153-
}, [s2Logs.basin, s2Logs.stream]);
156+
}, [s2Logs?.basin, s2Logs?.stream]);
154157

155158
return (
156159
<div className="grid h-full max-h-full grid-rows-[2.5rem_1fr] overflow-hidden bg-background-bright">
@@ -243,17 +246,19 @@ export default function Page() {
243246
/>
244247
</Property.Value>
245248
</Property.Item>
246-
<Property.Item>
247-
<Property.Label>Logs</Property.Label>
248-
<LogsDisplay
249-
logs={logs}
250-
isStreaming={isStreaming}
251-
streamError={streamError}
252-
initialCollapsed={(
253-
["PENDING", "DEPLOYED", "TIMED_OUT"] satisfies (typeof deployment.status)[]
254-
).includes(deployment.status)}
255-
/>
256-
</Property.Item>
249+
{!logsDisabled && (
250+
<Property.Item>
251+
<Property.Label>Logs</Property.Label>
252+
<LogsDisplay
253+
logs={logs}
254+
isStreaming={isStreaming}
255+
streamError={streamError}
256+
initialCollapsed={(
257+
["PENDING", "DEPLOYED", "TIMED_OUT"] satisfies (typeof deployment.status)[]
258+
).includes(deployment.status)}
259+
/>
260+
</Property.Item>
261+
)}
257262
{deployment.canceledAt && (
258263
<Property.Item>
259264
<Property.Label>Canceled at</Property.Label>

0 commit comments

Comments
 (0)