mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 07:04:48 +00:00
Add Railway Caddy frontend images
This commit is contained in:
parent
940e49fcfa
commit
e79a3d9389
6 changed files with 107 additions and 4 deletions
16
foundry/docker/frontend-caddy-entrypoint.sh
Normal file
16
foundry/docker/frontend-caddy-entrypoint.sh
Normal 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
|
||||||
11
foundry/docker/frontend.Caddyfile
Normal file
11
foundry/docker/frontend.Caddyfile
Normal 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
|
||||||
|
}
|
||||||
30
foundry/docker/frontend.Dockerfile
Normal file
30
foundry/docker/frontend.Dockerfile
Normal 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"]
|
||||||
30
foundry/docker/frontend.mock.Dockerfile
Normal file
30
foundry/docker/frontend.mock.Dockerfile
Normal 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"]
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
<script src="/__foundry_runtime_config.js"></script>
|
||||||
<script type="module" src="/src/main.tsx"></script>
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,15 @@
|
||||||
|
type FoundryRuntimeConfig = {
|
||||||
|
backendEndpoint?: string;
|
||||||
|
defaultWorkspaceId?: string;
|
||||||
|
frontendClientMode?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
__FOUNDRY_RUNTIME_CONFIG__?: FoundryRuntimeConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function resolveDefaultBackendEndpoint(): string {
|
function resolveDefaultBackendEndpoint(): string {
|
||||||
if (typeof window !== "undefined" && window.location?.origin) {
|
if (typeof window !== "undefined" && window.location?.origin) {
|
||||||
return `${window.location.origin}/api/rivet`;
|
return `${window.location.origin}/api/rivet`;
|
||||||
|
|
@ -10,20 +22,23 @@ type FrontendImportMetaEnv = ImportMetaEnv & {
|
||||||
};
|
};
|
||||||
|
|
||||||
const frontendEnv = import.meta.env as FrontendImportMetaEnv;
|
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" {
|
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") {
|
if (raw === "mock") {
|
||||||
return "mock";
|
return "mock";
|
||||||
}
|
}
|
||||||
if (raw === "remote" || raw === "" || raw === undefined) {
|
if (raw === "remote" || raw === "" || raw === undefined) {
|
||||||
return "remote";
|
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();
|
export const frontendClientMode = resolveFrontendClientMode();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue