Skip to content

Commit 2a05b72

Browse files
authored
fix(athena): Move HTTP proxy to dedicated module with self-contained build configuration (#550)
* fix: remove unused WASI HTTP handler from http-proxy stub Remove exports::wasi::http::incoming_handler::Guest implementation that was causing build failures. The HTTP functionality is handled through the hermes::http_request::event system instead. * fix: remove unused WASI HTTP handler from http-proxy stub Remove exports::wasi::http::incoming_handler::Guest implementation that was causing build failures. The HTTP functionality is handled through the hermes::http_request::event system instead. * refactor: reorganize HTTP proxy module build system with dedicated Earthfile Move HTTP proxy to its own directory with self-contained build config, implement direct WIT binding generation, and remove unused stub code. * feat(http-proxy): add WASI CLI imports to WIT bindings Add wasi:cli/[email protected] to the hermes world definition in the HTTP proxy module to enable CLI functionality support. * fix: build works * fix: build works * fix(athena): correct RBAC module path in app manifest Update manifest_app.json to use correct directory name 'rbac-registration-indexer' instead of 'rbac-registration'
1 parent fde33ac commit 2a05b72

File tree

7 files changed

+97
-280
lines changed

7 files changed

+97
-280
lines changed

hermes/apps/athena/manifest_app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"name": "http_proxy"
1010
},
1111
{
12-
"package": "modules/rbac-registration/lib/rbac_registration_indexer.hmod",
12+
"package": "modules/rbac-registration-indexer/lib/rbac_registration_indexer.hmod",
1313
"name": "rbac_registration_indexer"
1414
}
1515
],
1616
"www": "modules/http-proxy/lib/www"
17-
}
17+
}

hermes/apps/athena/modules/Earthfile

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ get-local-hermes:
5959
#
6060
# This creates Rust structs, enums, and functions that allow WASM modules
6161
# to interact with Hermes APIs like HTTP handling, logging, storage, etc.
62-
#
63-
# Multi-Module Architecture:
64-
# 🔗 SHARED BINDINGS: All modules use the same generated hermes.rs bindings
65-
# 📋 Common interfaces: HTTP, logging, storage, configuration, security
66-
# 🎯 Module-specific APIs: Each module can expose its own interfaces to others
67-
# ♻️ Reusable: Generated once, used by all modules in the application
68-
#
69-
# Future Module Examples:
70-
# - Authentication module: Uses shared HTTP + adds auth-specific interfaces
71-
# - Database module: Uses shared logging + adds database-specific interfaces
72-
# - Caching module: Uses shared storage + adds cache-specific interfaces
73-
#
7462
# Build Process:
7563
# 1. Uses WASI build environment with WIT tools pre-installed
7664
# 2. Processes WIT files to generate corresponding Rust code
@@ -88,135 +76,11 @@ gen-bindings:
8876
# NOTE: In multi-module apps, this same hermes.rs is copied to each module's src/
8977
SAVE ARTIFACT hermes.rs AS LOCAL athena/modules/http-proxy/src/hermes.rs
9078

