feat: (back) Add Dockerfile
This commit is contained in:
parent
30020853d9
commit
2faa3aa2f9
1 changed files with 36 additions and 0 deletions
36
backend/Dockerfile
Normal file
36
backend/Dockerfile
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Build stage
|
||||||
|
FROM golang:1.24-alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install build dependencies if needed (e.g., for CGO, though we disable it)
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
# Copy go mod and sum files
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the source from the current directory to the Working Directory inside the container
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the Go app
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -o api cmd/api/main.go
|
||||||
|
|
||||||
|
# Start a new stage from scratch
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install ca-certificates (useful for making HTTPS requests)
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
# Copy the Pre-built binary file from the previous stage
|
||||||
|
COPY --from=builder /app/api .
|
||||||
|
|
||||||
|
# Expose port (default 8080, but can be overridden)
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Command to run the executable
|
||||||
|
CMD ["./api"]
|
||||||
Loading…
Reference in a new issue