57 lines
1.2 KiB
Docker
57 lines
1.2 KiB
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 with staging tags
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -tags staging -o server cmd/server/main.go
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
# Install runtime dependencies and debugging tools for staging
|
|
RUN apk --no-cache add ca-certificates curl net-tools
|
|
|
|
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 staging environment file
|
|
COPY go-app/.env.staging .env
|
|
|
|
# Create credentials directory
|
|
RUN mkdir -p ./credentials
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8080/api/v1/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["./server"] |