Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/services-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
BRANCH: ${{ github.ref_name }}
COMMIT_SHA: ${{ github.sha }}
run: |
TARGETS="console rotor"
TARGETS="console rotor functions-server"
REGISTRY="${{ secrets.DOCKERHUB_USERNAME }}"
SHORT_SHA=$(git rev-parse --short=7 HEAD)

Expand Down
46 changes: 46 additions & 0 deletions all.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,49 @@ ENV JITSU_VERSION_STRING=${JITSU_BUILD_VERSION}


ENTRYPOINT ["/app/entrypoint.sh"]

# ============================================================================
# FUNCTIONS-SERVER STAGE - Deno-based UDF execution with Web Worker isolation
# ============================================================================
# Sandboxed functions execution for free-tier workspaces
FROM denoland/deno:debian AS functions-server

ARG JITSU_BUILD_VERSION=dev,
ARG JITSU_BUILD_DOCKER_TAG=dev,
ARG JITSU_BUILD_COMMIT_SHA=unknown,

WORKDIR /app

# Install curl for healthchecks
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*

EXPOSE 3401

# Copy Deno-specific build artifacts from builder
COPY --from=builder /app/services/rotor/dist/functions-server.mjs ./functions-server.mjs
COPY --from=builder /app/services/rotor/dist/workspace-worker.mjs ./workspace-worker.mjs
# Copy node_modules with native deps (installed by build.mts)
# Workspace packages and pure JS deps are bundled into functions-server.mjs by esbuild
COPY --from=builder /app/services/rotor/dist/node_modules ./node_modules
COPY --from=builder /app/services/rotor/dist/package.json ./package.json

ENV JITSU_VERSION_COMMIT_SHA=${JITSU_BUILD_COMMIT_SHA}
ENV JITSU_VERSION_DOCKER_TAG=${JITSU_BUILD_DOCKER_TAG}
ENV JITSU_VERSION_STRING=${JITSU_BUILD_VERSION}
ENV NODE_ENV=production

HEALTHCHECK CMD curl --fail http://localhost:3401/health || exit 1

ENTRYPOINT ["deno", "run", \
"--allow-net", \
"--allow-read", \
"--allow-write=/tmp/jitsu-udf,/data", \
"--allow-env", \
"--allow-sys", \
"--allow-ffi", \
"--allow-run=/app/node_modules/@esbuild/linux-arm64/bin/esbuild,/app/node_modules/@esbuild/linux-x64/bin/esbuild,/app/node_modules/esbuild/bin/esbuild", \
"--unstable-worker-options", \
"--no-check", \
"functions-server.mjs"]
19 changes: 19 additions & 0 deletions build-fs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

DATE_TAG=$(date +"%Y%m%d%H%M")
IMAGE="jitsucom/fs:dev-${DATE_TAG}"

echo "Building rotor image..."
docker buildx build \
--target functions-server \
--progress=plain \
--load \
-t "$IMAGE" \
-f all.Dockerfile \
.

echo "Loading image into minikube..."
minikube image load --overwrite=true "$IMAGE"

