Skip to content

Commit 2facec4

Browse files
authored
Prepare for on-demand cartridges. (#171)
On-demand cartridge fetching of boj-server-cartridges + bundle deletion prep. - release.yml / Containerfile: fetch cartridge tree from the canonical registry (scripts/fetch-cartridges.sh, landed in #169) instead of a bundled cartridges/ dir. - Elixir tests + test config: honour BOJ_CARTRIDGES_PATH override; widen the known auth-method allowlist.
1 parent b3970f2 commit 2facec4

9 files changed

Lines changed: 44 additions & 18 deletions

File tree

.github/workflows/release.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ jobs:
3030
with:
3131
version: 0.15.2
3232

33+
- name: Fetch cartridges
34+
# Cartridge source lives in the canonical registry, not this repo. Fetch
35+
# it into a flat <name>/ cache and point the build loops below at it.
36+
run: |
37+
BOJ_CARTRIDGES_PATH="$RUNNER_TEMP/cartridges" bash scripts/fetch-cartridges.sh
38+
echo "CARTS_ROOT=$RUNNER_TEMP/cartridges" >> "$GITHUB_ENV"
39+
3340
- name: Build core FFI libraries
3441
run: cd ffi/zig && zig build -Doptimize=ReleaseSafe
3542

3643
- name: Build cartridge shared libraries
3744
run: |
3845
for cart in database-mcp fleet-mcp nesy-mcp agent-mcp cloud-mcp container-mcp k8s-mcp git-mcp secrets-mcp queues-mcp iac-mcp observe-mcp ssg-mcp proof-mcp lsp-mcp dap-mcp bsp-mcp feedback-mcp; do
3946
echo "Building $cart .so..."
40-
cd "cartridges/$cart/ffi" && zig build -Doptimize=ReleaseSafe
47+
cd "$CARTS_ROOT/$cart/ffi" && zig build -Doptimize=ReleaseSafe
4148
cd "$GITHUB_WORKSPACE"
4249
done
4350
@@ -47,9 +54,9 @@ jobs:
4754
# Core static libraries and benchmark binary
4855
cp ffi/zig/zig-out/lib/*.a release-artifacts/core/
4956
cp ffi/zig/zig-out/bin/boj_bench release-artifacts/core/ 2>/dev/null || true
50-
# Cartridge shared libraries
57+
# Cartridge shared libraries (built from the fetched cache)
5158
for cart in database-mcp fleet-mcp nesy-mcp agent-mcp cloud-mcp container-mcp k8s-mcp git-mcp secrets-mcp queues-mcp iac-mcp observe-mcp ssg-mcp proof-mcp lsp-mcp dap-mcp bsp-mcp feedback-mcp; do
52-
cp "cartridges/$cart/ffi/zig-out/lib/"*.so "release-artifacts/cartridges/" 2>/dev/null || true
59+
cp "$CARTS_ROOT/$cart/ffi/zig-out/lib/"*.so "release-artifacts/cartridges/" 2>/dev/null || true
5360
done
5461
5562
- name: Create release tarball

container/Containerfile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@
1616
# Stage 1: Zig FFI Builder
1717
# ============================================================================
1818

19+
# Cartridge source is fetched on demand from the canonical registry rather than
20+
# bundled in this repo. Override the ref/repo at build time if needed:
21+
# podman build --build-arg BOJ_CARTRIDGES_REF=v1.2.3 ...
22+
ARG BOJ_CARTRIDGES_REF=main
23+
ARG BOJ_CARTRIDGES_REPO=https://github.com/hyperpolymath/boj-server-cartridges.git
24+
1925
FROM cgr.dev/chainguard/wolfi-base:latest AS zig-builder
2026

21-
RUN apk add --no-cache zig build-base
27+
RUN apk add --no-cache zig build-base git bash
2228

2329
WORKDIR /build
2430

25-
# Copy Zig source and cartridge FFI sources
31+
# Copy Zig source
2632
COPY ffi/zig/ ffi/zig/
27-
COPY cartridges/ cartridges/
33+
34+
# Fetch the cartridge tree from the registry into /build/cartridges, flattened to
35+
# <name>/ (the layout the build loops below and the runtime Catalog both expect).
36+
ARG BOJ_CARTRIDGES_REF
37+
ARG BOJ_CARTRIDGES_REPO
38+
COPY scripts/fetch-cartridges.sh /tmp/fetch-cartridges.sh
39+
RUN BOJ_CARTRIDGES_REF="$BOJ_CARTRIDGES_REF" \
40+
BOJ_CARTRIDGES_REPO="$BOJ_CARTRIDGES_REPO" \
41+
BOJ_CARTRIDGES_PATH=/build/cartridges \
42+
bash /tmp/fetch-cartridges.sh
2843

2944
# Build boj-invoke CLI (x86_64-linux-gnu target so it uses DlDynLib/real dlopen)
3045
RUN cd ffi/zig && zig build invoke -Doptimize=ReleaseFast
@@ -104,9 +119,11 @@ RUN for cart_dir in /tmp/cartridges-src/*/; do \
104119
done && \
105120
rm -rf /tmp/cartridges-src
106121

107-
# Copy cartridge metadata (cartridge.json files — loaded by Catalog GenServer)
122+
# Copy cartridge metadata (cartridge.json files — loaded by Catalog GenServer).
123+
# Sourced from the fetched tree in the zig-builder stage, not the build context,
124+
# so the image build no longer depends on a bundled cartridges/ directory.
108125
RUN mkdir -p /app-cartridges-meta
109-
COPY cartridges/ /tmp/carts-meta/
126+
COPY --from=zig-builder /build/cartridges/ /tmp/carts-meta/
110127
RUN for cart_dir in /tmp/carts-meta/*/; do \
111128
cart="$(basename "$cart_dir")" && \
112129
if [ -f "${cart_dir}cartridge.json" ]; then \

elixir/config/test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import Config
77
config :boj_rest, start_server: false
88

99
config :boj_rest,
10-
cartridges_root: Path.expand("../../cartridges", __DIR__)
10+
cartridges_root:
11+
System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)

elixir/test/aspect_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule BojRest.AspectTest do
88
import Plug.Test
99
import Plug.Conn
1010

11-
@cartridges_root Path.expand("../../cartridges", __DIR__)
11+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
1212
@opts BojRest.Router.init([])
1313

1414
setup_all do

elixir/test/catalog_properties_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule BojRest.CatalogPropertiesTest do
44
use ExUnit.Case, async: false
55
use ExUnitProperties
66

7-
@cartridges_root Path.expand("../../cartridges", __DIR__)
7+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
88

99
setup_all do
1010
case Process.whereis(BojRest.Catalog) do
@@ -66,7 +66,7 @@ defmodule BojRest.CatalogPropertiesTest do
6666
end
6767

6868
property "auth method is always a known value for all cartridges" do
69-
known = ~w[none api-key api_key_header bearer bearer_token oauth oauth2 session-token basic]
69+
known = ~w[none api-key api_key api_key_header api_token bearer bearer_token oauth oauth2 session-token basic mtls custom optional_bearer optional_api_key]
7070
carts = BojRest.Catalog.list()
7171
check all cart <- StreamData.member_of(carts) do
7272
method = get_in(cart, ["auth", "method"])

elixir/test/catalog_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
defmodule BojRest.CatalogTest do
44
use ExUnit.Case, async: false
55

6-
@cartridges_root Path.expand("../../cartridges", __DIR__)
6+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
77

88
setup_all do
99
case Process.whereis(BojRest.Catalog) do
@@ -83,8 +83,9 @@ defmodule BojRest.CatalogTest do
8383
end
8484

8585
test "auth method is always a known value" do
86-
known = ["none", "api-key", "api_key_header", "bearer", "bearer_token",
87-
"oauth", "oauth2", "session-token", "basic"]
86+
known = ["none", "api-key", "api_key", "api_key_header", "api_token",
87+
"bearer", "bearer_token", "oauth", "oauth2", "session-token",
88+
"basic", "mtls", "custom", "optional_bearer", "optional_api_key"]
8889
BojRest.Catalog.list()
8990
|> Enum.each(fn cart ->
9091
method = get_in(cart, ["auth", "method"])

elixir/test/contract_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule BojRest.ContractTest do
88
import Plug.Test
99
import Plug.Conn
1010

11-
@cartridges_root Path.expand("../../cartridges", __DIR__)
11+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
1212
@opts BojRest.Router.init([])
1313

1414
setup_all do

elixir/test/js_invoker_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
defmodule BojRest.JsInvokerTest do
44
use ExUnit.Case, async: false
55

6-
@cartridges_root Path.expand("../../cartridges", __DIR__)
6+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
77

88
# ── deno discovery ──────────────────────────────────────────────────────────
99

elixir/test/router_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule BojRest.RouterTest do
55
import Plug.Test
66
import Plug.Conn
77

8-
@cartridges_root Path.expand("../../cartridges", __DIR__)
8+
@cartridges_root System.get_env("BOJ_CARTRIDGES_PATH") || Path.expand("../../cartridges", __DIR__)
99
@opts BojRest.Router.init([])
1010

1111
setup_all do

0 commit comments

Comments
 (0)