feat: dockerfile for api
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,3 +22,5 @@
|
||||
.env.local
|
||||
|
||||
ordr-api
|
||||
|
||||
./nohup.out
|
||||
31
api/Dockerfile
Normal file
31
api/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
||||
# Stage 1: Build the application
|
||||
FROM golang:1.25.3-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod and go.sum first to leverage Docker's caching
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application source code
|
||||
COPY . .
|
||||
|
||||
# Build the Go application
|
||||
# CGO_ENABLED=0 disables Cgo for a fully static binary
|
||||
# -a links all packages statically
|
||||
# -installsuffix cgo_non_shared avoids issues with shared libraries
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo_non_shared -o main .
|
||||
|
||||
# Stage 2: Create the final lean image
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the built binary from the builder stage
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
# Expose the port your Gin application listens on (e.g., 8080)
|
||||
EXPOSE 8080
|
||||
|
||||
# Command to run the application
|
||||
CMD ["./ordr-api"]
|
||||
Reference in New Issue
Block a user