91-
# HTTP Proxy WASM Module Build
92-
# =============================
93-
# Compiles the HTTP proxy Rust code into a WebAssembly module using the wasm32-wasip2 target.
94-
# This creates a sandboxed, portable component that can run in the Hermes runtime.
95-
#
96-
# 🌟 FIRST MODULE EXAMPLE - This demonstrates the pattern for building WASM modules
97-
# 📈 SCALABLE PATTERN: Additional modules follow this same build template:
98-
#
99-
# Future Module Build Targets (following this pattern):
100-
# +build-auth-module: Authentication and authorization (JWT, OAuth, API keys)
101-
# +build-database-module: Database connectivity and ORM functionality
102-
# +build-cache-module: Caching layer with Redis/Memcached support
103-
# +build-notification-module: Email, SMS, push notifications
104-
# +build-analytics-module: Request tracking, metrics, and reporting
105-
# +build-rate-limit-module: Request throttling and DDoS protection
106-
#
107-
# Multi-Module Benefits:
108-
# ✅ Independent development and testing of each module
109-
# ✅ Selective updates - rebuild only changed modules
110-
# ✅ Parallel compilation for faster overall build times
111-
# ✅ Modular deployment - enable/disable features per environment
112-
# ✅ Clear separation of concerns and responsibilities
113-
#
114-
# Build Pipeline:
115-
# 1. Set up Rust toolchain with WASM target support
116-
# 2. Copy source code and dependencies into build container
117-
# 3. Generate and integrate WIT bindings (shared across modules)
118-
# 4. Compile to optimized WASM binary
119-
# 5. Export artifacts for packaging
120-
#
121-
# Compilation Target: wasm32-wasip2 (WebAssembly System Interface Preview 2)
122-
# Optimization: Release mode with size optimizations (opt-level = "z", lto = true)
123-
# Output: http_proxy.wasm - Executable WebAssembly module
124-
# Duration: ~3-5 minutes (Rust compilation to WASM)
125-
local-build-http-proxy:
126-
DO rust-ci+SETUP
127-
WORKDIR /app
128-
129-
# Copy source code and project configuration
130-
COPY --keep-ts --dir http-proxy/src .
131-
COPY http-proxy/Cargo.toml .
132-
133-
# Integrate generated WIT bindings into the build
134-
COPY +gen-bindings/hermes.rs src/hermes.rs
135-
136-
# Copy module configuration and metadata files
137-
COPY http-proxy/lib/config.schema.json .
138-
COPY http-proxy/lib/manifest_module.json .
139-
COPY http-proxy/lib/metadata.json .
140-
COPY http-proxy/lib/settings.schema.json .
141-
142-
# Create the missing config.json file (empty JSON object)
143-
RUN echo '{}' > config.json
144-
145-
# Download web assets directly to root level
146-
COPY github.com/input-output-hk/catalyst-voices/catalyst_voices+build-web/web .
147-
148-
# Compile Rust code to WebAssembly
149-
DO rust-ci+CARGO \
150-
--args "build --target wasm32-wasip2 --release" \
151-
--output="wasm32-wasip2/release/http_proxy.wasm"
152-
153-
# Create staging directory structure
154-
RUN mkdir -p /staging/www
155-
156-
# Copy WASM module and JSON config files to root of staging
157-
RUN cp target/wasm32-wasip2/release/http_proxy.wasm /staging/
158-
RUN cp *.json /staging/ || true
159-
160-
# Copy web assets to www subdirectory
161-
RUN cp -r assets /staging/www/ || true
162-
RUN cp -r canvaskit /staging/www/ || true
163-
RUN cp -r icons /staging/www/ || true
164-
165-
# Copy all regular files from current directory to staging/www, skip directories
166-
RUN find . -maxdepth 1 -type f -exec cp {} /staging/www/ \; 2>/dev/null || echo "⚠️ Some files may not have been copied"
167-
168-
# Export build artifacts from staging directory
169-
SAVE ARTIFACT /staging AS LOCAL http-proxy/lib
170-
171-
# Future Module Build Targets
172-
# ============================
173-
# 🚀 COMING SOON: Additional module build targets following the same pattern as build-http-proxy
174-
#
175-
# Example future targets:
176-
#
177-
# build-auth-module:
178-
# DO rust-ci+SETUP
179-
# WORKDIR /app
180-
# COPY --keep-ts --dir auth-module/src .
181-
# COPY auth-module/Cargo.toml .
182-
# COPY +gen-bindings/hermes.rs src/hermes.rs
183-
# COPY auth-module/lib/*.json .
184-
# DO rust-ci+CARGO --args "build --target wasm32-wasip2 --release" --output="wasm32-wasip2/release/auth_module.wasm"
185-
# SAVE ARTIFACT target/wasm32-wasip2/release/auth_module.wasm AS LOCAL auth-module/lib/auth_module.wasm
186-
#
187-
# build-database-module:
188-
# DO rust-ci+SETUP
189-
# WORKDIR /app
190-
# COPY --keep-ts --dir database-module/src .
191-
# COPY database-module/Cargo.toml .
192-
# COPY +gen-bindings/hermes.rs src/hermes.rs
193-
# COPY database-module/lib/*.json .
194-
# DO rust-ci+CARGO --args "build --target wasm32-wasip2 --release" --output="wasm32-wasip2/release/database_module.wasm"
195-
# SAVE ARTIFACT target/wasm32-wasip2/release/database_module.wasm AS LOCAL database-module/lib/database_module.wasm
19679

19780
# Complete Multi-Module Build Pipeline
19881
# =====================================
19982
# Orchestrates the complete build process for all components.
20083
# This target builds the Hermes engine and all WASM modules in the correct order.
201-
#
202-
# 🏗️ SCALABLE ARCHITECTURE: As modules are added, they're included here for parallel builds
203-
# ⚡ PARALLEL COMPILATION: Multiple modules can build simultaneously for speed
204-
# 🎯 DEPENDENCY MANAGEMENT: Ensures proper build order and shared resource generation
205-
#
206-
# Current Build Order:
207-
# 1. get-local-hermes: Core runtime engine
208-
# 2. build-http-proxy: HTTP proxy WASM module (includes binding generation)
209-
#
210-
# Future Multi-Module Build Order:
211-
# 1. get-local-hermes: Core runtime engine
212-
# 2. Parallel module builds:
213-
# - build-http-proxy: HTTP routing and proxy functionality
214-
# - build-auth-module: Authentication and authorization
215-
# - build-database-module: Database connectivity and ORM
216-
# - build-cache-module: Caching and session management
217-
# - build-notification-module: Email, SMS, push notifications
218-
# - build-analytics-module: Request tracking and metrics
219-
#
22084
# Use this target for:
22185
# - Complete rebuilds from clean state
22286
# - CI/CD pipeline builds
@@ -246,31 +110,6 @@ build-all:
246110
# Earthly provides reproducible, containerized builds that work consistently across
247111
# different development environments without requiring local Rust toolchains.
248112
#
249-
# Multi-Module Application Architecture:
250-
# 🏗️ Applications can contain MULTIPLE WASM modules working together
251-
# 📦 Each module is compiled independently and packaged together
252-
# 🔗 Modules communicate through Hermes runtime interfaces
253-
# 🎯 Currently building: HTTP proxy (first of many planned modules)
254-
#
255-
# Scalable Build System:
256-
# - Each module gets its own build target (e.g., +build-http-proxy, +build-auth-module)
257-
# - Shared binding generation (+gen-bindings) used by all modules
258-
# - Parallel compilation of multiple modules for faster builds
259-
# - Individual module testing and development workflows
260-
#
261-
# Build Architecture:
262-
# 1. Import reusable build components from external sources
263-
# 2. Generate shared WebAssembly Interface Type (WIT) bindings
264-
# 3. Compile each Rust module to WebAssembly (WASM) using wasm32-wasip2 target
265-
# 4. Package all modules together into a single application bundle
266-
#
267-
# Key Benefits:
268-
# - Consistent builds across different machines and CI/CD environments
269-
# - No need to install Rust toolchains locally
270-
# - Automatic dependency management and caching
271-
# - Isolated build environments prevent "works on my machine" issues
272-
# - Modular architecture allows independent development and testing
273-
#
274113
# Usage Examples:
275114
# earthly +build-all # Build everything (engine + all modules)
276115
# earthly +get-local-hermes # Build just the Hermes engine
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
VERSION 0.8
2+
3+
IMPORT ../../../../ AS hermes
4+
IMPORT ../../../../../wasm/wasi AS wasi
5+
6+
build-http-proxy:
7+
DO wasi+BUILD_RUST_COMPONENT --wasi-src-dir=../../../../../wasm/wasi --out=http_proxy.wasm
8+
9+
10+
11+
# HTTP Proxy WASM Module Build
12+
# =============================
13+
# Compiles the HTTP proxy Rust code into a WebAssembly module using the wasm32-wasip2 target.
14+
# This creates a sandboxed, portable component that can run in the Hermes runtime.
15+
#
16+
# Build Pipeline:
17+
# 1. Set up Rust toolchain with WASM target support
18+
# 2. Copy source code and dependencies into build container
19+
# 3. Generate and integrate WIT bindings (shared across modules)
20+
# 4. Compile to optimized WASM binary
21+
# 5. Export artifacts for packaging
22+
#
23+
# Compilation Target: wasm32-wasip2 (WebAssembly System Interface Preview 2)
24+
# Optimization: Release mode with size optimizations (opt-level = "z", lto = true)
25+
# Output: http_proxy.wasm - Executable WebAssembly module
26+
# Duration: ~3-5 minutes (Rust compilation to WASM)
27+
local-build-http-proxy:
28+
FROM alpine
29+
COPY +build-http-proxy/http_proxy.wasm .
30+
31+
# Copy module configuration and metadata files
32+
COPY lib/config.schema.json .
33+
COPY lib/manifest_module.json .
34+
COPY lib/metadata.json .
35+
COPY lib/settings.schema.json .
36+
37+
# Create the missing config.json file (empty JSON object)
38+
RUN echo '{}' > config.json
39+
40+
# Download web assets directly to root level
41+
COPY github.com/input-output-hk/catalyst-voices/catalyst_voices+build-web/web .
42+
43+
# Create staging directory structure
44+
RUN mkdir -p /staging/www
45+
46+
# Copy WASM module and JSON config files to root of staging
47+
RUN cp http_proxy.wasm /staging/
48+
RUN cp *.json /staging/ || true
49+
50+
# Copy web assets to www subdirectory
51+
RUN cp -r assets /staging/www/ || true
52+
RUN cp -r canvaskit /staging/www/ || true
53+
RUN cp -r icons /staging/www/ || true
54+
55+
# Copy all regular files from current directory to staging/www, skip directories
56+
RUN find . -maxdepth 1 -type f -exec cp {} /staging/www/ \; 2>/dev/null || echo "⚠️ Some files may not have been copied"
57+
58+
# Export build artifacts from staging directory
59+
SAVE ARTIFACT /staging AS LOCAL lib
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"app_name":"catalyst_voices","version":"0.1.0","build_number":"1757006451","package_name":"catalyst_voices"}
1+
{"app_name":"catalyst_voices","version":"0.1.0","build_number":"1758273146","package_name":"catalyst_voices"}

