CJHauser commited on
Commit
87abeb5
·
verified ·
1 Parent(s): fb224c9

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +89 -0
Dockerfile ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM oven/bun:1-slim
2
+
3
+ ARG DEBIAN_FRONTEND=noninteractive
4
+ RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ git ca-certificates curl sqlite3 rsync python3 \
6
+ && rm -rf /var/lib/apt/lists/*
7
+
8
+ WORKDIR /app
9
+
10
+ ARG LUMIVERSE_REPO=https://github.com/CloudCompile/Lumiverse.git
11
+ ARG LUMIVERSE_REF=multiuser2
12
+ RUN git clone --depth 1 --branch "${LUMIVERSE_REF}" "${LUMIVERSE_REPO}" .
13
+
14
+ RUN cat > /tmp/patch-auth-rewrite.mjs <<'PATCH'
15
+ import { readFileSync, writeFileSync } from "fs";
16
+
17
+ const path = "src/app.ts";
18
+ const src = readFileSync(path, "utf8");
19
+
20
+ const before = `app.on(["POST", "GET"], "/api/auth/*", (c) => {
21
+ const host = c.req.header("host");
22
+ if (host) {
23
+ const url = new URL(c.req.url);
24
+ const rewritten = new URL(url.pathname + url.search, \`http://\${host}\`);
25
+ return auth.handler(new Request(rewritten.toString(), c.req.raw));
26
+ }
27
+ return auth.handler(c.req.raw);
28
+ });`;
29
+
30
+ const after = `app.on(["POST", "GET"], "/api/auth/*", (c) => {
31
+ const host = c.req.header("x-forwarded-host") || c.req.header("host");
32
+ const proto = c.req.header("x-forwarded-proto") || "http";
33
+
34
+ if (host) {
35
+ const url = new URL(c.req.url);
36
+ const rewritten = new URL(url.pathname + url.search, \`${proto}://${host}\`);
37
+ return auth.handler(new Request(rewritten.toString(), c.req.raw));
38
+ }
39
+ return auth.handler(c.req.raw);
40
+ });`;
41
+
42
+ if (!src.includes(before)) {
43
+ console.error("[patch] Expected auth rewrite block not found in src/app.ts");
44
+ process.exit(1);
45
+ }
46
+
47
+ writeFileSync(path, src.replace(before, after), "utf8");
48
+ console.log("[patch] Patched src/app.ts for x-forwarded-proto/host");
49
+ PATCH
50
+
51
+ RUN bun /tmp/patch-auth-rewrite.mjs \
52
+ && grep -n "x-forwarded-proto" src/app.ts >/dev/null
53
+
54
+ RUN rm -f package-lock.json && bun install --production
55
+
56
+ WORKDIR /app/frontend
57
+ RUN rm -f package-lock.json && bun install && bun run build
58
+ RUN printf "self.addEventListener('install',e=>e.skipWaiting());self.addEventListener('activate',e=>e.waitUntil(self.clients.claim()));\n" > /app/frontend/dist/sw.js
59
+ RUN test -f /app/frontend/dist/index.html
60
+
61
+ WORKDIR /app
62
+ ENV NODE_ENV=production
63
+ ENV PORT=7860
64
+ ENV DATA_DIR=/app/data
65
+ ENV FRONTEND_DIR=/app/frontend/dist
66
+ ENV TRUST_ANY_ORIGIN=true
67
+ ENV AUTH_PUBLIC_SIGNUP=true
68
+ ENV OWNER_PASSWORD=changeme123
69
+
70
+ RUN cat > /app/start.sh <<'SH'
71
+ #!/usr/bin/env sh
72
+ set -eu
73
+
74
+ export DATA_DIR="${DATA_DIR:-/app/data}"
75
+
76
+ # Run with the runner script so IPC is available for the operator page
77
+ exec bun run scripts/runner.ts
78
+ SH
79
+
80
+ RUN chmod +x /app/start.sh
81
+
82
+ USER root
83
+ RUN mkdir -p /app/data && chown -R bun:bun /app/data
84
+
85
+ EXPOSE 7860
86
+ VOLUME /app/data
87
+
88
+ USER bun
89
+ CMD ["/app/start.sh"]