miniITCS/docker/Dockerfile.backend

38 lines
709 B
Docker

# Multi-stage build for Go backend
FROM golang:1.21-alpine AS builder
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git gcc musl-dev sqlite-dev
# Copy go mod files
COPY backend/go.mod backend/go.sum* ./
RUN go mod download || true
# Copy source code
COPY backend/ .
# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o server ./cmd/server
# Final stage
FROM alpine:latest
WORKDIR /app
# Install runtime dependencies
RUN apk --no-cache add ca-certificates sqlite-libs
# Copy the binary from builder
COPY --from=builder /app/server .
# Create data directory
RUN mkdir -p /app/data
# Expose port
EXPOSE 8080
# Run the application
CMD ["./server"]