Docker and Workflow
This commit is contained in:
30
backend/Dockerfile
Normal file
30
backend/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
# Stage 1: Build the Go application
|
||||
FROM golang:1.22-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod and go.sum files to download dependencies
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
# CGO_ENABLED=0 is important for a clean static build for Alpine
|
||||
# -o main specifies the output file name
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
||||
|
||||
# Stage 2: Create the final lightweight image
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the built binary from the builder stage
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
# Expose port 8080 (you can change this if your app uses a different port)
|
||||
EXPOSE 8080
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./main"]
|
||||
Reference in New Issue
Block a user