2024-09-23 07:59:50 -05:00
|
|
|
# Stage 1: Build the Go binary
|
2024-10-28 11:34:41 -05:00
|
|
|
FROM golang:1.22-alpine AS builder
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
WORKDIR /app
|
|
|
|
|
2024-10-28 11:34:41 -05:00
|
|
|
# Install necessary packages
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
git \
|
|
|
|
gcc \
|
|
|
|
musl-dev \
|
|
|
|
mupdf \
|
|
|
|
mupdf-dev
|
|
|
|
|
2024-09-23 07:59:50 -05:00
|
|
|
# Copy go.mod and go.sum files
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
|
|
|
# Download dependencies
|
|
|
|
RUN go mod download
|
|
|
|
|
2024-12-13 09:48:09 -06:00
|
|
|
# Pre-compile go-sqlite3 to avoid doing this every time
|
|
|
|
RUN CGO_ENABLED=1 go build -tags musl -o /dev/null github.com/mattn/go-sqlite3
|
2024-09-23 07:59:50 -05:00
|
|
|
|
2024-12-13 09:48:09 -06:00
|
|
|
# Now copy the actual source files
|
|
|
|
COPY *.go .
|
|
|
|
|
|
|
|
# Build the binary using caching for both go modules and build cache
|
|
|
|
RUN CGO_ENABLED=1 GOMAXPROCS=$(nproc) go build -tags musl -o paperless-gpt .
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Stage 2: Build Vite frontend
|
2024-10-28 11:34:41 -05:00
|
|
|
FROM node:20-alpine AS frontend
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
WORKDIR /app
|
|
|
|
|
2024-10-28 11:34:41 -05:00
|
|
|
# Install necessary packages
|
|
|
|
RUN apk add --no-cache git
|
2024-09-23 07:59:50 -05:00
|
|
|
|
2024-10-28 11:34:41 -05:00
|
|
|
# Copy package.json and package-lock.json
|
2024-09-23 07:59:50 -05:00
|
|
|
COPY web-app/package.json web-app/package-lock.json ./
|
|
|
|
|
|
|
|
# Install dependencies
|
|
|
|
RUN npm install
|
|
|
|
|
|
|
|
# Copy the frontend code
|
|
|
|
COPY web-app /app/
|
|
|
|
|
|
|
|
# Build the frontend
|
|
|
|
RUN npm run build
|
|
|
|
|
2024-10-28 11:34:41 -05:00
|
|
|
# Stage 3: Create a lightweight image with the Go binary and frontend
|
2024-09-23 07:59:50 -05:00
|
|
|
FROM alpine:latest
|
|
|
|
|
2024-10-28 11:34:41 -05:00
|
|
|
# Install necessary runtime dependencies
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
ca-certificates
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Set the working directory inside the container
|
2024-10-26 08:21:13 -05:00
|
|
|
WORKDIR /app/
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Copy the Go binary from the builder stage
|
|
|
|
COPY --from=builder /app/paperless-gpt .
|
|
|
|
|
|
|
|
# Copy the frontend build
|
2024-10-26 08:21:13 -05:00
|
|
|
COPY --from=frontend /app/dist /app/web-app/dist
|
2024-09-23 07:59:50 -05:00
|
|
|
|
|
|
|
# Expose the port the app runs on
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
# Command to run the binary
|
2024-10-28 11:34:41 -05:00
|
|
|
CMD ["/app/paperless-gpt"]
|