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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
**/node_modules
**/dist
.git
docs/screenshots
.superpowers
.claude
**/.env*
**/*.local
62 changes: 19 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,29 @@ permissions:
contents: read

jobs:
# Typecheck ("lint"): the workspace has no ESLint — the static-analysis gate
# is the TypeScript compiler, run via each package's `build` (tsc -p ...).
# This also validates the vite builds for the apps.
typecheck:
name: Typecheck & build
# Typecheck, build and unit tests run through the shared node-ci workflow.
# The workspace has no ESLint or `typecheck` script: the static-analysis gate
# is the TypeScript compiler, run via each package's `build` (tsc -p ...), so
# the build step is the typecheck. It also validates the vite app bundles.
ci:
uses: xraph/workflows/.github/workflows/node-ci.yml@v1
with:
scripts: '["test","build"]'

# Container image: the entrypoint script tests need no docker, then the smoke
# script builds the image and runs it read-only beside an echo upstream.
image:
name: Container image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.12.0
- name: Entrypoint tests
run: sh deploy/docker/entrypoint_test.sh

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build (tsc typecheck + app bundles)
run: pnpm -r build

test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.12.0

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Test (vitest)
run: pnpm test
- name: Smoke test
run: sh deploy/docker/smoke.sh
191 changes: 137 additions & 54 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: Release

# Tag-triggered npm release for the @fabriq-ai/* packages.
# Tag-triggered release: the @fabriq-ai/* npm packages, and the console
# container image on ghcr.io (ghcr.io/xraph/fabriq-admin).
#
# Lockstep versioning: pushing a `vX.Y.Z` tag stamps EVERY publishable
# workspace package (packages/* + plugins/*) to that version and publishes
# them together to the public npm registry under the @fabriq-ai scope. The
# two apps (apps/host, apps/remote-example) are `private: true` and are
# skipped automatically by `pnpm -r publish`.
# Lockstep versioning: pushing a `vX.Y.Z` tag runs the shared CI workflow
# (test + build) on the tagged commit. Once it passes, every publishable
# workspace package (packages/* + plugins/*) is stamped to that version and
# published to the public npm registry under the @fabriq-ai scope, in
# dependency order, through xraph/workflows' npm-publish.yml. The two apps
# (apps/host, apps/remote-example) are `private: true` and are not in the
# `packages` list, so they are never published.
#
# git tag v0.2.0 && git push origin v0.2.0
#
Expand All @@ -15,9 +18,15 @@ name: Release
#
# Pre-release suffixes (v0.2.0-rc.1) publish under the `next` dist-tag instead
# of `latest`, so `npm install @fabriq-ai/ui` never resolves a pre-release.
# Every version is published with an npm provenance attestation. A re-run skips
# versions already on the registry, so a half-finished release can be resumed.
#
# The image is built for linux/amd64 and linux/arm64 and tagged :X.Y.Z, plus
# :X.Y for stable releases (no pre-release suffix). It runs independently of
# CI and the npm publish, so a failure in one does not block the other.
#
# Requires an NPM_TOKEN secret: an npm automation token with publish rights to
# the @fabriq-ai org.
# the @fabriq-ai org. The image push uses the workflow's own GITHUB_TOKEN.
on:
push:
tags:
Expand All @@ -32,67 +41,141 @@ permissions:
contents: read

jobs:
npm:
# Same gate as ci.yml, run on the tagged commit before anything is published.
ci:
uses: xraph/workflows/.github/workflows/node-ci.yml@v1
with:
scripts: '["test","build"]'

# The expression language has no string replace, and npm-publish.yml refuses
# a version with a leading v, so the tag is trimmed here. The dist-tag is
# picked here too: npm 11 won't publish a pre-release without one.
prepare:
name: Resolve version and dist-tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.resolve.outputs.version }}
dist-tag: ${{ steps.resolve.outputs.dist_tag }}
steps:
- id: resolve
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
echo "version=${version}" >> "$GITHUB_OUTPUT"

# A '-' before any '+build' metadata marks a pre-release in semver.
# Build metadata is cut first so 1.2.3+build-7 still counts as stable.
case "${version%%+*}" in
*-*) echo "dist_tag=next" >> "$GITHUB_OUTPUT" ;;
*) echo "dist_tag=latest" >> "$GITHUB_OUTPUT" ;;
esac
echo "Releasing ${version}"

publish:
name: Publish @fabriq-ai packages
needs: [ci, prepare]
# Provenance mints an OIDC token, and a called workflow only gets the
# permissions its caller grants, so id-token: write has to be granted here.
permissions:
contents: read
id-token: write
uses: xraph/workflows/.github/workflows/npm-publish.yml@v1
with:
package-manager: pnpm
# Every publishable package under packages/* and plugins/* (25), with
# dependencies first. Derived by topologically sorting each package.json's
# dependencies and peerDependencies on other @fabriq-ai packages: ui, then
# admin-sdk (which needs ui), then the plugins (which need both),
# alphabetically. Add a new package here, after anything it depends on.
packages: |-
[
"packages/ui",
"packages/admin-sdk",
"plugins/analytics",
"plugins/api-console",
"plugins/cache",
"plugins/commands",
"plugins/connection",
"plugins/crdt",
"plugins/distill",
"plugins/entity-browser",
"plugins/events",
"plugins/files",
"plugins/graph",
"plugins/live",
"plugins/migrations",
"plugins/overview",
"plugins/plugins-manager",
"plugins/projections",
"plugins/query",
"plugins/recall",
"plugins/search",
"plugins/spatial",
"plugins/telemetry",
"plugins/tenants",
"plugins/types"
]
version: ${{ needs.prepare.outputs.version }}
dist-tag: ${{ needs.prepare.outputs.dist-tag }}
# Each package.json has a repository field naming this repository.
provenance: true
dry-run: false
build-script: build
# Lets a re-run finish a release that died part way through the list.
skip-existing: true
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

image:
name: Publish container image
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # npm provenance (--provenance) attestation
packages: write # push to ghcr.io
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.12.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
cache: pnpm
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Resolve version + dist-tag from the tag
- name: Resolve image tags from the tag
id: ver
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# Anything with a pre-release suffix (contains a '-') ships as `next`.
if printf '%s' "$VERSION" | grep -q '-'; then
echo "dist_tag=next" >> "$GITHUB_OUTPUT"
else
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
fi
echo "Releasing ${VERSION}"

- name: Build
run: pnpm -r build

- name: Test
run: pnpm test
MAJOR_MINOR="$(printf '%s' "$VERSION" | cut -d. -f1,2)"
{
echo "version=${VERSION}"
echo "tags<<EOF"
echo "ghcr.io/xraph/fabriq-admin:${VERSION}"
# Pre-release suffixes (contains a '-') never move the :X.Y tag.
if ! printf '%s' "$VERSION" | grep -q '-'; then
echo "ghcr.io/xraph/fabriq-admin:${MAJOR_MINOR}"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"

- name: Stamp workspace versions to the tag (lockstep)
run: |
set -euo pipefail
# Bump every workspace package to the tag version. Private apps are
# bumped too but harmless — they are never published. workspace:*
# deps are rewritten to the concrete version by pnpm at publish time.
pnpm -r exec npm version "${{ steps.ver.outputs.version }}" \
--no-git-tag-version --allow-same-version
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
provenance: false
sbom: false
tags: ${{ steps.ver.outputs.tags }}

- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: "true"
run: |
set -euo pipefail
pnpm -r publish \
--access public \
--tag "${{ steps.ver.outputs.dist_tag }}" \
--no-git-checks
- name: Inspect the pushed image
run: docker buildx imagetools inspect "ghcr.io/xraph/fabriq-admin:${{ steps.ver.outputs.version }}"
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# syntax=docker/dockerfile:1

# The build stage always runs on the builder's own architecture. The output is
# static files, so both image platforms share one build.
FROM --platform=$BUILDPLATFORM node:20.18-alpine AS build
WORKDIR /src
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm -r build

FROM nginxinc/nginx-unprivileged:1.27-alpine
LABEL org.opencontainers.image.source=https://github.com/xraph/fabriq-admin

USER root
RUN apk add --no-cache jq
USER 101

COPY --from=build /src/apps/host/dist /usr/share/nginx/html
COPY deploy/docker/default.conf /etc/nginx/conf.d/default.conf
COPY --chmod=0755 deploy/docker/40-fabriq-admin-runtime.sh /docker-entrypoint.d/40-fabriq-admin-runtime.sh

# Only /tmp needs to be writable (run with --read-only --tmpfs /tmp).
EXPOSE 8080
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,42 @@ Then add its `remoteEntry.js` URL from the **Plugins** page to load it into the

---

## Run the container

Every release tag publishes an image to `ghcr.io/xraph/fabriq-admin` for `linux/amd64` and `linux/arm64`, tagged `X.Y.Z` and (for stable releases) `X.Y`. Point it at your Fabriq admin backend and open the port:

```bash
docker run --rm -p 8081:8080 \
--add-host=host.docker.internal:host-gateway \
-e FABRIQ_ADMIN_UPSTREAM=http://host.docker.internal:8080 \
ghcr.io/xraph/fabriq-admin:X.Y.Z
```

The `--add-host` line is for Linux engines, where `host.docker.internal` doesn't exist unless you add it. Docker Desktop already has it, and the flag does no harm there.

The console is now on http://localhost:8081. The browser talks to `/admin` on that same origin, and nginx forwards it to your backend, so there's no CORS to sort out.

Nothing is baked in at build time. The container reads its settings when it starts, writes the console's `config.js` into `/tmp`, and then hands over to nginx. Bad values stop it right there: the message goes to stderr and the exit code is 1.

The upstream hostname has to resolve when the container starts. If it doesn't, nginx fails and the container exits 1 before it serves anything. The address it finds is then pinned until the container restarts, so restart the console whenever the Fabriq server is recreated. In Compose that's `depends_on: {fabriq: {condition: service_started, restart: true}}` on the console service. On Kubernetes, point the upstream at a Service and not at a pod.

| Variable | Default | What it does |
|---|---|---|
| `FABRIQ_ADMIN_UPSTREAM` | unset | Origin of the admin backend, such as `http://fabriq:8081`, with no path. When set, `/admin/` is proxied there, with the browser's `Cookie` header dropped and no body size limit (file uploads are base64 JSON). |
| `FABRIQ_ADMIN_UPSTREAM_KEY` | unset | A Fabriq key (`fq_` plus 32 or more letters and digits). nginx sends it as `Authorization: Bearer` and replaces any header the browser sent. It never reaches `config.js`. While a key is set, requests the browser marks as cross-site or same-site get a 403. Needs `FABRIQ_ADMIN_UPSTREAM`. |
| `FABRIQ_ADMIN_BASE_PATH` | `/` | The path prefix the browser sees, such as `/console/`. Start and end with `/`. |
| `FABRIQ_ADMIN_API_URL` | `<base path>admin` when an upstream is set | Where the browser sends API calls. A path starting with `/`, or an `http://` or `https://` URL. |
| `FABRIQ_ADMIN_DEFAULT_TENANT` | unset | Tenant to select when the browser has none stored yet. Up to 64 letters, digits, `-` and `_`. |
| `FABRIQ_ADMIN_MAP_STYLE_URL` | unset | Style URL for the Spatial map. `http://` or `https://`. |

The container always serves from `/`. If you run it behind a proxy under a prefix, let the proxy strip the prefix before forwarding and set `FABRIQ_ADMIN_BASE_PATH` to the same prefix, so links and assets resolve in the browser.

It listens on 8080, runs as uid 101, and only needs `/tmp` to be writable, so `--read-only --tmpfs /tmp` works. `GET /healthz` returns `ok`.

To build it yourself, run `docker build -t fabriq-admin .` from the repo root. `sh deploy/docker/smoke.sh` builds the image and checks the whole contract against an echo server.

---

## Embedding in your app

```tsx
Expand Down
2 changes: 2 additions & 0 deletions apps/host/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fabriq Admin</title>
</head>
<body>
<div id="root"></div>
<script src="config.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions apps/host/public/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.__FABRIQ_ADMIN_CONFIG__ = window.__FABRIQ_ADMIN_CONFIG__ || {};
Loading
Loading