hermes/apps/athena/modules/http-proxy/src/lib.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,32 @@
2020
//! proxy system capable of routing between multiple backends, supporting A/B testing,
2121
//! gradual rollouts, and advanced traffic management scenarios.
2222
23-
#[allow(clippy::all, unused)]
24-
mod hermes;
25-
mod stub;
26-
27-
use crate::hermes::exports::hermes::http_gateway::event::HttpGatewayResponse;
28-
use crate::hermes::exports::hermes::http_gateway::event::HttpResponse;
29-
use crate::hermes::hermes::binary::api::Bstr;
30-
3123
use regex::RegexSet;
3224
use std::sync::OnceLock;
3325

26+
use exports::hermes::http_gateway::event::{
27+
Bstr, Guest as _, Headers, HttpGatewayResponse, HttpResponse,
28+
};
29+
30+
wit_bindgen::generate!({
31+
world: "hermes:app/hermes",
32+
path: "../../../wasi/wit",
33+
inline: "
34+
package hermes:app;
35+
36+
world hermes {
37+
include wasi:cli/[email protected];
38+
import hermes:logging/api;
39+
export hermes:http-gateway/event;
40+
41+
}
42+
",
43+
generate_all,
44+
});
45+
export!(HttpProxyComponent);
46+
47+
use hermes::logging::api::{log, Level};
48+
3449
/// What to do when a route pattern matches
3550
#[derive(Debug, Clone, Copy)]
3651
enum RouteAction {
@@ -150,8 +165,8 @@ fn create_not_found_response(
150165

151166
/// Logs an info message
152167
fn log_info(message: &str) {
153-
hermes::hermes::logging::api::log(
154-
hermes::hermes::logging::api::Level::Info,
168+
log(
169+
Level::Info,
155170
Some("http-proxy"),
156171
None,
157172
None,
@@ -164,8 +179,8 @@ fn log_info(message: &str) {
164179

165180
/// Logs a debug message
166181
fn log_debug(message: &str) {
167-
hermes::hermes::logging::api::log(
168-
hermes::hermes::logging::api::Level::Debug,
182+
log(
183+
Level::Debug,
169184
Some("http-proxy"),
170185
None,
171186
None,
@@ -178,8 +193,8 @@ fn log_debug(message: &str) {
178193

179194
/// Logs a warning message
180195
fn log_warn(message: &str) {
181-
hermes::hermes::logging::api::log(
182-
hermes::hermes::logging::api::Level::Warn,
196+
log(
197+
Level::Warn,
183198
Some("http-proxy"),
184199
None,
185200
None,
@@ -200,15 +215,15 @@ fn format_response_type(response: &HttpGatewayResponse) -> String {
200215
}
201216
}
202217

203-
impl hermes::exports::hermes::http_gateway::event::Guest for HttpProxyComponent {
218+
impl exports::hermes::http_gateway::event::Guest for HttpProxyComponent {
204219
/// Routes HTTP requests through configurable proxy logic.
205220
///
206221
/// Current implementation provides temporary bridging to external Cat Voices
207222
/// endpoints while native implementations are developed. Future versions will
208223
/// support sophisticated routing rules, backend selection, and middleware chains.
209224
fn reply(
210225
_body: Vec<u8>,
211-
_headers: hermes::exports::hermes::http_gateway::event::Headers,
226+
_headers: Headers,
212227
path: String,
213228
method: String,
214229
) -> Option<HttpGatewayResponse> {
@@ -232,5 +247,3 @@ impl hermes::exports::hermes::http_gateway::event::Guest for HttpProxyComponent
232247
Some(response)
233248
}
234249
}
235-
236-
hermes::export!(HttpProxyComponent with_types_in hermes);

0 commit comments

Comments
 (0)