118 lines
3.2 KiB
Docker
118 lines
3.2 KiB
Docker
# Multi-stage build
|
|
|
|
# Stage 1: Build the Go executable
|
|
FROM golang:1.21-bookworm as go-builder
|
|
|
|
WORKDIR /root
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
COPY cmd/ ./cmd/
|
|
COPY internal/ ./internal/
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/app cmd/app/main.go
|
|
|
|
# Stage 2: Setup Node.js environment with mermaid CLI
|
|
FROM node:20-bookworm-slim as node-builder
|
|
|
|
WORKDIR /root
|
|
|
|
# Copy mermaid CLI package files
|
|
COPY ./mermaidcli/package*.json ./
|
|
COPY ./mermaidcli/puppeteer-config.json ./
|
|
|
|
# Install Node dependencies and Chrome via Puppeteer
|
|
RUN npm ci --only=production && \
|
|
npx puppeteer browsers install chrome-headless-shell && \
|
|
npm cache clean --force
|
|
|
|
# Stage 3: Final runtime image
|
|
FROM node:20-bookworm-slim
|
|
|
|
# Install system dependencies for Chrome/Puppeteer
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
fonts-liberation \
|
|
libappindicator3-1 \
|
|
libasound2 \
|
|
libatk-bridge2.0-0 \
|
|
libatk1.0-0 \
|
|
libc6 \
|
|
libcairo2 \
|
|
libcups2 \
|
|
libdbus-1-3 \
|
|
libexpat1 \
|
|
libfontconfig1 \
|
|
libgbm1 \
|
|
libgcc1 \
|
|
libglib2.0-0 \
|
|
libgtk-3-0 \
|
|
libnspr4 \
|
|
libnss3 \
|
|
libpango-1.0-0 \
|
|
libpangocairo-1.0-0 \
|
|
libstdc++6 \
|
|
libx11-6 \
|
|
libx11-xcb1 \
|
|
libxcb1 \
|
|
libxcomposite1 \
|
|
libxcursor1 \
|
|
libxdamage1 \
|
|
libxext6 \
|
|
libxfixes3 \
|
|
libxi6 \
|
|
libxrandr2 \
|
|
libxrender1 \
|
|
libxss1 \
|
|
libxtst6 \
|
|
libxshmfence1 \
|
|
libdrm2 \
|
|
libxkbcommon0 \
|
|
libatspi2.0-0 \
|
|
lsb-release \
|
|
wget \
|
|
xdg-utils \
|
|
--no-install-recommends && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /root
|
|
|
|
# Copy Go executable
|
|
COPY --from=go-builder /root/bin/app ./app
|
|
|
|
# Copy Node.js dependencies and mermaid CLI with Chrome
|
|
COPY --from=node-builder /root/node_modules ./node_modules
|
|
COPY --from=node-builder /root/package*.json ./
|
|
COPY --from=node-builder /root/puppeteer-config.json ./
|
|
COPY --from=node-builder /root/.cache /root/.cache
|
|
|
|
# Set Puppeteer environment variables and dynamically find Chrome
|
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
|
RUN CHROME_PATH=$(find /root/.cache/puppeteer -name "chrome-headless-shell" -type f 2>/dev/null | head -1) && \
|
|
echo "export PUPPETEER_EXECUTABLE_PATH='$CHROME_PATH'" >> /root/.bashrc && \
|
|
echo "Found Chrome at: $CHROME_PATH" && \
|
|
chmod +x "$CHROME_PATH" 2>/dev/null || true
|
|
|
|
# Create directories for input/output
|
|
RUN mkdir -p ./in ./out && \
|
|
chmod 0777 ./in ./out
|
|
|
|
# Create startup script to set Chrome path dynamically
|
|
RUN echo '#!/bin/bash\n\
|
|
export PUPPETEER_EXECUTABLE_PATH=$(find /root/.cache/puppeteer -name "chrome-headless-shell" -type f 2>/dev/null | head -1)\n\
|
|
echo "Using Chrome at: $PUPPETEER_EXECUTABLE_PATH"\n\
|
|
exec "$@"' > /root/start.sh && \
|
|
chmod +x /root/start.sh
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:80/health || exit 1
|
|
|
|
# Expose port
|
|
EXPOSE 80
|
|
|
|
# Run the application with dynamic Chrome path
|
|
ENTRYPOINT ["/root/start.sh"]
|
|
CMD ["./app", "--allow-all-origins=true", "--mermaid=./node_modules/.bin/mmdc", "--in=./in", "--out=./out", "--puppeteer=./puppeteer-config.json"]
|