Files
bookhoard/backend/Dockerfile
T

37 lines
745 B
Docker

# Build stage
FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install sqlc
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Copy backend source code
COPY backend/ ./backend/
# Download dependencies
RUN cd backend && go mod tidy
# Generate sqlc code
RUN cd backend && sqlc generate
# Build the application
RUN cd backend && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ../main ./cmd/server
# Final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the binary from builder stage
COPY --from=builder /app/main .
# Copy migrations (if needed for initialization)
COPY --from=builder /app/backend/migrations ./migrations
# Expose port
EXPOSE 8765
# Run the binary
CMD ["./main"]