Skip to content

Commit d70f153

Browse files
committed
Local test merge of PR anomalyco#175: feat: add static directory to Dockerfile for static file serving
2 parents ec9d95c + b571d53 commit d70f153

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎packages/opencode/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ research
22
dist
33
gen
44
app.log
5+
static

‎packages/opencode/Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ RUN apk add libgcc libstdc++ ripgrep
88

99
FROM base AS build-amd64
1010
COPY dist/shuvcode-linux-x64-baseline-musl/bin/shuvcode /usr/local/bin/shuvcode
11+
COPY static /usr/local/bin/static
1112

1213
FROM base AS build-arm64
1314
COPY dist/shuvcode-linux-arm64-musl/bin/shuvcode /usr/local/bin/shuvcode
15+
COPY static /usr/local/bin/static
1416

1517
ARG TARGETARCH
1618
FROM build-${TARGETARCH}

‎packages/opencode/src/installation/index.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BusEvent } from "@/bus/bus-event"
22
import { Bus } from "@/bus"
33
import path from "path"
4+
import fs from "fs"
45
import { $ } from "bun"
56
import z from "zod"
67
import { NamedError } from "@opencode-ai/util/error"
@@ -62,6 +63,11 @@ export namespace Installation {
6263
return CHANNEL === "local"
6364
}
6465

66+
export function isBundled() {
67+
const staticPath = path.join(path.dirname(process.execPath), "static")
68+
return fs.existsSync(staticPath)
69+
}
70+
6571
export async function method() {
6672
const exec = process.execPath.toLowerCase()
6773

‎packages/opencode/src/server/server.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ import { TuiEvent } from "@/cli/cmd/tui/event"
4646
import { Snapshot } from "@/snapshot"
4747
import { SessionSummary } from "@/session/summary"
4848
import { SessionStatus } from "@/session/status"
49-
import { upgradeWebSocket, websocket } from "hono/bun"
49+
import { upgradeWebSocket, websocket, serveStatic } from "hono/bun"
5050
import { errors } from "./error"
5151
import { Pty } from "@/pty"
5252
import { Installation } from "@/installation"
53+
import fs from "fs"
54+
import path from "path"
5355

5456
// @ts-ignore This global is needed to prevent ai-sdk from logging warnings to stdout https://github.com/vercel/ai/blob/2dc67e0ef538307f21368db32d5a12345d98831b/packages/ai/src/logger/log-warnings.ts#L85
5557
globalThis.AI_SDK_LOG_WARNINGS = false
@@ -2647,6 +2649,14 @@ export namespace Server {
26472649
},
26482650
)
26492651
.all("/*", async (c) => {
2652+
if (Installation.isBundled()) {
2653+
const res = await serveStatic({
2654+
root: path.relative(process.cwd(), path.join(path.dirname(process.execPath), "static")),
2655+
rewriteRequestPath: (path) => (path === "/" ? "/index.html" : path),
2656+
})(c, async () => {})
2657+
if (res) return res
2658+
}
2659+
26502660
const desktopHost = Installation.isLocal()
26512661
? process.env.OPENCODE_DESKTOP_URL || "http://localhost:3000"
26522662
: process.env.SHUVCODE_DESKTOP_URL || "https://desktop.shuv.ai"

0 commit comments

Comments
 (0)