add Dockerfile for multi-stage build and update generate.go command
This commit is contained in:
30
Dockerfile
30
Dockerfile
@ -0,0 +1,30 @@
|
||||
# ---------- Build Stage ----------
|
||||
FROM golang:1.24 AS builder
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Go module files and download dependencies
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the Go binary
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/api/main.go
|
||||
|
||||
# ---------- Final Image ----------
|
||||
FROM alpine:latest
|
||||
|
||||
# Set working directory in final image
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only the binary from builder
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
# Expose the port your app listens on
|
||||
EXPOSE 8080
|
||||
|
||||
# Set default command
|
||||
CMD ["./main"]
|
||||
|
||||
Reference in New Issue
Block a user