echo "Done: $IMAGE"
9 changes: 7 additions & 2 deletions builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ FROM node:24-bookworm-slim
# Install Node.js 24 manually from NodeSource + all runtime dependencies
# This includes everything needed for building AND running the final images
RUN apt-get update && \
apt-get install -y ca-certificates gnupg git curl telnet python3 g++ make jq nano cron bash netcat-traditional procps && \
apt-get install -y ca-certificates gnupg git curl telnet python3 g++ make jq nano cron bash netcat-traditional procps unzip && \
rm -rf /var/lib/apt/lists/* && \
npm -g install pnpm@10 && \
npm cache clean --force
npm cache clean --force && \
ARCH=$(uname -m) && \
curl -fsSL "https://github.com/denoland/deno/releases/latest/download/deno-${ARCH}-unknown-linux-gnu.zip" -o /tmp/deno.zip && \
unzip -o /tmp/deno.zip -d /usr/local/bin && \
chmod +x /usr/local/bin/deno && \
rm /tmp/deno.zip

#print current user
RUN whoami && echo "Current user is $(whoami)"
Expand Down
7 changes: 5 additions & 2 deletions bulker/jitsubase/appbase/abstract_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ func (r *AbstractRepository[T]) start() {
}
}
} else {
// No refresh period configured — poll with a minimum interval to avoid busy-looping
ticker := time.NewTicker(1 * time.Second)
for {
select {
case <-ticker.C:
r.refresh(true)
case <-r.closed:
ticker.Stop()
return
default:
r.refresh(true)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions bulker/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (o *Operator) reconcile() {
continue
}

wsWorkspaceData := CalculateWorkspaceData(ws.ID, connections, functions, true)
wsWorkspaceData := CalculateWorkspaceData(ws.ID, connections, functions)

if slices.Contains(functionsClasses, FunctionsClassPremium) || slices.Contains(functionsClasses, FunctionsClassDedicated) {
wData := *wsWorkspaceData // Copy
Expand Down Expand Up @@ -1102,7 +1102,8 @@ func (o *Operator) buildDeploymentFromData(data *DeploymentData) *appsv1.Deploym

var resources corev1.ResourceRequirements
resourcesConfig := o.config.PodsResources
if data.FunctionsClass == FunctionsClassPremium && o.config.PodsResourcesPremium != "" {
// free deployment use premium resource because it serve multiple workspaces at once
if (data.FunctionsClass == FunctionsClassPremium || data.FunctionsClass == FunctionsClassFree) && o.config.PodsResourcesPremium != "" {
resourcesConfig = o.config.PodsResourcesPremium
}
if resourcesConfig != "" {
Expand Down
2 changes: 0 additions & 2 deletions bulker/operator/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func CalculateWorkspaceData(
workspaceID string,
connections []*EnrichedConnectionConfig,
functions []*FunctionConfig,
hasDedicatedFS bool,
) *WorkspaceData {
var maxUpdatedAt time.Time
var usesWarehouseAPI bool
Expand Down Expand Up @@ -249,7 +248,6 @@ func CalculateWorkspaceData(
Connections: filteredConnections,
Functions: functions,
UsesWarehouseAPI: usesWarehouseAPI,
HasDedicatedFS: hasDedicatedFS,
ConfigHash: configHash,
}
}
Expand Down
1 change: 0 additions & 1 deletion bulker/operator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type WorkspaceData struct {
Connections []*EnrichedConnectionConfig
Functions []*FunctionConfig
UsesWarehouseAPI bool
HasDedicatedFS bool
FunctionsClass string // premium, dedicated, free
ConfigHash string // Hash of connections + functions for change detection
FunctionsConfigMapCount int // Number of functions ConfigMaps (for splitting large data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type DataLayoutImpl<T> = (
) => MappedEvent[] | MappedEvent;

export function jitsuLegacy(event: AnalyticsServerEvent, ctx: FullContext<BulkerDestinationConfig>): MappedEvent {
const flat = toJitsuClassic(event, ctx);
const flat = toJitsuClassic(event, ctx, true);
return { event: omit(flat, JitsuInternalProperties), table: event[TableNameParameter] ?? "events" };
}

Expand Down
55 changes: 36 additions & 19 deletions libs/functions/__tests__/classic-mapping.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AnalyticsServerEvent } from "@jitsu/protocols/analytics";
import type { Event as JitsuLegacyEvent } from "@jitsu/sdk-js";
import { FullContext, UserAgent } from "@jitsu/protocols/functions";
import { fromJitsuClassic, removeUndefined, TableNameParameter, toJitsuClassic, toSnakeCase } from "../src";
import { FullContext } from "@jitsu/protocols/functions";
import { fromJitsuClassic, toJitsuClassic } from "../src";
import { classicEvents } from "./data/classic-events";

const identify: AnalyticsServerEvent = {
Expand Down Expand Up @@ -264,14 +264,22 @@ const legacyPageExpectedWarehouse = {
};

test("legacy event s3", () => {
const identifyLegacyResult = toJitsuClassic(identify, {
props: { keepOriginalNames: true },
destination: { type: "s3" },
} as unknown as FullContext);
const pageLegacyResult = toJitsuClassic(page, {
props: { keepOriginalNames: true },
destination: { type: "s3" },
} as unknown as FullContext);
const identifyLegacyResult = toJitsuClassic(
identify,
{
props: { keepOriginalNames: true },
destination: { type: "s3" },
} as unknown as FullContext,
true
);
const pageLegacyResult = toJitsuClassic(
page,
{
props: { keepOriginalNames: true },
destination: { type: "s3" },
} as unknown as FullContext,
true
);
console.log(JSON.stringify(identifyLegacyResult, null, 2));
expect(identifyLegacyResult).toStrictEqual(legacyIdentifyExpectedS3);

Expand All @@ -280,14 +288,22 @@ test("legacy event s3", () => {
});

test("legacy event warehouse", () => {
const identifyLegacyResult = toJitsuClassic(identify, {
props: { keepOriginalNames: true },
destination: { type: "postgres" },
} as unknown as FullContext);
const pageLegacyResult = toJitsuClassic(page, {
props: { keepOriginalNames: true },
destination: { type: "postgres" },
} as unknown as FullContext);
const identifyLegacyResult = toJitsuClassic(
identify,
{
props: { keepOriginalNames: true },
destination: { type: "postgres" },
} as unknown as FullContext,
true
);
const pageLegacyResult = toJitsuClassic(
page,
{
props: { keepOriginalNames: true },
destination: { type: "postgres" },
} as unknown as FullContext,
true
);
console.log(JSON.stringify(identifyLegacyResult, null, 2));
expect(identifyLegacyResult).toStrictEqual(legacyIdentifyExpectedWarehouse);

Expand All @@ -307,7 +323,8 @@ test("classic events mapping", () => {
const restored = fromJitsuClassic(event);
const mapped = toJitsuClassic(
restored as AnalyticsServerEvent,
{ props: { keepOriginalNames: true }, destination: { type: "s3" } } as unknown as FullContext
{ props: { keepOriginalNames: true }, destination: { type: "s3" } } as unknown as FullContext,
true
);
delete mapped.anon_ip;
expect(mapped).toStrictEqual(event);
Expand Down
21 changes: 12 additions & 9 deletions libs/functions/src/lib/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ function anonymizeIp(ip: string | undefined) {
}
}

export function toJitsuClassic(event: AnalyticsServerEvent, ctx: FullContext): AnyEvent {
const keepOriginalNames = !!ctx.props.keepOriginalNames;
const fileStorage = ctx.destination.type === "s3" || ctx.destination.type === "gcs";
let transferFunc = transferAsSnakeCase;
if (keepOriginalNames) {
if (fileStorage) {
transferFunc = transfer;
} else {
transferFunc = transferAsClassic;
export function toJitsuClassic(event: AnalyticsServerEvent, ctx: FullContext, bulker: boolean = false): AnyEvent {
let transferFunc = transfer;
if (bulker) {
const keepOriginalNames = !!ctx?.props?.keepOriginalNames;
const fileStorage = ctx?.destination?.type === "s3" || ctx?.destination?.type === "gcs";
transferFunc = transferAsSnakeCase;
if (keepOriginalNames) {
if (fileStorage) {
transferFunc = transfer;
} else {
transferFunc = transferAsClassic;
}
}
}
let url: URL | undefined = undefined;
Expand Down
2 changes: 1 addition & 1 deletion libs/jitsu-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@jitsu/common-config": "workspace:*",
"tslib": "catalog:",
"@playwright/test": "^1.57.0",
"@playwright/test": "1.58.2",
"esbuild": "catalog:",
"tsx": "catalog:",
"@segment/analytics-next": "^1.75.0",
Expand Down
4 changes: 3 additions & 1 deletion libs/jitsu-js/src/analytics-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ export function ensureAnonymousId(opts: JitsuOptions): string | undefined {
secure: window.location.protocol === "https:",
});
if (opts.debug) {
console.log(`[JITSU DEBUG] preInitAnonymousId: created anonymous ID cookie '${cookieName}'=${id} on domain '${domain}'`);
console.log(
`[JITSU DEBUG] preInitAnonymousId: created anonymous ID cookie '${cookieName}'=${id} on domain '${domain}'`
);
}
return id;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"release:canary": "monorel --filter ./types/protocols --filter ./cli/jitsu-cli --filter ./libs/functions --filter ./libs/jitsu-js --filter ./libs/jitsu-react --version '1.10.5-canary.{rev}.{time}' --npm-tag canary --git-tag 'jitsu-js-libs-canary-v{version}' --push-tag"
},
"devDependencies": {
"@playwright/test": "1.57.0",
"@playwright/test": "1.58.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
Expand Down
Loading
Loading