|
1 | | -# ---- Build static Storybook ---- |
2 | | -FROM node:20-alpine AS build |
3 | | -WORKDIR /app |
| 1 | +# syntax=docker/dockerfile:1.7 |
4 | 2 |
|
5 | | -COPY client/package.json client/package-lock.json* ./client/ |
| 3 | +############################ |
| 4 | +# 1) Build Storybook static |
| 5 | +############################ |
| 6 | +FROM node:20-alpine AS build |
6 | 7 | WORKDIR /app/client |
7 | 8 |
|
| 9 | +# Install deps (cached) |
| 10 | +COPY client/package.json client/package-lock.json ./ |
8 | 11 | RUN npm ci |
9 | 12 |
|
10 | | -COPY client/ . |
| 13 | +# Copy the rest |
| 14 | +COPY client/ ./ |
11 | 15 |
|
| 16 | +# Build static Storybook (outputs storybook-static/) |
12 | 17 | RUN npm run build-storybook |
13 | 18 |
|
14 | | -# ---- Serve with nginx ---- |
15 | | -FROM nginx:alpine |
16 | | -COPY --from=build /app/client/storybook-static /usr/share/nginx/html |
| 19 | +######################################## |
| 20 | +# 2) Serve static files with nginx |
| 21 | +######################################## |
| 22 | +FROM nginx:1.27-alpine |
17 | 23 |
|
18 | | -RUN printf 'server {\n\ |
19 | | - listen 80;\n\ |
20 | | - server_name _;\n\ |
21 | | - root /usr/share/nginx/html;\n\ |
22 | | - index index.html;\n\ |
23 | | - location / {\n\ |
24 | | - try_files $uri $uri/ /index.html;\n\ |
25 | | - }\n\ |
26 | | -}\n' > /etc/nginx/conf.d/default.conf |
| 24 | +# Replace default server config with SPA-friendly config |
| 25 | +RUN rm -f /etc/nginx/conf.d/default.conf && \ |
| 26 | + printf 'server {\n\ |
| 27 | + listen 80;\n\ |
| 28 | + server_name _;\n\ |
| 29 | + root /usr/share/nginx/html;\n\ |
| 30 | + index index.html;\n\ |
| 31 | + # Storybook is a SPA; fall back to index.html\n\ |
| 32 | + location / {\n\ |
| 33 | + try_files $uri $uri/ /index.html;\n\ |
| 34 | + }\n\ |
| 35 | + # Cache immutable assets aggressively\n\ |
| 36 | + location ~* \\.(?:js|css|png|jpg|jpeg|gif|svg|ico|woff2?)$ {\n\ |
| 37 | + expires 30d;\n\ |
| 38 | + add_header Cache-Control \"public, max-age=2592000, immutable\";\n\ |
| 39 | + try_files $uri =404;\n\ |
| 40 | + }\n\ |
| 41 | + }\n' > /etc/nginx/conf.d/storybook.conf |
| 42 | + |
| 43 | +# Copy build output |
| 44 | +COPY --from=build /app/client/storybook-static /usr/share/nginx/html |
27 | 45 |
|
28 | 46 | EXPOSE 80 |
0 commit comments