2025-05-24 11:14:38 +02:00
|
|
|
# Multi-stage build
|
2020-04-07 00:25:47 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Stage 1: Build the Go executable
|
|
|
|
|
FROM golang:1.21-bookworm as go-builder
|
2020-04-07 00:25:47 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
WORKDIR /root
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
RUN go mod download
|
2020-04-07 00:25:47 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
COPY cmd/ ./cmd/
|
|
|
|
|
COPY internal/ ./internal/
|
2020-04-07 00:25:47 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/app cmd/app/main.go
|
2020-04-07 00:25:47 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Stage 2: Setup Node.js environment with mermaid CLI
|
|
|
|
|
FROM node:20-bookworm-slim as node-builder
|
2020-04-15 20:26:21 +02:00
|
|
|
|
|
|
|
|
WORKDIR /root
|
|
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Copy mermaid CLI package files
|
|
|
|
|
COPY ./mermaidcli/package*.json ./
|
|
|
|
|
COPY ./mermaidcli/puppeteer-config.json ./
|
|
|
|
|
|
|
|
|
|
# Install Node dependencies
|
|
|
|
|
RUN npm ci --only=production && npm cache clean --force
|
2020-04-15 20:26:21 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Stage 3: Final runtime image
|
|
|
|
|
FROM node:20-bookworm-slim
|
2020-04-15 20:26:21 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Install system dependencies for Puppeteer
|
2020-04-07 00:25:47 +02:00
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
2025-05-24 11:14:38 +02:00
|
|
|
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 \
|
|
|
|
|
lsb-release \
|
|
|
|
|
wget \
|
|
|
|
|
xdg-utils \
|
|
|
|
|
--no-install-recommends && \
|
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2020-04-15 20:26:21 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
WORKDIR /root
|
|
|
|
|
|
|
|
|
|
# Copy Go executable
|
|
|
|
|
COPY --from=go-builder /root/bin/app ./app
|
2020-04-15 20:26:21 +02:00
|
|
|
|
2025-05-24 11:14:38 +02:00
|
|
|
# Copy Node.js dependencies and mermaid CLI
|
|
|
|
|
COPY --from=node-builder /root/node_modules ./node_modules
|
|
|
|
|
COPY --from=node-builder /root/package*.json ./
|
|
|
|
|
COPY --from=node-builder /root/puppeteer-config.json ./
|
|
|
|
|
|
|
|
|
|
# Create directories for input/output
|
|
|
|
|
RUN mkdir -p ./in ./out && \
|
|
|
|
|
chmod 0777 ./in ./out
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
CMD ["./app", "--allow-all-origins=true", "--mermaid=./node_modules/.bin/mmdc", "--in=./in", "--out=./out", "--puppeteer=./puppeteer-config.json"]
|