# 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 and Chrome 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 mermaid CLI package files COPY ./mermaidcli/package*.json ./ COPY ./mermaidcli/puppeteer-config.json ./ # Install Node dependencies and Chrome in single layer RUN npm ci --only=production && \ npx puppeteer browsers install chrome-headless-shell && \ npm cache clean --force # Set environment variables - let Puppeteer find Chrome automatically ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=false # 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 directly CMD ["./app", "--allow-all-origins=true", "--mermaid=./node_modules/.bin/mmdc", "--in=./in", "--out=./out", "--puppeteer=./puppeteer-config.json"]