50 lines
944 B
Docker
50 lines
944 B
Docker
|
|
# 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
|
||
|
|
|
||
|
|
# Copy .env file if needed
|
||
|
|
COPY go-app/.env.example .env
|
||
|
|
|
||
|
|
# Expose port
|
||
|
|
EXPOSE 8080
|
||
|
|
|
||
|
|
# Run the application
|
||
|
|
CMD ["./server"]
|