Dockerfile 810 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Build stage
  2. FROM golang:1.22.5-alpine AS builder
  3. # Install build dependencies
  4. RUN apk add --no-cache gcc musl-dev
  5. # Set working directory
  6. WORKDIR /app
  7. # Copy go mod and sum files
  8. COPY go.mod go.sum ./
  9. # Download dependencies
  10. RUN go mod download
  11. # Copy source code
  12. COPY . .
  13. # Build the application
  14. RUN CGO_ENABLED=1 GOOS=linux go build -a -o byom-trends .
  15. # Final stage
  16. FROM alpine:3.19
  17. # Install runtime dependencies
  18. RUN apk add --no-cache sqlite-libs ca-certificates tzdata
  19. # Create app directory
  20. WORKDIR /app
  21. # Copy binary from builder
  22. COPY --from=builder /app/byom-trends .
  23. COPY --from=builder /app/config.yaml .
  24. # Create data directory
  25. RUN mkdir -p /app/data
  26. # Set environment variables
  27. ENV GIN_MODE=release
  28. # Expose port
  29. EXPOSE 8080
  30. # Run the application
  31. CMD ["/app/byom-trends", "serve"]