-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
139 lines (108 loc) · 4.39 KB
/
Dockerfile
File metadata and controls
139 lines (108 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Multi-stage Dockerfile for facet CLI with Chromium browser
# Supports multi-arch builds (amd64, arm64)
FROM node:20-bookworm-slim AS builder
ARG GIT_COMMIT=unknown
# Install system dependencies and bun
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
git \
curl \
unzip \
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:$PATH"
# Install pnpm
RUN npm install -g pnpm@9.15.9
# Set working directory
WORKDIR /app
# Copy package files
COPY package.json pnpm-lock.yaml ./
COPY cli/package.json cli/pnpm-lock.yaml ./cli/
# Install dependencies
RUN pnpm install --frozen-lockfile
RUN cd cli && pnpm install --frozen-lockfile
# Copy source code
COPY . .
# Build the standalone binary (bun compile) and the lib
ENV GIT_COMMIT=${GIT_COMMIT}
RUN cd cli && pnpm run build
# Final stage with Chromium browser
FROM node:20-bookworm-slim
ARG VERSION=dev
# Install Chromium browser and dependencies for Puppeteer
# Using Chromium from Debian repos for better multi-arch support
RUN apt-get update && apt-get install -y \
chromium \
chromium-sandbox \
fonts-liberation \
fonts-noto-color-emoji \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-freefont-ttf \
ca-certificates \
curl \
unzip \
imagemagick \
bubblewrap \
socat \
ripgrep \
&& rm -rf /var/lib/apt/lists/*
# Install pnpm (used by facet at runtime to install template dependencies)
RUN npm install -g pnpm@9.15.9
# Install sandbox-runtime for template execution isolation
RUN npm install -g @anthropic-ai/sandbox-runtime
# Allow ImageMagick to read/write PDFs (blocked by default policy)
RUN sed -i 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml 2>/dev/null || true
# Install bun (needed to run vite-ssr-loader.ts at template build time)
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:$PATH"
# Set Chromium executable path for Puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
# Copy the compiled standalone binary from builder
COPY --from=builder /app/dist/facet /usr/local/bin/facet
# Copy source files needed at runtime (component library + examples)
COPY --from=builder /app/src /app/src
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/package.json /app/package.json
COPY --from=builder /app/pnpm-lock.yaml /app/pnpm-lock.yaml
# Copy example files for demonstration
COPY cli/examples/SimpleReport.tsx /app/examples/
COPY cli/examples/simple-data.json /app/examples/
# Pre-populate npm cache with the locally-built @flanksource/facet package.
# This means `npm install @flanksource/facet@<version>` inside .facet/ at
# runtime will resolve from cache rather than fetching from the registry.
RUN mkdir -p /tmp/facet-pack && \
TARBALL=$(cd /app && npm pack --pack-destination /tmp/facet-pack/ 2>/dev/null | tail -1) && \
npm cache add /tmp/facet-pack/${TARBALL} && \
rm -rf /tmp/facet-pack
# Verify Chromium and facet binary are available
RUN chromium --version && facet --version
# Pack @flanksource/facet to a permanent tarball path.
# FACET_PACKAGE_PATH tells the CLI to use this local tarball instead of
# fetching from the npm registry (the version may not yet be published).
RUN cd /app && npm pack --pack-destination /app/ 2>/dev/null
ENV FACET_PACKAGE_PATH=/app/facet.tgz
RUN mv /app/flanksource-facet-*.tgz /app/facet.tgz
RUN mkdir -p /workspace /templates /etc/facet
COPY srt-settings.json /etc/facet/srt-settings.json
# Set default working directory
WORKDIR /workspace
EXPOSE 3010
# Add labels
LABEL org.opencontainers.image.title="Facet" \
org.opencontainers.image.description="Generate beautiful PDFs and datasheets from React templates with Chrome" \
org.opencontainers.image.source="https://github.com/flanksource/facet" \
org.opencontainers.image.vendor="Flanksource" \
org.opencontainers.image.version="${VERSION}"
# Warm the node_modules / .facet cache by rendering the playground sample
RUN cd /app/examples && \
facet pdf SimpleReport.tsx --data simple-data.json --output /tmp/warmup.pdf && \
rm -f /tmp/warmup.pdf
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:3010/healthz || exit 1
CMD ["facet", "serve", "--templates-dir", "/templates"]