Skip to content

Commit 6713e9f

Browse files
authored
Make iframe-outputs docker use nginx (#719)
* Make iframe-outputs docker use nginx - Split Dockerfile into build and production stages - pnpm install uses cache to speed up builds * Address nginx warning * Add healthz endpoint for `hub`
1 parent 3885b80 commit 6713e9f

3 files changed

Lines changed: 64 additions & 10 deletions

File tree

Dockerfile.iframe-outputs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
1-
# Minimal Dockerfile for iframe outputs
2-
# Runs the iframe Vite dev server
3-
FROM node:23-alpine
1+
# syntax=docker/dockerfile:1.4
2+
# Build stage
3+
FROM node:23-alpine AS builder
44
RUN npm install -g pnpm@latest
55
WORKDIR /app
66

77
# Copy workspace files
88
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
99

10-
# Copy package files for workspace (needed for @runtimed/schema imports)
10+
# Copy schema package.json (only workspace dependency needed for iframe)
1111
COPY packages/schema/package.json packages/schema/tsconfig.json ./packages/schema/
12-
COPY packages/schema/src ./packages/schema/src
12+
13+
# Install dependencies with cache mount
14+
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
15+
pnpm install --frozen-lockfile
1316

1417
# Copy source files needed for iframe
18+
COPY packages/schema/src ./packages/schema/src
1519
COPY src/components/ui ./src/components/ui
1620
COPY src/lib ./src/lib
21+
COPY src/util/iframe.ts ./src/util/iframe.ts
1722
COPY src/components/outputs/shared-with-iframe ./src/components/outputs/shared-with-iframe
1823
COPY iframe-outputs ./iframe-outputs
1924
COPY vite.config.ts tsconfig.json tsconfig.node.json ./
2025

21-
# Install all dependencies at root level
22-
RUN pnpm install --frozen-lockfile
26+
# Build the iframe outputs
27+
RUN pnpm build:iframe
28+
29+
# Production stage
30+
FROM nginx:alpine
31+
32+
# Copy built files from builder stage
33+
COPY --from=builder /app/iframe-outputs/worker/dist /usr/share/nginx/html
34+
35+
# Copy nginx configuration
36+
COPY iframe-outputs/nginx-main.conf /etc/nginx/nginx.conf
37+
COPY iframe-outputs/nginx.conf /etc/nginx/conf.d/default.conf
2338

24-
# Expose port for local testing
39+
# Expose port 8000
2540
EXPOSE 8000
2641

27-
# Run the vite dev server
28-
CMD ["pnpm", "dev:iframe", "--host"]
42+
# Start nginx
43+
CMD ["nginx", "-g", "daemon off;"]
2944

iframe-outputs/nginx-main.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The default nginx configuration causes this warning in the logs when running in hub:
2+
# nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
3+
# So we're overriding it here.
4+
events {
5+
worker_connections 1024;
6+
}
7+
8+
http {
9+
include /etc/nginx/mime.types;
10+
default_type application/octet-stream;
11+
12+
sendfile on;
13+
keepalive_timeout 65;
14+
15+
include /etc/nginx/conf.d/*.conf;
16+
}
17+

iframe-outputs/nginx.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 8000;
3+
root /usr/share/nginx/html;
4+
index index.html react.html;
5+
6+
gzip on;
7+
8+
# Allow iframe embedding
9+
add_header Content-Security-Policy "frame-ancestors *;" always;
10+
11+
# Health check endpoint
12+
location /healthz {
13+
access_log off;
14+
return 200 "healthy\n";
15+
add_header Content-Type text/plain;
16+
}
17+
18+
# Serve static files
19+
location / {
20+
try_files $uri $uri/ /index.html;
21+
}
22+
}

0 commit comments

Comments
 (0)