cmc-sales/Dockerfile.go

57 lines
1.3 KiB
Docker
Raw Normal View History

2025-06-24 03:32:28 -07:00
# Build stage
FROM golang:1.23-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git
# Set working directory
WORKDIR /app
# Copy go mod files
COPY go-app/go.mod go-app/go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY go-app/ .
# Install sqlc (compatible with Go 1.23+)
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Generate sqlc code
RUN sqlc generate
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server cmd/server/main.go
# Runtime stage
FROM alpine:latest
# Install runtime dependencies
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the binary from builder
COPY --from=builder /app/server .
# Copy templates and static files
COPY go-app/templates ./templates
COPY go-app/static ./static
2025-08-04 14:50:12 -07:00
# Copy Gmail OAuth credentials if they exist
# Note: These files contain sensitive data and should not be committed to version control
# Consider using Docker secrets or environment variables for production
# Using conditional copy pattern to handle missing files gracefully
COPY go-app/credentials.jso[n] ./
COPY go-app/token.jso[n] ./
2025-06-24 03:32:28 -07:00
# Copy .env file if needed
COPY go-app/.env.example .env
# Expose port
EXPOSE 8080
# Run the application
CMD ["./server"]