Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ga-build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
51 changes: 51 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 APP_ENV=prod

EXPOSE 3021

CMD ["/app/server", "--env=prod"]
19 changes: 9 additions & 10 deletions api/clickhouse-client.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -52,11 +52,11 @@ export const LogsInputSchema = UNION(
type Log = Asserted<typeof LogSchemaOutput>
type LogsInput = Asserted<typeof LogsInputSchema>

export const client: ReturnType<typeof chclient.createClient> = isLocal
? local.createLocalClient(CLICKHOUSE_HOST) as unknown as ReturnType<
typeof chclient.createClient
export const client: ReturnType<typeof createClient> = isLocal
? (await createLocalClient(CLICKHOUSE_HOST)) as unknown as ReturnType<
typeof createClient
>
: chclient.createClient({
: createClient({
url: CLICKHOUSE_HOST,
username: CLICKHOUSE_USER,
password: CLICKHOUSE_PASSWORD,
Expand Down Expand Up @@ -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<string, unknown> = {
timestamp: new Date(log.timestamp),
Expand Down
6 changes: 2 additions & 4 deletions api/lib/clickhouse-local.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import defer * as chdb from 'chdb'

export function createLocalClient(path: string) {
const session = new chdb.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 {
Expand Down
2 changes: 1 addition & 1 deletion api/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you handle to disable the generate with AI feature if no token is set ?


export const GEMINI_MODEL = ENV(
'GEMINI_MODEL',
Expand Down
9 changes: 9 additions & 0 deletions api/lib/local_ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down
4 changes: 1 addition & 3 deletions api/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 5 additions & 4 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading