Spaces:
Build error
Build error
| # Build stage | |
| FROM golang:1.21-alpine AS builder | |
| # Install build dependencies | |
| RUN apk add --no-cache gcc musl-dev sqlite-dev git | |
| WORKDIR /app | |
| # Explicitly enable Go modules | |
| ENV GO111MODULE=on | |
| # Copy go.mod and go.sum first for better caching | |
| COPY go.mod go.sum* ./ | |
| # Download dependencies | |
| RUN go mod download | |
| # Copy all source files | |
| COPY . . | |
| # Verify module structure (debug) | |
| RUN echo "=== Go mod contents ===" && cat go.mod && echo "=== Files ===" && ls -la | |
| # Tidy and build | |
| RUN go mod tidy | |
| RUN CGO_ENABLED=1 GOOS=linux go build -o main . | |
| # Runtime stage | |
| FROM alpine:3.19 | |
| # Install runtime dependencies | |
| RUN apk add --no-cache ca-certificates tzdata sqlite-libs | |
| WORKDIR /app | |
| # Create data directory | |
| RUN mkdir -p /app/data | |
| # Copy binary from builder | |
| COPY --from=builder /app/main . | |
| # Copy templates and static files | |
| COPY --from=builder /app/templates ./templates | |
| COPY --from=builder /app/static ./static | |
| # Set environment variables | |
| ENV PORT=7860 | |
| ENV DATABASE_PATH=/app/data/tempmail.db | |
| ENV GIN_MODE=release | |
| # Create non-root user | |
| RUN adduser -D -g '' appuser && chown -R appuser:appuser /app | |
| USER appuser | |
| EXPOSE 7860 | |
| HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ | |
| CMD wget --no-verbose --tries=1 --spider http://localhost:7860/ || exit 1 | |
| CMD ["./main"] |