Add Railway Caddy frontend images

This commit is contained in:
Nathan Flurry 2026-03-12 18:08:02 -07:00
parent 9960fba40e
commit d7d13e330a
6 changed files with 107 additions and 4 deletions

View file

@ -0,0 +1,16 @@
#!/bin/sh
set -eu
escape_js() {
printf '%s' "${1:-}" | sed 's/\\/\\\\/g; s/"/\\"/g'
}
cat > /srv/__foundry_runtime_config.js <<EOF
window.__FOUNDRY_RUNTIME_CONFIG__ = {
backendEndpoint: "$(escape_js "${VITE_HF_BACKEND_ENDPOINT:-}")",
defaultWorkspaceId: "$(escape_js "${VITE_HF_WORKSPACE:-}")",
frontendClientMode: "$(escape_js "${FOUNDRY_FRONTEND_CLIENT_MODE:-remote}")"
};
EOF
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

View file

@ -0,0 +1,11 @@
{
auto_https off
}
:{$PORT:80} {
root * /srv
encode gzip zstd
header /__foundry_runtime_config.js Cache-Control "no-store"
try_files {path} /index.html
file_server
}

View file

@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.7
FROM node:22-bookworm-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@9.15.0 --activate
FROM base AS build
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm --filter @sandbox-agent/foundry-shared build
RUN pnpm --filter acp-http-client build
RUN pnpm --filter @sandbox-agent/cli-shared build
RUN SKIP_OPENAPI_GEN=1 pnpm --filter sandbox-agent build
RUN pnpm --filter @sandbox-agent/react build
RUN pnpm --filter @sandbox-agent/foundry-client build
RUN pnpm --filter @sandbox-agent/foundry-frontend-errors build
ENV FOUNDRY_FRONTEND_CLIENT_MODE=remote
RUN pnpm --filter @sandbox-agent/foundry-frontend build
FROM caddy:2.10-alpine AS runtime
COPY foundry/docker/frontend.Caddyfile /etc/caddy/Caddyfile
COPY foundry/docker/frontend-caddy-entrypoint.sh /usr/local/bin/foundry-frontend-entrypoint
COPY --from=build /app/foundry/packages/frontend/dist /srv
RUN chmod +x /usr/local/bin/foundry-frontend-entrypoint
ENV PORT=80
ENV FOUNDRY_FRONTEND_CLIENT_MODE=remote
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/foundry-frontend-entrypoint"]

View file

@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.7
FROM node:22-bookworm-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@9.15.0 --activate
FROM base AS build
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm --filter @sandbox-agent/foundry-shared build
RUN pnpm --filter acp-http-client build
RUN pnpm --filter @sandbox-agent/cli-shared build
RUN SKIP_OPENAPI_GEN=1 pnpm --filter sandbox-agent build
RUN pnpm --filter @sandbox-agent/react build
RUN pnpm --filter @sandbox-agent/foundry-client build
RUN pnpm --filter @sandbox-agent/foundry-frontend-errors build
ENV FOUNDRY_FRONTEND_CLIENT_MODE=mock
RUN pnpm --filter @sandbox-agent/foundry-frontend build
FROM caddy:2.10-alpine AS runtime
COPY foundry/docker/frontend.Caddyfile /etc/caddy/Caddyfile
COPY foundry/docker/frontend-caddy-entrypoint.sh /usr/local/bin/foundry-frontend-entrypoint
COPY --from=build /app/foundry/packages/frontend/dist /srv
RUN chmod +x /usr/local/bin/foundry-frontend-entrypoint
ENV PORT=80
ENV FOUNDRY_FRONTEND_CLIENT_MODE=mock
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/foundry-frontend-entrypoint"]

View file

@ -18,6 +18,7 @@
</head>
<body>
<div id="root"></div>
<script src="/__foundry_runtime_config.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View file

@ -1,3 +1,15 @@
type FoundryRuntimeConfig = {
backendEndpoint?: string;
defaultWorkspaceId?: string;
frontendClientMode?: string;
};
declare global {
interface Window {
__FOUNDRY_RUNTIME_CONFIG__?: FoundryRuntimeConfig;
}
}
function resolveDefaultBackendEndpoint(): string {
if (typeof window !== "undefined" && window.location?.origin) {
return `${window.location.origin}/api/rivet`;
@ -10,20 +22,23 @@ type FrontendImportMetaEnv = ImportMetaEnv & {
};
const frontendEnv = import.meta.env as FrontendImportMetaEnv;
const runtimeConfig = typeof window !== "undefined" ? window.__FOUNDRY_RUNTIME_CONFIG__ : undefined;
export const backendEndpoint = import.meta.env.VITE_HF_BACKEND_ENDPOINT?.trim() || resolveDefaultBackendEndpoint();
export const backendEndpoint = runtimeConfig?.backendEndpoint?.trim() || import.meta.env.VITE_HF_BACKEND_ENDPOINT?.trim() || resolveDefaultBackendEndpoint();
export const defaultWorkspaceId = import.meta.env.VITE_HF_WORKSPACE?.trim() || "default";
export const defaultWorkspaceId = runtimeConfig?.defaultWorkspaceId?.trim() || import.meta.env.VITE_HF_WORKSPACE?.trim() || "default";
function resolveFrontendClientMode(): "mock" | "remote" {
const raw = frontendEnv.FOUNDRY_FRONTEND_CLIENT_MODE?.trim().toLowerCase();
const raw = runtimeConfig?.frontendClientMode?.trim().toLowerCase() || frontendEnv.FOUNDRY_FRONTEND_CLIENT_MODE?.trim().toLowerCase();
if (raw === "mock") {
return "mock";
}
if (raw === "remote" || raw === "" || raw === undefined) {
return "remote";
}
throw new Error(`Unsupported FOUNDRY_FRONTEND_CLIENT_MODE value "${frontendEnv.FOUNDRY_FRONTEND_CLIENT_MODE}". Expected "mock" or "remote".`);
throw new Error(
`Unsupported FOUNDRY_FRONTEND_CLIENT_MODE value "${runtimeConfig?.frontendClientMode ?? frontendEnv.FOUNDRY_FRONTEND_CLIENT_MODE}". Expected "mock" or "remote".`,
);
}
export const frontendClientMode = resolveFrontendClientMode();