From 10b62b064a7eb1b5215209dec263ad7869b52d7f Mon Sep 17 00:00:00 2001 From: Abdou TOP Date: Wed, 10 Jun 2026 16:37:18 +0000 Subject: [PATCH 1/2] fix: resolve Deno task interception, experimental imports, and socket permissions --- .github/workflows/ga-build-image.yml | 24 +++++++++++++ Dockerfile.dev | 52 ++++++++++++++++++++++++++++ api/clickhouse-client.ts | 19 +++++----- api/lib/clickhouse-local.ts | 4 +-- api/lib/local_ipc.ts | 9 +++++ api/lib/logger.ts | 4 +-- deno.json | 3 +- deno.lock | 9 ++--- 8 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 Dockerfile.dev diff --git a/.github/workflows/ga-build-image.yml b/.github/workflows/ga-build-image.yml index dcf19aa..68bcf5a 100644 --- a/.github/workflows/ga-build-image.yml +++ b/.github/workflows/ga-build-image.yml @@ -45,3 +45,27 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + + - name: 🏷️ Extract metadata (dev) + id: meta-dev + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + flavor: | + suffix=-dev + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: 🏗️ Build and push Docker image (dev) + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.dev + push: true + tags: ${{ steps.meta-dev.outputs.tags }} + labels: ${{ steps.meta-dev.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..7c71ebc --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,52 @@ +FROM denoland/deno:latest AS builder +WORKDIR /app + +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + build-essential \ + python3 \ + npm && \ + rm -rf /var/lib/apt/lists/* + +COPY ./deno.json /app/deno.json +COPY ./deno.lock /app/deno.lock + +RUN deno install +RUN deno task setup:chdb + +RUN mkdir -p /app/prod_deps/node_modules/.deno/chdb@2.0.1/node_modules && \ + cp -r /app/node_modules/.deno/chdb@2.0.1/node_modules/chdb /app/prod_deps/node_modules/.deno/chdb@2.0.1/node_modules/chdb && \ + ln -s .deno/chdb@2.0.1/node_modules/chdb /app/prod_deps/node_modules/chdb + +COPY ./tasks/vite.ts /app/tasks/vite.ts +COPY ./web /app/web +RUN deno cache --allow-scripts=npm:esbuild@0.28.0 --lock=deno.lock tasks/vite.ts web/index.tsx +ENV BASE_URL="/" +RUN deno task prod:vite + +COPY ./api /app/api +COPY ./db /app/db +RUN deno cache --allow-scripts=npm:esbuild@0.28.0 --lock=deno.lock api/server.ts +RUN deno task prod:api + + +FROM ubuntu:24.04 +WORKDIR /app + +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=builder /app/dist/api /app/server +COPY --from=builder /app/db/functions /app/db/functions +COPY --from=builder /app/prod_deps/ /app/ + +ENV LOCAL_ENV=true +ENV BASE_URL=/ +ENV PORT=3021 +ENV GEMINI_API_KEY=something +ENV APP_ENV=prod + +EXPOSE 3021 + +CMD ["/app/server", "--env=prod"] \ No newline at end of file diff --git a/api/clickhouse-client.ts b/api/clickhouse-client.ts index a0e1f55..3eaf7c9 100644 --- a/api/clickhouse-client.ts +++ b/api/clickhouse-client.ts @@ -1,5 +1,5 @@ -import defer * as chclient from '@clickhouse/client' -import defer * as local from './lib/clickhouse-local.ts' +import { createClient } from '@clickhouse/client' +import { createLocalClient } from './lib/clickhouse-local.ts' import { isLocal } from './lib/env.ts' import { @@ -52,11 +52,11 @@ export const LogsInputSchema = UNION( type Log = Asserted type LogsInput = Asserted -export const client: ReturnType = isLocal - ? local.createLocalClient(CLICKHOUSE_HOST) as unknown as ReturnType< - typeof chclient.createClient +export const client: ReturnType = isLocal + ? createLocalClient(CLICKHOUSE_HOST) as unknown as ReturnType< + typeof createClient > - : chclient.createClient({ + : createClient({ url: CLICKHOUSE_HOST, username: CLICKHOUSE_USER, password: CLICKHOUSE_PASSWORD, @@ -93,11 +93,10 @@ export async function insertLogs(service_name: string, data: LogsInput) { const rows = logsToInsert.map((log) => { const traceHex = numberToHex128(log.trace_id) const spanHex = numberToHex128(log.span_id ?? log.trace_id) - const attributes = - log.attributes && typeof log.attributes === 'object' && + const attributes = log.attributes && typeof log.attributes === 'object' && !Array.isArray(log.attributes) - ? log.attributes - : {} + ? log.attributes + : {} const row: Record = { timestamp: new Date(log.timestamp), diff --git a/api/lib/clickhouse-local.ts b/api/lib/clickhouse-local.ts index 988a4f5..af1bfdd 100644 --- a/api/lib/clickhouse-local.ts +++ b/api/lib/clickhouse-local.ts @@ -1,7 +1,7 @@ -import defer * as chdb from 'chdb' +import { Session } from 'chdb' export function createLocalClient(path: string) { - const session = new chdb.Session(path) + const session = new Session(path) session.query(`SET date_time_input_format = 'best_effort'`) return { diff --git a/api/lib/local_ipc.ts b/api/lib/local_ipc.ts index 81ba773..a456393 100644 --- a/api/lib/local_ipc.ts +++ b/api/lib/local_ipc.ts @@ -146,6 +146,15 @@ export async function startRegistryServer(socketPath = defaultSocketPath) { } await removeSocket(socketPath) const listener = Deno.listen({ transport: 'unix', path: socketPath }) + + if (Deno.build.os !== 'windows') { + try { + await Deno.chmod(socketPath, 0o666) + } catch (error) { + console.error('Failed to set socket permissions:', error) + } + } + void acceptLoop(listener) return { close: () => { diff --git a/api/lib/logger.ts b/api/lib/logger.ts index 88ae5a8..cf54458 100644 --- a/api/lib/logger.ts +++ b/api/lib/logger.ts @@ -33,9 +33,7 @@ export function createLogger(serviceName: string): Log { ) => { const ctx = getContext() const attributes = - props && typeof props === 'object' && !Array.isArray(props) - ? props - : {} + props && typeof props === 'object' && !Array.isArray(props) ? props : {} batch.push({ timestamp: Date.now(), diff --git a/deno.json b/deno.json index e267719..ffc89a6 100644 --- a/deno.json +++ b/deno.json @@ -25,8 +25,7 @@ "prod:vite": "BASE_URL=/ APP_ENV=prod deno run -A tasks/vite.ts", "review": "deno run -A https://gistcdn.githack.com/kigiri/7658b4af30bb5eaca3e4cad1fcac7b0c/raw/review.js", "seed": "deno run -A --env-file=.env.dev tasks/seed.ts", - "setup": "deno install && deno task setup:chdb", - "setup:chdb": "cd node_modules/chdb && bash update_libchdb.sh && npm run build", + "setup:chdb": "cd node_modules/chdb && bash update_libchdb.sh && npx node-gyp configure build --verbose && bash fix_loader_path.sh", "test": "deno test --env-file=.env.test -A --unstable-worker-options --no-check" }, "imports": { diff --git a/deno.lock b/deno.lock index cd1bfe1..79b4376 100644 --- a/deno.lock +++ b/deno.lock @@ -3,7 +3,7 @@ "specifiers": { "jsr:@01edu/api-client@~0.2.6": "0.2.6", "jsr:@01edu/api-proxy@~0.2.1": "0.2.1", - "jsr:@01edu/api@~0.2.7": "0.2.7", + "jsr:@01edu/api@~0.2.7": "0.2.8", "jsr:@01edu/time@0.1": "0.1.0", "jsr:@01edu/types@~0.2.6": "0.2.6", "jsr:@cd/sqlite@~0.13.1": "0.13.1", @@ -60,13 +60,14 @@ "npm:vite@^8.0.3": "8.0.16" }, "jsr": { - "@01edu/api@0.2.7": { - "integrity": "17198ab087829f38dafc17e08cd7fd72ce04118a0058019d6af055f5ab3ea244", + "@01edu/api@0.2.8": { + "integrity": "b49fa2db91cef165d0bf819efdc72c690332ec4bd73403ce6db96c8a016ab7d2", "dependencies": [ "jsr:@01edu/time", "jsr:@01edu/types", "jsr:@std/fmt@^1.0.9", - "jsr:@std/http@^1.0.25" + "jsr:@std/http@^1.0.25", + "jsr:@std/streams" ] }, "@01edu/api-client@0.2.6": { From b34381a8dc0da0dd5556a68f6854266a64dead95 Mon Sep 17 00:00:00 2001 From: Abdou TOP Date: Wed, 10 Jun 2026 16:49:56 +0000 Subject: [PATCH 2/2] fix: add setup task for database configuration in CI workflow --- Dockerfile.dev | 1 - api/clickhouse-client.ts | 2 +- api/lib/clickhouse-local.ts | 6 ++---- api/lib/env.ts | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 7c71ebc..5984dec 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -44,7 +44,6 @@ COPY --from=builder /app/prod_deps/ /app/ ENV LOCAL_ENV=true ENV BASE_URL=/ ENV PORT=3021 -ENV GEMINI_API_KEY=something ENV APP_ENV=prod EXPOSE 3021 diff --git a/api/clickhouse-client.ts b/api/clickhouse-client.ts index 3eaf7c9..82c11bd 100644 --- a/api/clickhouse-client.ts +++ b/api/clickhouse-client.ts @@ -53,7 +53,7 @@ type Log = Asserted type LogsInput = Asserted export const client: ReturnType = isLocal - ? createLocalClient(CLICKHOUSE_HOST) as unknown as ReturnType< + ? (await createLocalClient(CLICKHOUSE_HOST)) as unknown as ReturnType< typeof createClient > : createClient({ diff --git a/api/lib/clickhouse-local.ts b/api/lib/clickhouse-local.ts index af1bfdd..9b033e6 100644 --- a/api/lib/clickhouse-local.ts +++ b/api/lib/clickhouse-local.ts @@ -1,7 +1,5 @@ -import { Session } from 'chdb' - -export function createLocalClient(path: string) { - const session = new Session(path) +export async function createLocalClient(path: string) { + const session = new (await import('chdb')).Session(path) session.query(`SET date_time_input_format = 'best_effort'`) return { diff --git a/api/lib/env.ts b/api/lib/env.ts index 196260a..a9ce9b9 100644 --- a/api/lib/env.ts +++ b/api/lib/env.ts @@ -28,7 +28,7 @@ const LOCAL_ENV = ENV('LOCAL_ENV', '') export const isLocal = LOCAL_ENV === 'yes' || LOCAL_ENV === '1' || LOCAL_ENV === 'true' -export const GEMINI_API_KEY = ENV('GEMINI_API_KEY') +export const GEMINI_API_KEY = ENV('GEMINI_API_KEY', '') export const GEMINI_MODEL = ENV( 'GEMINI_MODEL',