add first draft working docker setup
This commit is contained in:
+14
-3
@@ -1,4 +1,7 @@
|
||||
# ── Build stage ──────────────────────────────────────────
|
||||
FROM node:22-alpine AS builder
|
||||
ARG PUBLIC_PB_URL=/pb
|
||||
ENV PUBLIC_PB_URL=$PUBLIC_PB_URL
|
||||
RUN corepack enable
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
@@ -6,8 +9,12 @@ RUN pnpm install --frozen-lockfile
|
||||
RUN pnpm --filter frontend build
|
||||
RUN pnpm --filter proxy build
|
||||
|
||||
# ── Runtime stage ────────────────────────────────────────
|
||||
FROM node:22-alpine
|
||||
RUN corepack enable && apk add --no-cache nginx
|
||||
ARG PUBLIC_PB_URL=/pb
|
||||
ENV PUBLIC_PB_URL=$PUBLIC_PB_URL
|
||||
ENV PB_ENDPOINT=http://127.0.0.1:8090
|
||||
RUN corepack enable && apk add --no-cache nginx wget unzip ca-certificates
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/frontend/build ./frontend/build
|
||||
COPY --from=builder /app/proxy/dist ./proxy/dist
|
||||
@@ -15,8 +22,12 @@ COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/pnpm-lock.yaml ./
|
||||
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
|
||||
COPY docker/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
# Bundle PocketBase (same version as Dockerfile.dev) into the app container.
|
||||
RUN wget -qO /tmp/pb.zip https://github.com/pocketbase/pocketbase/releases/download/v0.25.8/pocketbase_0.25.8_linux_amd64.zip \
|
||||
&& unzip -o /tmp/pb.zip -d /usr/local/bin/ \
|
||||
&& rm /tmp/pb.zip
|
||||
RUN chmod +x /entrypoint.sh /usr/local/bin/pocketbase
|
||||
ENV FRONTEND_PORT=2080
|
||||
ENV PROXY_PORT=3456
|
||||
EXPOSE 3001
|
||||
EXPOSE 3001 8090
|
||||
CMD ["/entrypoint.sh"]
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
PB_DATA=${PB_DATA_DIR:-/app/pb_data}
|
||||
|
||||
# Seed a platform superuser from env (idempotent — no-op if it already exists).
|
||||
# If PB_EMAIL/PB_PASSWORD aren't set, skip and rely on manual web setup.
|
||||
if [ -n "$PB_EMAIL" ] && [ -n "$PB_PASSWORD" ]; then
|
||||
echo "[entrypoint] Ensuring PocketBase superuser..."
|
||||
pocketbase superuser upsert "$PB_EMAIL" "$PB_PASSWORD" --dir="$PB_DATA" || true
|
||||
fi
|
||||
|
||||
# Start PocketBase (internal only; published via loopback for admin UI).
|
||||
pocketbase serve --http=0.0.0.0:8090 --dir="$PB_DATA" &
|
||||
|
||||
# Wait for PB to be healthy before starting the proxy (which runs migrate).
|
||||
echo "[entrypoint] Waiting for PocketBase..."
|
||||
for i in $(seq 1 30); do
|
||||
if curl -sf http://127.0.0.1:8090/api/health >/dev/null 2>&1; then
|
||||
echo "[entrypoint] PocketBase is healthy."
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# Start the app (frontend + proxy). The proxy auto-runs schema migration.
|
||||
PORT=${FRONTEND_PORT:-2080} node /app/frontend/build/index.js &
|
||||
PROXY_PORT=${PROXY_PORT:-3456} node /app/proxy/dist/index.js &
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ server {
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# App's Hono proxy (/api/*).
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:3456;
|
||||
proxy_http_version 1.1;
|
||||
@@ -19,4 +20,25 @@ server {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Browser → internal PocketBase SDK (REST + realtime WebSocket). Only the
|
||||
# /api subtree the PocketBase JS SDK uses. The admin UI (/_ and everything
|
||||
# else under /pb/) is intentionally NOT proxied, keeping it internal.
|
||||
location /pb/api/ {
|
||||
proxy_pass http://127.0.0.1:8090/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_buffering off;
|
||||
proxy_read_timeout 3600s;
|
||||
}
|
||||
|
||||
# Everything else under /pb/ (including /pb/_ admin UI) → 404.
|
||||
location /pb/ {
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user