From f2c300519d0382ae69dc80f24d1882f2e4346b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Mon, 20 May 2024 18:13:59 -0300 Subject: [PATCH 1/7] test: capture tbwaiter errors on production --- apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts index d559b80..8fddfe1 100644 --- a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts +++ b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts @@ -20,9 +20,11 @@ export const tbConsumerRouter = createTRPCRouter({ ) .query(async ({ input }) => { const url = `${env.TENSORBOARD_API_URL}/api/tensorboard/start`; + console.log(url); const res = await fetch(url, { method: 'POST', + mode: 'cors', headers: { 'Content-Type': 'application/json', 'X-API-KEY': env.TENSORBOARD_API_KEY, @@ -30,7 +32,10 @@ export const tbConsumerRouter = createTRPCRouter({ body: JSON.stringify(input), }); + console.log(res); + const data: unknown = await res.json(); + console.log(data); if (!res.ok) { const error = z From 0c7e6405cec305f8205ec4de2f909c7bb822719a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Mon, 20 May 2024 18:31:32 -0300 Subject: [PATCH 2/7] test: try to catch consumer fetch error --- .../src/server/api/routers/tb_consumer.ts | 60 +++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts index 8fddfe1..6d33659 100644 --- a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts +++ b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts @@ -20,39 +20,37 @@ export const tbConsumerRouter = createTRPCRouter({ ) .query(async ({ input }) => { const url = `${env.TENSORBOARD_API_URL}/api/tensorboard/start`; - console.log(url); - const res = await fetch(url, { - method: 'POST', - mode: 'cors', - headers: { - 'Content-Type': 'application/json', - 'X-API-KEY': env.TENSORBOARD_API_KEY, - }, - body: JSON.stringify(input), - }); - - console.log(res); - - const data: unknown = await res.json(); - console.log(data); - - if (!res.ok) { - const error = z - .object({ - status: z.string(), - message: z.string(), - }) - .parse(data); - - throw new TRPCError({ - code: 'INTERNAL_SERVER_ERROR', - message: error.message, + try { + const res = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-KEY': env.TENSORBOARD_API_KEY, + }, + body: JSON.stringify(input), }); - } - - const parsed = TensorboardResponseSchema.parse(data); - return parsed; + const data: unknown = await res.json(); + + if (!res.ok) { + const error = z + .object({ + status: z.string(), + message: z.string(), + }) + .parse(data); + + throw new TRPCError({ + code: 'INTERNAL_SERVER_ERROR', + message: error.message, + }); + } + const parsed = TensorboardResponseSchema.parse(data); + + return parsed; + } catch (e) { + console.log(e); + } }), }); From b1a9751516d90f5327f6755f7f20d47c09e04181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Mon, 20 May 2024 18:37:25 -0300 Subject: [PATCH 3/7] fix build --- apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts index 6d33659..fad9311 100644 --- a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts +++ b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts @@ -52,5 +52,11 @@ export const tbConsumerRouter = createTRPCRouter({ } catch (e) { console.log(e); } + return { + logdir: '', + name: '', + url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', + pid: 0, + }; }), }); From 15ec77b109d3587f898bac8f8d02ff9c56704e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Mon, 20 May 2024 19:06:32 -0300 Subject: [PATCH 4/7] test: try to disable next cache on tb request --- .../src/server/api/routers/tb_consumer.ts | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts index fad9311..337fc41 100644 --- a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts +++ b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts @@ -21,42 +21,34 @@ export const tbConsumerRouter = createTRPCRouter({ .query(async ({ input }) => { const url = `${env.TENSORBOARD_API_URL}/api/tensorboard/start`; - try { - const res = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-API-KEY': env.TENSORBOARD_API_KEY, - }, - body: JSON.stringify(input), - }); + const headers = new Headers(); + headers.append('Content-Type', 'application/json'); + headers.append('x-api-key', env.TENSORBOARD_API_KEY); + const options = { + method: 'POST', + headers, + body: JSON.stringify(input), + }; + + const res = await fetch(url, { ...options, cache: 'no-store' }); + + const data: unknown = await res.json(); - const data: unknown = await res.json(); - - if (!res.ok) { - const error = z - .object({ - status: z.string(), - message: z.string(), - }) - .parse(data); - - throw new TRPCError({ - code: 'INTERNAL_SERVER_ERROR', - message: error.message, - }); - } - const parsed = TensorboardResponseSchema.parse(data); - - return parsed; - } catch (e) { - console.log(e); + if (!res.ok) { + const error = z + .object({ + status: z.string(), + message: z.string(), + }) + .parse(data); + + throw new TRPCError({ + code: 'INTERNAL_SERVER_ERROR', + message: error.message, + }); } - return { - logdir: '', - name: '', - url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', - pid: 0, - }; + const parsed = TensorboardResponseSchema.parse(data); + + return parsed; }), }); From 49938313ccaa41a18f11cf8151d727098a619fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Tue, 21 May 2024 09:42:57 -0300 Subject: [PATCH 5/7] restore tbConsumer start query; add dummy page to test tb dummy query --- apps/deepsirius-ui/src/pages/hello.tsx | 15 +++++++++++ .../src/server/api/routers/tb_consumer.ts | 27 ++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 apps/deepsirius-ui/src/pages/hello.tsx diff --git a/apps/deepsirius-ui/src/pages/hello.tsx b/apps/deepsirius-ui/src/pages/hello.tsx new file mode 100644 index 0000000..1881ec7 --- /dev/null +++ b/apps/deepsirius-ui/src/pages/hello.tsx @@ -0,0 +1,15 @@ +import { api } from '~/utils/api'; + +export default function Page() { + const { data, isLoading } = api.tbConsumer.hello.useQuery(); + + if (isLoading) { + return
Loading...
; + } + + return ( +
+
{JSON.stringify(data, null, 2)}
+
+ ); +} diff --git a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts index 337fc41..a6dc80d 100644 --- a/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts +++ b/apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts @@ -20,17 +20,14 @@ export const tbConsumerRouter = createTRPCRouter({ ) .query(async ({ input }) => { const url = `${env.TENSORBOARD_API_URL}/api/tensorboard/start`; - - const headers = new Headers(); - headers.append('Content-Type', 'application/json'); - headers.append('x-api-key', env.TENSORBOARD_API_KEY); - const options = { + const res = await fetch(url, { method: 'POST', - headers, + headers: { + 'Content-Type': 'application/json', + 'x-api-key': env.TENSORBOARD_API_KEY, + }, body: JSON.stringify(input), - }; - - const res = await fetch(url, { ...options, cache: 'no-store' }); + }); const data: unknown = await res.json(); @@ -51,4 +48,16 @@ export const tbConsumerRouter = createTRPCRouter({ return parsed; }), + hello: protectedProcedure.query(async () => { + const url = `${env.TENSORBOARD_API_URL}/api/`; + const res = await fetch(url, { + method: 'GET', + headers: { + 'x-api-key': env.TENSORBOARD_API_KEY, + }, + }); + + const data: unknown = await res.json(); + return data; + }), }); From c8d46a271d3668a3fc2e39269dbbd5a04037d1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Tue, 21 May 2024 10:02:19 -0300 Subject: [PATCH 6/7] update docs dockerfile to stop using latest pnpm and breaking build, switch to corepack enable --- apps/docs/Dockerfile | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/docs/Dockerfile b/apps/docs/Dockerfile index 6a3a484..3b8f4db 100644 --- a/apps/docs/Dockerfile +++ b/apps/docs/Dockerfile @@ -1,34 +1,35 @@ -# Builder -FROM node:alpine AS builder -RUN apk add --no-cache libc6-compat -RUN apk update +FROM node:18-alpine AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable + +# ---- +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat WORKDIR /app -RUN yarn global add turbo +RUN pnpm add --global turbo COPY . . RUN turbo prune @deepsirius-ui/docs --docker # Installer -FROM node:alpine AS installer -RUN apk add --no-cache libc6-compat -RUN apk update - +FROM deps AS installer WORKDIR /app -RUN yarn global add pnpm -RUN yarn global add turbo COPY --from=builder /app/out/json/ . COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml RUN pnpm install -COPY --from=builder /app/out/full/ . +COPY --from=deps /app/out/full/ . COPY turbo.json turbo.json RUN turbo build --filter=@deepsirius-ui/docs... # Runner -FROM node:alpine AS runner +FROM base AS runner WORKDIR /app RUN addgroup --system --gid 1001 nodejs From d6aa14ac8a9816ad788e1f107281edf16fc6c4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Lu=C3=ADs?= Date: Tue, 21 May 2024 10:08:01 -0300 Subject: [PATCH 7/7] fix: typo in docs dockerfile --- apps/docs/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/docs/Dockerfile b/apps/docs/Dockerfile index 3b8f4db..6069124 100644 --- a/apps/docs/Dockerfile +++ b/apps/docs/Dockerfile @@ -18,9 +18,9 @@ RUN turbo prune @deepsirius-ui/docs --docker FROM deps AS installer WORKDIR /app -COPY --from=builder /app/out/json/ . -COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml -COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml +COPY --from=deps /app/out/json/ . +COPY --from=deps /app/out/pnpm-lock.yaml ./pnpm-lock.yaml +COPY --from=deps /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml RUN pnpm install COPY --from=deps /app/out/full/ .